Unofficial LSL Reference

[[functions:llabs]]


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

functions:llabs [2014-01-02 08:20 SLT]
sei [Complete examples] oops, will print 3, not -3
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.+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[integervalue (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 isthe value with any negative sign removed.
  
-More rigorously, the result will be the same as IntVal ​if IntVal ​is positive or zero, and -IntVal otherwise.+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 LSL integers.+  * 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 LSL $lty[integer]. 
 ===== Short examples ===== ===== Short examples =====
  
 <code lsl2> <code lsl2>
 integer AbsInt; integer AbsInt;
 +AbsInt = llAbs(-3); ​   // sets AbsInt to 3
 AbsInt = llAbs(-45); ​  // sets AbsInt to 45 AbsInt = llAbs(-45); ​  // sets AbsInt to 45
 AbsInt = llAbs(0); ​    // sets AbsInt to 0 AbsInt = llAbs(0); ​    // sets AbsInt to 0
 AbsInt = llAbs(45); ​   // sets AbsInt to 45 AbsInt = llAbs(45); ​   // sets AbsInt to 45
 +Absint = llAbs(AbsInt - 50); // sets AbsInt to 5 (see explanation below)
 </​code>​ </​code>​
- +The last example ​assumes that ''​AbsInt''​ was 45 due to the previous line45 - 50 equals ​-5and ''​llAbs(-5)''​ equals ​5.
-===== Complete examples ===== +
- +
-<file lsl2 llAbs-example.lsl> +
-default +
-+
-    state_entry() +
-    { +
-        llOwnerSay((string)llAbs(-3) + "" + (string)llAbs(5)); // will print: 3, 5 +
-    } +
-+
-</​file>​+
  
 ===== See also ===== ===== See also =====
  
-  * [[llFabs]] +  * $lfn[llFabs] ​takes the absolute value of a $ty[float]. 
 +  * Other $lfn[math/] functions