Skip to content

llCos

float llCos(float Theta)

Returns the cosine of Theta (Theta in radians).

Parameters
Theta (float)
// Touch the object with this script in it to see the cosine of random numbers!
default
{
touch_start(integer num)
{
float r = llFrand(TWO_PI);
llOwnerSay("The cosine of " + (string)r + " in radians or " + (string)(r * RAD_TO_DEG) + " in degrees is " + (string)llCos(r));
}
}

Due to IEEE754 single-precision floating-point limitations:

  • llCos(PI_BY_TWO) returns -4.371139E-8 (hex: 0xB33BBD2E) instead of 0
  • llCos(PI/3.0) returns 0.49999997 (hex: 0x3EFFFFFF) instead of 0.5

Be aware of these precision issues when comparing cosine results to exact values.