Jump to content

Trigonometric functions: Difference between revisions

+Icon+Unicon
m (markup typo)
(+Icon+Unicon)
Line 503:
; outputs
; ( 3.16578, 1.95960)</lang>
 
== Icon and Unicon ==
Icon and Unicon trig functions 'sin', 'cos', 'tan', 'asin', 'acos', and 'atan' operate on angles expressed in radians. Conversion functions 'dtor' and 'rtod' convert between the two systems. The example below uses string invocation to construct and call the functions:
==={{header|Icon}}===
<lang Icon>invocable all
procedure main()
 
d := 30 # degrees
r := dtor(d) # convert to radians
 
every write(f := !["sin","cos","tan"],"(",r,")=",y := f(r)," ",fi := "a" || f,"(",y,")=",x := fi(y)," rad = ",rtod(x)," deg")
end</lang>
Sample Output:<pre>sin(0.5235987755982988)=0.4999999999999999 asin(0.4999999999999999)=0.5235987755982988 rad = 30.0 deg
cos(0.5235987755982988)=0.8660254037844387 acos(0.8660254037844387)=0.5235987755982987 rad = 29.99999999999999 deg
tan(0.5235987755982988)=0.5773502691896257 atan(0.5773502691896257)=0.5235987755982988 rad = 30.0 deg</pre>
==={{header|Unicon}}===
The Icon solution works in Unicon.
 
=={{header|J}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.