Difference between revisions of "LlPow"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
(llPow is *very* slow compared to plain multiplication, so for a static integer exponent it's not necessary)
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:
|sort=Pow|func=llPow
|sort=Pow|func=llPow
|func_id=5|func_sleep=0.0|func_energy=10.0
|func_id=5|func_sleep=0.0|func_energy=10.0
|func_footnote=Triggers a [[LSL_Math_Error|Math Error]] for imaginary results <code>(({{LSLPT|exponent}} != ([[integer]]){{LSLPT|exponent}}) && ({{LSLPT|base}} < 0.0))</code>
|func_footnote=Returns {{abbr|NaN|not a number}} when {{LSLP|base}} is negative and {{LSLP|exponent}} is not an integer (an imaginary result, <code>({{LSLPT|exponent}} != ([[integer]]){{LSLPT|exponent}}) && ({{LSLPT|base}} < 0.0)</code>).
|p1_type=float|p1_name=base|p1_desc
|p1_type=float|p1_name=base|p1_desc
|p2_type=float|p2_name=exponent|p2_desc
|p2_type=float|p2_name=exponent|p2_desc
Line 8: Line 8:
|return_text=that is {{LSLP|base}} raised to the power {{LSLP|exponent}} ({{LSLP|base}}<sup>{{LSLP|exponent}}</sup>)
|return_text=that is {{LSLP|base}} raised to the power {{LSLP|exponent}} ({{LSLP|base}}<sup>{{LSLP|exponent}}</sup>)
|spec
|spec
|caveats=* Can crash the script.
|caveats=*If {{LSLP|exponent}} is a static integer and not a variable, llPow is dramatically slower than simple repeated multiplication, i.e. it's much faster to do <code>val = base*base*base</code> instead of <code>val = llPow(base, 3)</code>.
*Triggers a {{LSLGC|Error/Math|Math Error}} for imaginary results if not compiled in Mono.
|examples=
|examples=
<source lang="lsl2">default {
<syntaxhighlight lang="lsl2">default {
     state_entry() {
     state_entry() {
           llOwnerSay("llPow(5, .5) (" + (string)llPow(5, .5) + ") is equal to llSqrt(5) ("  
           llOwnerSay("llPow(5, .5) (" + (string)llPow(5, .5) + ") is equal to llSqrt(5) ("  
                       + (string)llSqrt(5) + ").");
                       + (string)llSqrt(5) + ").");
     }
     }
}</source>
}</syntaxhighlight>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llLog]]|}}
|also_functions={{LSL DefineRow||[[llLog]]|}}

Latest revision as of 07:38, 1 November 2023

Summary

Function: float llPow( float base, float exponent );
0.0 Forced Delay
10.0 Energy

Returns a float that is base raised to the power exponent (baseexponent)

• float base
• float exponent

Returns NaN when base is negative and exponent is not an integer (an imaginary result, (exponent != (integer)exponent) && (base < 0.0)).

Caveats

  • If exponent is a static integer and not a variable, llPow is dramatically slower than simple repeated multiplication, i.e. it's much faster to do val = base*base*base instead of val = llPow(base, 3).
  • Triggers a Math Error for imaginary results if not compiled in Mono.

Examples

default {
     state_entry() {
          llOwnerSay("llPow(5, .5) (" + (string)llPow(5, .5) + ") is equal to llSqrt(5) (" 
                      + (string)llSqrt(5) + ").");
     }
}

See Also

Functions

•  llLog
•  llLog10
•  llSqrt

Deep Notes

Signature

function float llPow( float base, float exponent );