You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.
This shows you the differences between two versions of the page.
functions:llround [2014-01-20 14:47 SLT] omei created |
functions:llround [2015-02-04 13:29 SLT] (current) sei pinf and minf |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | $nav | ||
===== Function: llRound ===== | ===== Function: llRound ===== | ||
Line 4: | Line 5: | ||
integer llRound(float fval) | integer llRound(float fval) | ||
</code> | </code> | ||
+ | |||
+ | Round a $lty[float] to the nearest integer. | ||
===== Parameters ===== | ===== Parameters ===== | ||
=== fval === | === fval === | ||
- | any float value | + | The $lty[float] value to be rounded. |
- | ===== Result ===== | + | ===== Return value ===== |
- | Returns the integer value that is the nearest to fval. | + | Returns the integer value that is the nearest to $prm[fval]. If the decimal part is exactly .5, it will be rounded up (towards positive infinity). |
===== Notes ===== | ===== Notes ===== | ||
- | * The function returns -2147483648 (Hex. 80000000) for float values greater than 2147483647 or less than -2147483648 | + | * The function returns -2147483648 (Hex. 0x80000000) for float values of 2147483648.0 or bigger (including $pinf), or less than -2147483648.0 (including $minf), or $nan. |
===== Short examples ===== | ===== Short examples ===== | ||
<code lsl2> | <code lsl2> | ||
- | integer i = llRound(-3.3); // i will become -3 | + | integer i; |
- | integer i = llRound(3.3); // i will become 3 | + | // Any float between 2.5 and approx. 3.4999998 will cause the function to return 3 |
- | integer i = llRound(-99.6); // i will become -100 | + | // (3.4999998 is the biggest possible float less than 3.5, due to float limitations) |
+ | i = llRound(2.6); // i will become 3 | ||
+ | i = llRound(3.3); // i will become 3 | ||
+ | i = llRound(3.499); // i will become 3 | ||
+ | i = llRound(3.5); // i will become 4 | ||
+ | i = llRound(3.501); // i will become 4 | ||
+ | // Any float between -3.5 and approx. -2.5000002 will cause the function to return -3 | ||
+ | // (-2.5000002 is the biggest possible float less than -2.5, due to float limitations) | ||
+ | i = llRound(-3.3); // i will become -3 | ||
+ | i = llRound(-3.499); // i will become -3 | ||
+ | i = llRound(-3.5); // i will become -3 | ||
+ | i = llRound(-3.501); // i will become -4 | ||
</code> | </code> | ||
===== See also ===== | ===== See also ===== | ||
- | * [[llCeil]] | + | * $lfn[llCeil] rounds always towards positive infinity (e.g. 1.1 is rounded up to 2.0, and -1.1 is rounded up to -1.0). |
- | * [[llFloor]] | + | * $lfn[llFloor] rounds always towards negative infinity (e.g. 1.1 is rounded down to 1.0 and -1.1 is rounded down to -2.0). |
+ | * $lty[float] type and associated caveats and limitations. | ||