Trigonometric functions: Difference between revisions

added javascript
(added Fortran)
(added javascript)
Line 286:
0.7853981633974483 45.0
</pre>
 
=={{header|JavaScript}}==
 
JavaScript's <tt>Math</tt> class contains all six functions and is automatically included as part of the language. The functions all accept radians only, so conversion is necessary when dealing with degrees. The <tt>Math</tt> class also has a <tt>PI</tt> constant for easy conversion.
 
<javascript>
//Pi / 4 is 45 degrees. All answers should be the same.
var radians = Math.PI / 4;
var degrees = 45.0;
//sine
window.alert(Math.sin(radians) + " " + Math.sin(degrees * Math.PI / 180));
//cosine
window.alert(Math.cos(radians) + " " + Math.cos(degrees * Math.PI / 180));
//tangent
window.alert(Math.tan(radians) + " " + Math.tan(degrees * Math.PI / 180));
//arcsine
var arcsin = Math.asin(Math.sin(radians));
window.alert(arcsin + " " + (arcsin * 180 / Math.PI));
//arccosine
var arccos = Math.acos(Math.cos(radians));
window.alert(arccos + " " + (arccos * 180 / Math.PI));
//arctangent
var arctan = Math.atan(Math.tan(radians));
window.alert(arctan + " " + (arctan * 180 / Math.PI));
</javascript>
 
=={{header|Logo}}==
Anonymous user