Trigonometric functions: Difference between revisions

RPL: add section
No edit summary
(RPL: add section)
Line 4,760:
</syntaxhighlight>
 
=={{header|RPL}}==
RPL has somewhere a system flag that defines if arguments passed to trigonometric functions are in degrees or radians. The words <code>DEG</code> and <code>RAD</code> set the flag appropriately.
We can therefore answer the task so:
π 4 / →NUM 'XRAD' STO
45 'XDEG' STO
XRAD RAD SIN XDEG DEG SIN
which will return <code>.707106781187</code> 2 times.
Another way is to stay in the same trigonometric mode and use <code>D→R</code> or <code>R→D</code> conversion words. This is the way used below:
RAD
π 4 / →NUM SIN 45 D→R SIN
π 3 / →NUM COS 60 D→R COS
π 6 / →NUM TAN 30 D→R TAN
{{out}}
<pre>
6: .707106781187
5: .707106781187
4: .499999999997
3: .499999999997
2: .577350269189
1: .577350269189
</pre>
As we have now in the stack the 6 values to be inversed, let's call the required functions in reverse order. The <code>6 ROLLD</code> instruction pushes the number from level 1 to level 6 of the stack, making thus the next number available for inversion.
ATAN R→D 6 ROLLD
ATAN 6 ROLLD
ACOS R→D 6 ROLLD
ACOS 6 ROLLD
ASIN R→D 6 ROLLD
ASIN 6 ROLLD
{{out}}
<pre>
6: .785398163397
5: 45
4: 1.0471975512
3: 60.0000000002
2: .523598775598
1: 30
</pre>
Calculations made with a HP-28S. Emulator has better precision and returns 60 for <code>60 D→R COS ACOS R→D</code>
=={{header|Ruby}}==
 
1,150

edits