Jump to content

Trigonometric functions: Difference between revisions

added scheme
(-> IDL)
(added scheme)
Line 258:
 
OCaml's preloaded <tt>Pervasives</tt> modules contains all six functions. The functions all accept radians only, so conversion is necessary when dealing with degrees.
<ocaml>let pi = 4. *. atan 1.
 
let radians = pi /. 4.
let degrees = 45.;;
 
Printf.printf "%f %f\n" (tansin radians) (tansin (degrees *. pi /. 180.));;
let () =
Printf.printf "%f %f\n" (sincos radians) (sincos (degrees *. pi /. 180.));;
Printf.printf "%f %f\n" (costan radians) (costan (degrees *. pi /. 180.));;
let arcsin = asin (sin radians);;
Printf.printf "%f %f\n" (tan radians) (tan (degrees *. pi /. 180.));
Printf.printf "%f %f\n" letarcsin (arcsin =*. asin180. (sin/. radianspi);;
andlet arccos = acos (cos radians);;
Printf.printf "%f %f\n" arcsinarccos (arcsinarccos *. 180. /. pi);;
andlet arctan = atan (tan radians) in;;
Printf.printf "%f %f\n" arcsin (arcsin *. 180. /. pi);
Printf.printf "%f %f\n" arccosarctan (arccosarctan *. 180. /. pi);;</ocaml>
Printf.printf "%f %f\n" arctan (arctan *. 180. /. pi)
Output:
<pre>
Line 285 ⟶ 284:
=={{header|Perl}}==
{{works with|Perl|5.8.8}}
<perl>use Math::Trig;
 
$angle_degrees = 45;
$angle_radians = pi / 4;
 
print sin($angle_radians).' '.sin(deg2rad($angle_degrees))."\n";
print cos($angle_radians).' '.cos(deg2rad($angle_degrees))."\n";
print tan($angle_radians).' '.tan(deg2rad($angle_degrees))."\n";
print cot($angle_radians).' '.cot(deg2rad($angle_degrees))."\n";
$asin = asin(sin($angle_radians));
print $asin.' '.rad2deg($asin)."\n";
$acos = acos(cos($angle_radians));
print $acos.' '.rad2deg($acos)."\n";
$atan = atan(tan($angle_radians));
print $atan.' '.rad2deg($atan)."\n";
$acot = acot(cot($angle_radians));
print $acot.' '.rad2deg($acot)."\n";</perl>
 
Output:
Line 314 ⟶ 313:
0.785398163397448 45
</pre>
 
=={{header|Scheme}}==
 
<scheme>(define pi (* 4 (atan 1)))
 
(define radians (/ pi 4))
(define degrees 45)
 
(display (sin radians))
(display " ")
(display (sin (* degrees (/ pi 180))))
(newline)
 
(display (cos radians))
(display " ")
(display (cos (* degrees (/ pi 180))))
(newline)
 
(display (tan radians))
(display " ")
(display (tan (* degrees (/ pi 180))))
(newline)
(define arcsin (asin (sin radians)))
(display arcsin)
(display " ")
(display (* arcsin (/ 180 pi)))
(newline)
 
(define arccos (acos (cos radians)))
(display arccos)
(display " ")
(display (* arccos (/ 180 pi)))
(newline)
 
(define arctan (atan (tan radians)))
(display arctan)
(display " ")
(display (* arctan (/ 180 pi)))
(newline)</scheme>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.