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:llabs [2014-01-01 13:09 SLT] omei created |
functions:llabs [2015-09-22 11:56 SLT] (current) sei wording |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | $nav | ||
===== Function: llAbs ===== | ===== Function: llAbs ===== | ||
<code lsl2> | <code lsl2> | ||
- | integer llAbs(integer IntVal) | + | integer llAbs(integer ival) |
</code> | </code> | ||
+ | |||
+ | Return the absolute value of the parameter (for integers). | ||
===== Parameters ===== | ===== Parameters ===== | ||
- | > **''IntVal''** | + | === ival === |
- | > a positive or negative integer value or the name of an integer variable. | + | Any $lty[integer] value (can be negative) |
- | ===== Result ===== | + | ===== Return value ===== |
- | The result will be an integer that is the absolute value of IntVal, that is the value with any negative sign removed. | + | It returns an integer that is the absolute value of $prm[ival], that is, the value with any negative sign removed. |
+ | |||
+ | More rigorously, the result will be the same as $prm[ival] if $prm[ival] is positive or zero, and $prm[-ival] if it is negative. | ||
===== Notes ===== | ===== Notes ===== | ||
- | * To determine the absolute value of a float, use llFabs | + | * To determine the absolute value of a $lty[float], use $lfn[llFabs]. |
+ | * As a special case, the absolute value of -2,147,483,648 (-2<sup>31</sup>, the lowest integer LSL supports) is returned by this function as -2,147,483,648 because the positive integer 2,147,483,648 is outside the range of a LSL $lty[integer]. | ||
- | ===== Examples ===== | + | ===== Short examples ===== |
- | This example illustrates the use of llAbs: | + | <code lsl2> |
- | <file lsl2 llAbs-example.lsl> | + | integer AbsInt; |
- | default | + | AbsInt = llAbs(-3); // sets AbsInt to 3 |
- | { | + | AbsInt = llAbs(-45); // sets AbsInt to 45 |
- | state_entry() | + | AbsInt = llAbs(0); // sets AbsInt to 0 |
- | { | + | AbsInt = llAbs(45); // sets AbsInt to 45 |
- | integer AbsInt = llAbs(-45.67); // result will be 45.67 | + | Absint = llAbs(AbsInt - 50); // sets AbsInt to 5 (see explanation below) |
- | } | + | </code> |
- | } | + | The last example assumes that ''AbsInt'' was 45 due to the previous line. 45 - 50 equals -5, and ''llAbs(-5)'' equals 5. |
- | </file> | + | |
===== See also ===== | ===== See also ===== | ||
- | * [[llFabs]] | + | * $lfn[llFabs] takes the absolute value of a $ty[float]. |
+ | * Other $lfn[math/] functions |