[arc] sin / cos / tan / PI
Definition: |
atom res = sin(atom a)
-- or -- atom res = cos(atom a) -- or -- atom res = tan(atom a) -- or -- atom a = arcsin(atom x) -- or -- atom a = arccos(atom x) -- or -- atom a = arctan(atom x) -- or -- atom a = atan2(atom y, x) |
Description: |
sin/cos/tan(a) return the the sine/cosine/tangent of a, where a is in radians. arcsin/arccos/arctan(x) return an angle with sine/cosine/tangent equal to x. atan2() returns the arctangent of a ratio, equivalent to arctan(y/x) but can handle a zero denominator and is more accurate. |
pwa/p2js: | Supported. |
Comments: |
The argument to arcsin and arccos, x, must be in the range -1 to +1 inclusive. For arcsin and arctan, a value between -PI/2 and +PI/2 (radians) will be returned. For arccos, a value between 0 and PI (radians) will be returned. Multiply radians by XPG_RAD2DEG (defined in xpGUI as 180/PI) to convert to degrees. arcsin() and arccos() are not as fast as arctan(). These functions may be applied to an atom or sq_sin() / sq_cos() / sq_tan() / sq_arcsin() / srccos() / sq_arctan() to all elements of a sequence. The rules for sequence operations apply. Note that the following diagram uses degrees, so eg sin(30*XPG_DEG2RAD) = 0.5, where XPG_DEG2RAD is defined in xpGUI as PI/180. |
Example: |
?sin(0.9) -- prints 0.7833269096 ?cos(0.5) -- prints 0.8775825619 ?tan(0.1) -- prints 0.1003346721 ?arctan(2) -- prints 1.107148718 ?atan2(1,0) -- prints 1.570796327 ?arcsin(1) -- prints 1.570796327 ?arccos(-1) -- prints 3.141592654 ?PI -- prints 3.141592654 |
Implementation: |
via :%opSin, :%opCos, :%opTan, and :%opArcTan in builtins\VM\pTrig.e (an autoinclude) See builtins\misc.e (an autoinclude) for the implementations of arcsin(), arccos(), and atan2(). The constant PI is defined in psym.e/syminit(), part of the compiler, as 3.141592653589793238, the last two digits of which are of course irrelevant on 32-bit. See mpfr_const_pi() should you require more accuracy. |