Unofficial LSL Reference

[[functions:llfabs]]


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

This is an old revision of the document!


Function: llFabs

float llFabs(float FloatVal)

Parameters

FloatVal

Any float value (can be negative)

Result

The result will be a float that is the absolute value of FloatVal, 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.

Notes

  • To determine the absolute value of an integer, use llAbs.
  • "Minus zero" (-0.0) is a special case of a float that can rarely appear in some situations. 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. 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.

Short examples

float F = -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(0.0); // F is zero

Complete examples

llFabs-example.lsl
default
{
    state_entry()
    {
        llOwnerSay((string)llFabs(-PI) + ", " + (string)llFabs(0.5)); // will print: 3.141593, 0.500000
    }
}

See also