Unofficial LSL Reference

[[functions:llpow]]


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

Function: llPow

float llPow(float base, float exp)

Raise a number to an exponent.

Parameters

base

The number to raise.

exp

The exponent to raise the base to.

Return value

The result of raising base to the power exp.

Notes

  • There is no function to return ex given x, and no built-in constant for e. Use llPow(2.7182818, value) instead.

The rules for corner cases are somewhat convoluted. In order:

  • If either argument is NaN, the result is NaN.
  • If the exponent is 0.0 or -0.0, the result is 1.0. This includes in particular the bases 0.0, Infinity, and -Infinity.
  • If the base is Infinity or -Infinity, and the exponent is negative, the result is 0.0.
  • If the base is -Infinity and the exponent is positive and represents an odd integer, the result is -Infinity.
  • If the base is Infinity or -Infinity and the exponent is positive, the result is Infinity (except in those cases which meet the previous point's condition).
  • If the base is -0.0, and the exponent is negative and represents an odd integer, the result is -Infinity.
  • If the base is 0.0 or -0.0, and the exponent is negative, the result is Infinity (except in those cases which meet the previous point's condition).
  • If the base is 1.0 or -1.0, and the exponent is Infinity or -Infinity, the result is NaN.
  • If the base is negative, the exponent must have no decimals (i.e. represent an integer number); otherwise, NaN is returned.
  • In all other cases, the expected result (the base raised to the exponent) is returned.

Short examples

float f;
f = llPow(1, 444);    // sets f to 1
f = llPow(0, 5);      // sets f to 0
f = llPow(5, 0);      // sets f to 1
f = llPow(0, 0);      // sets f to 1
f = llPow(2.7182818, 3); // raises 2.7182818 (the Euler constant) to the 3rd power,
                         // storing the result (approx. 20.085540) in f
f = llPow(-0.5, 4);   // sets f to 0.0625
f = llPow(-1.5, 1.5); // sets f to NaN because the base is negative and the exponent has decimals

See also

  • llLog calculates the natural logarithm of the input.
  • llLog10 calculates the logarithm in base 10 of the input.
  • float type and associated caveats and limitations.