Trigonometric functions: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) |
Kinitawowi (talk | contribs) (add ZX Spectrum) |
||
Line 4,923: | Line 4,923: | ||
(1.0).atan().toDeg() //-->45 |
(1.0).atan().toDeg() //-->45 |
||
etc</lang> |
etc</lang> |
||
=={{header|ZX Spectrum Basic}}== |
|||
The ZX Spectrum ROM only calculates sine and arctangent directly (via Chebyshev polynomials), and uses internal functions of these (and the square root) to generate the other functions. In particular, arcsin x is calculated as arctan ( x / ( sqrt ( 1 - x * x ) ) + 1 ) / 2, which is why some of these functions are legendarily slow. |
|||
<lang zxbasic>10 DEF FN d(a)=a*PI/180:REM convert degrees to radians; all ZX Spectrum trig calculations are done in radians |
|||
20 DEF FN i(r)=180*r/PI:REM convert radians to degrees for inverse functions |
|||
30 LET d=45 |
|||
40 LET r=PI/4 |
|||
50 PRINT SIN r,SIN FN d(d) |
|||
60 PRINT COS r,COS FN d(d) |
|||
70 PRINT TAN r,TAN FN d(d) |
|||
80 PRINT |
|||
90 LET d=.5 |
|||
110 PRINT ASN d,FN i(ASN d) |
|||
120 PRINT ACS d,FN i(ACS d) |
|||
130 PRINT ATN d,FN i(ATN d)</lang> |
|||
{{out}} |
|||
<pre> |
|||
0.70710678 0.70710678 |
|||
0.70710678 0.70710678 |
|||
1 1 |
|||
0.52359878 30 |
|||
1.0471976 60 |
|||
0.46364761 26.565051 |
|||
0 OK, 130:1 |
|||
</pre> |
|||
{{omit from|Batch File|No access to advanced math.}} |
{{omit from|Batch File|No access to advanced math.}} |