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:llfabs [2014-05-14 10:25 SLT] sei created |
functions:llfabs [2015-02-04 13:07 SLT] (current) sei remove extra bracket |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | $nav | ||
===== Function: llFabs ===== | ===== Function: llFabs ===== | ||
<code lsl2> | <code lsl2> | ||
- | float llFabs(float FloatVal) | + | float llFabs(float fval) |
</code> | </code> | ||
+ | |||
+ | Return the absolute value of the parameter (for floats). | ||
===== Parameters ===== | ===== Parameters ===== | ||
- | === FloatVal === | + | === fval === |
- | Any [[types/float]] value (can be negative) | + | Any $lty[float] value (can be negative) |
- | ===== Result ===== | + | ===== Return value ===== |
- | The result will be a float that is the absolute value of FloatVal, that is, the value with any negative sign removed. | + | Returns a $lty[float] that is the absolute value of $prm[fval], that is, the value with any negative sign removed. |
- | > More rigorously, the result will be the same as FloatVal if FloatVal is positive or zero, and -FloatVal if it was negative. | + | More rigorously, the result will be the same as $prm[fval] if $prm[fval] is positive or zero, and $prm[-fval] if it is negative. |
===== Notes ===== | ===== Notes ===== | ||
- | * To determine the absolute value of an [[types/integer]], use [[llAbs]]. | + | * To determine the absolute value of an $lty[integer], use $lfn[llAbs]. |
- | * "Minus zero" (-0.0) is a special case of a [[types/float]] that can rarely appear in some calculations. The absolute value of Minus zero is 0.0. This should not be a concern anyway, as minus zero is mostly transparent to all calculations (e.g. -0.0 == 0.0 evaluates to [[constants/TRUE]]). | + | * "Minus zero" (-0.0) is a special case of a $ty[float] that can rarely appear in some situations. The absolute value of Minus zero is returned by this function unchanged (as -0.0). This should not be a concern anyway, as minus zero is mostly transparent to all calculations (e.g. minus zero is considered equal to zero, and doesn't err when taking its square root). |
- | * The absolute value of [[/NaN]] is **NaN**. The absolute value of [[Infinity]] and **-Infinity** is **Infinity**. | + | * The absolute value of $nan is $nan. The absolute value of $pinf and $minf is $pinf. |
===== Short examples ===== | ===== Short examples ===== | ||
Line 28: | Line 31: | ||
F = llFabs(F); // sets F to 2.25 | F = llFabs(F); // sets F to 2.25 | ||
F = llFabs(F); // F is still 2.25 because it was already positive | F = llFabs(F); // F is still 2.25 because it was already positive | ||
- | F = llFabs(0.0); // F is zero | + | F = llFabs(0.0); // sets F to zero |
+ | F = llFabs(-PI); // sets F to approx. 3.141593 | ||
+ | F = llFabs(0.5); // sets F to 0.5 | ||
</code> | </code> | ||
- | |||
- | ===== Complete examples ===== | ||
- | |||
- | <file lsl2 llFabs-example.lsl> | ||
- | default | ||
- | { | ||
- | state_entry() | ||
- | { | ||
- | llOwnerSay((string)llFabs(-PI) + ", " + (string)llFabs(0.5)); // will print: 3.141593, 0.500000 | ||
- | } | ||
- | } | ||
- | </file> | ||
===== See also ===== | ===== See also ===== | ||
- | * [[llAbs]] takes the absolute value of an [[types/integer]]. | + | * $lfn[llAbs] takes the absolute value of an $lty[integer]. |
- | * [[llVecMag]] takes the norm (magnitude) of a [[types/vector]]. | + | * $lfn[llVecMag] takes the norm (magnitude) of a $lty[vector]. |