Difference between revisions of "LlFabs"

From Second Life Wiki
Jump to navigation Jump to search
m (LSL llFabs moved to LlFabs)
(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)
 
(18 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL Function
|inject-2={{Issues/SCR-439}}
|func=llFabs|sort=Fabs
|func=llFabs|sort=Fabs
|func_id=7|func_sleep=0.0|func_energy=10.0
|func_id=7|func_sleep=0.0|func_energy=10.0
|func_footnote
|func_footnote
|p1_type=float
|p1_type=float|p1_name=val|p1_desc=Any valid float value
|p1_name=val
|p1_desc=Any valid float value
|p2_type|p2_name|p2_desc
|p3_type|p3_name|p3_desc
|p4_type|p4_name|p4_desc
|p5_type|p5_name|p5_desc
|p6_type|p6_name|p6_desc
|p7_type|p7_name|p7_desc
|p8_type|p8_name|p8_desc
|p9_type|p9_name|p9_desc
|p10_type|p10_name|p10_desc
|p11_type|p11_name|p11_desc
|p12_type|p12_name|p12_desc
|return_type=float
|return_type=float
|return_text=that is the positive version of '''val'''.
|return_text=that is the positive version of {{LSLP|val}}.
|other_languages={{LSL OL|C++|[http://www.cplusplus.com/reference/cmath/fabs/ fabs]}}
|spec
|spec
|caveats
|caveats
|examples=
|examples=
<pre>
<source lang="lsl2">
default
default
{
{
     state_entry()
     state_entry()
     {
     {
         llSay(0,"The absolute value of -4.5 is: "+(string)llFabs(-4.5) );
         llSay(0,"The (Float)absolute value of -4.5 is: "+(string)llFabs(-4.5) );
     }
     }
}
}
</pre>
// returns :
// The (Float)absolute value of -4.5 is: 4.500000
</source>
|helpers
|helpers
|related=
|also_functions={{LSL DefineRow||[[llAbs]]|[[integer]] version of llFabs}}
* {{LSLG|llAbs}}
|also_events
|also_articles=
|also_articles={{LSL DefineRow||{{Wikipedia|Absolute value}}|}}
* [http://en.wikipedia.org/wiki/Absolute_value Wikipedia - Absolute value]
|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.
|notes
|cat1=Math
|cat1=Math
|cat2
|cat2=Float
|cat3
|cat3
|cat4
|cat4
|haiku={{Haiku|Even with all your little bits intact,|down to the final point|it's still size that matters.}}
}}
}}

Latest revision as of 15:11, 28 October 2023

Summary

Function: float llFabs( float val );
0.0 Forced Delay
10.0 Energy

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

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

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.