Difference between revisions of "LlFabs"

From Second Life Wiki
Jump to navigation Jump to search
m (LlFabs moved to LSL 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)
 
(29 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{lowercase|llFabs}}
{{LSL Function
__NOTOC__
|inject-2={{Issues/SCR-439}}
 
|func=llFabs|sort=Fabs
{| width="100%"
|func_id=7|func_sleep=0.0|func_energy=10.0
|-
|func_footnote
|<div id="box">
|p1_type=float|p1_name=val|p1_desc=Any valid float value
== [[LSL_Type_float|float]] llFabs( [[LSL_Type_float|float]] val); ==
|return_type=float
<div style="padding: 0.5em">
|return_text=that is the positive version of {{LSLP|val}}.
* val - Any valid float value
|other_languages={{LSL OL|C++|[http://www.cplusplus.com/reference/cmath/fabs/ fabs]}}
</div>
|spec
</div>
|caveats
|-
|examples=
|
<source lang="lsl2">
<div id="box">
default
 
{
== Specification ==
    state_entry()
<div style="padding: 0.5em">
    {
This function returns the absolute value passed to it. Basically, it removes the negative sign, on the number if there is one. If the parameter is a positive one, it just returns it.
        llSay(0,"The (Float)absolute value of -4.5 is: "+(string)llFabs(-4.5) );
{|  
    }
|-
| [[LSL_Energy|Energy]]:
| 10.0
|-
| [[LSL_Sleep|Sleep]]:
| 0.0
|-
| [[LSL_Function_ID|Function ID]]:  
| 7
|}
</div>
</div>
|-
|
<div id="box">
 
== Caveats ==
<div style="padding: 0.5em">
</div>
</div>
 
|-
|
<div id="box">
== Examples ==
<div style="padding: 0.5em">
<lsl>
default {
  state_entry()
  {
      llSay(0,"The absolute value of -4.5 is: "+(string)llFabs(-4.5) );
  }
}
}
</lsl>
// returns :
</div>
// The (Float)absolute value of -4.5 is: 4.500000
</div>
</source>
|-
|helpers
|
|also_functions={{LSL DefineRow||[[llAbs]]|[[integer]] version of llFabs}}
<div id="box">
|also_events
== Helper Functions ==
|also_articles={{LSL DefineRow||{{Wikipedia|Absolute value}}|}}
<div style="padding: 0.5em">
|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.
<lsl>
|cat1=Math
</lsl>
|cat2=Float
</div>
|cat3
</div>
|cat4
|-
|haiku={{Haiku|Even with all your little bits intact,|down to the final point|it's still size that matters.}}
|
}}
<div id="box">
== See Also ==
<div style="padding: 0.5em">
</div>
</div>
|-
|
<div id="box">
== Notes ==
<div style="padding: 0.5em">
</div>
</div>
|}
 
[[Category:LSL_Functions]]
[[Category:LSL_Math]]

Latest revision as of 14: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.