Difference between revisions of "LlFabs"

From Second Life Wiki
Jump to navigation Jump to search
m (url updated)
(like llAbs, llFabs isn't strictly necessary, though can't bitshift so avoiding the function isn't quite as powerful and it produces NaNs for infinity/+0 for -0)
 
Line 26: Line 26:
|also_events
|also_events
|also_articles={{LSL DefineRow||{{Wikipedia|Absolute value}}|}}
|also_articles={{LSL DefineRow||{{Wikipedia|Absolute value}}|}}
|notes
|notes=*Using <code>{{LSLP|val}}-2*{{LSLP|val}}*({{LSLP|val}}<0)</code> is roughly 60% faster than llFabs as it avoids a function call, though it produces {{abbr|NaN|not a number}} if given an infinite value and (correctly) returns 0.0 instead of -0.0 when taking the absolute value of negative zero.
|cat1=Math
|cat1=Math
|cat2=Float
|cat2=Float

Latest revision as of 15:11, 28 October 2023

Summary

Function: float llFabs( float val );

Returns a float that is the positive version of val.

• float val Any valid float value
This function is similar to functions (e.g. fabs) found in many other languages: 
C++
fabs

Caveats

Important Issues

~ All Issues ~ Search JIRA for related Bugs
   Mono only: llFabs of Negative Zero is negative, should be positive.

Examples

default
{
    state_entry()
    {
        llSay(0,"The (Float)absolute value of -4.5 is: "+(string)llFabs(-4.5) );
    }
}
// returns :
// The (Float)absolute value of -4.5 is: 4.500000

Notes

  • Using val-2*val*(val<0) is roughly 60% faster than llFabs as it avoids a function call, though it produces NaN if given an infinite value and (correctly) returns 0.0 instead of -0.0 when taking the absolute value of negative zero.

See Also

Functions

•  llAbs integer version of llFabs

Articles

•  "Wikipedia logo"Absolute value

Deep Notes

All Issues

~ Search JIRA for related Issues
   Mono only: llFabs of Negative Zero is negative, should be positive.

Signature

function float llFabs( float val );

Haiku

Even with all your little bits intact,
down to the final point
it's still size that matters.