Unofficial LSL Reference

[[types:float]]


Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

types:float [2015-09-22 10:02 SLT]
sei Rationalize the heading texts
types:float [2015-09-22 11:28 SLT] (current)
sei missed styling a word
Line 2: Line 2:
 ===== Float type ===== ===== Float type =====
  
-The $ty[float] type represents a number with decimals, as opposed to the [[integer]] type which is for whole numbers only.+The $ty[float] type represents a number with decimals, as opposed to the $lty[integer] type which is for whole numbers only.
  
 Floating-point ($ty[float]) constants can be entered in two formats. The first is by just writing the number with its sign, the decimal point (mandatory for the constant to actually be a float and not an integer), and the decimals. For example, ''​3.7''​ or ''​-5.4164''​ are valid float constants. Neither the part to the left of the point nor the part to the right of the point are mandatory (e.g. ''​37.''​ or ''​-.25''​ are valid), but a point without any digits around it is not a valid floating-point constant. Floating-point ($ty[float]) constants can be entered in two formats. The first is by just writing the number with its sign, the decimal point (mandatory for the constant to actually be a float and not an integer), and the decimals. For example, ''​3.7''​ or ''​-5.4164''​ are valid float constants. Neither the part to the left of the point nor the part to the right of the point are mandatory (e.g. ''​37.''​ or ''​-.25''​ are valid), but a point without any digits around it is not a valid floating-point constant.
Line 46: Line 46:
  
 For example, in this format, the number 1.000000001 can't be distinguished from the number 1.000000002 because it requires 10 significant digits to distinguish them, and there are not enough significant digits in the float type. However, the number 1.00001 can be distinguished from the number 1.00002 because it has 6 significant digits. For example, in this format, the number 1.000000001 can't be distinguished from the number 1.000000002 because it requires 10 significant digits to distinguish them, and there are not enough significant digits in the float type. However, the number 1.00001 can be distinguished from the number 1.00002 because it has 6 significant digits.
- 
-=== Type casting floats to strings === 
  
 Due to the way floats work, the closer to zero they are the more precision after the decimal point they have, and vice versa. Numbers above 8,388,608.0 or less than -8,​388,​608.0 don't have any decimal places at all, while numbers between -1.0 and 1.0 have at least 6 decimal places, possibly more depending on how close to zero they are. Due to the way floats work, the closer to zero they are the more precision after the decimal point they have, and vice versa. Numbers above 8,388,608.0 or less than -8,​388,​608.0 don't have any decimal places at all, while numbers between -1.0 and 1.0 have at least 6 decimal places, possibly more depending on how close to zero they are.
 +
 +=== Type casting a float to string ===
  
 When they are typecast to $lty[string],​ floats are always translated with all of their digits to the left of the decimal point, and six decimal places to the right, rounded. However, as an exception, when a $lty[vector] (a collection of three floats) or a $lty[rotation] (a collection of four floats) is typecast to $ty[string],​ its floats are converted using five decimal places to the right of the decimal point. This exception does not apply if they are inside a list and the list is converted to string. When they are typecast to $lty[string],​ floats are always translated with all of their digits to the left of the decimal point, and six decimal places to the right, rounded. However, as an exception, when a $lty[vector] (a collection of three floats) or a $lty[rotation] (a collection of four floats) is typecast to $ty[string],​ its floats are converted using five decimal places to the right of the decimal point. This exception does not apply if they are inside a list and the list is converted to string.
Line 94: Line 94:
 // string using 6 decimal places too. // string using 6 decimal places too.
 </​code>​ </​code>​
 +
 +The float value $nan is translated to the string ''​NaN'',​ no matter the kind; the float value $pinf is translated to the string ''​Infinity''​ and the float value $minf to the string ''​-Infinity''​. This happens also with other functions that convert floats to string (e.g. $lfn[llList2String],​ $lfn[llDumpList2String]),​ except one: $lfn[llList2CSV] translates the float value $nan to the string ''​nan''​ (if it's regular NaN) or ''​-nan''​ (if it's the indeterminate kind of NaN), and translates $pinf and $minf to ''​inf''​ and ''​-inf''​ respectively.
  
 === Precision caveats === === Precision caveats ===