Trigonometric functions: Difference between revisions

no edit summary
(Add BaCon)
No edit summary
Line 335:
*/</lang>
 
=={{header|Autolisp}}==
Autolisp provides <b>(sin x) (cos x) (tan x)</b> and <b>(atan x)</b>.
Function arguments are expressed in radians.
<lang Autolisp>
(defun rad_to_deg (rad)(* 180.0 (/ rad _pi)))
(defun deg_to_rad (deg)(* _pi (/ deg 180.0)))
 
(defun asin (x)
(cond
((and(> x -1.0)(< x 1.0)) (atan (/ x (sqrt (- 1.0 (* x x))))))
((= x -1.0) (* -1.0 (/ pi 2)))
((= x 1) (/ pi 2))
)
)
 
(defun acos (x)
(cond
((and(>= x -1.0)(<= x 1.0)) (-(* pi 0.5) (asin x)))
)
)
 
(list
(list "cos PI/6" (cos (/ pi 6)) "cos 30 deg" (cos (deg_to_rad 30)))
(list "sin PI/4" (sin (/ pi 4)) "sin 45 deg" (sin (deg_to_rad 45)))
(list "tan PI/3" (tan (/ pi 3))"tan 60 deg" (tan (deg_to_rad 60)))
(list "asin 1 rad" (asin 1.0) "asin 1 rad (deg)" (rad_to_deg (asin 1.0)))
(list "acos 1/2 rad" (acos (/ 1 2.0)) "acos 1/2 rad (deg)" (rad_to_deg (acos (/ 1 2.0))))
(list "atan pi/12" (atan (/ pi 12)) "atan 15 deg" (rad_to_deg(atan(deg_to_rad 15))))
)
</lang>
{{out}}
<pre>
(("cos PI/6 rad" 0.866025 "cos 30 deg" 0.866025)
("sin PI/4 rad" 0.707107 "sin 45 deg" 0.707107)
("tan PI/3 rad" 1.73205 " tan 60 deg" 1.73205)
("asin 1 rad" 1.57080 "asin 1 rad (deg)" 90.0000)
("acos 1/2 rad" 1.04720 "acos 1/2 rad" 60.0000)
("atan pi/12 rad" 0.256053 "atan 15 deg" 14.6707))
</pre>
=={{header|AWK}}==
Awk only provides <tt>sin()</tt>, <tt>cos()</tt> and <tt>atan2()</tt>, the three bare necessities for trigonometry. They all use radians. To calculate the other functions, we use these three trigonometric identities:
Anonymous user