Trigonometric functions: Difference between revisions

Add Jsish
(Add Jsish)
Line 1,734:
acos(-sqrt(2)/2) = 135
atan(sqrt(3)) = 60.00000000000001</lang>
 
=={{header|Jsish}}==
Like many programming languages that handle trig, Jsish also includes the ''atan2'' function, which was originally added to Fortran to allow disambiguous results when converting from cartesian to polar coordinates, due to the mirror image nature of normal arctan.
 
To find what methods are supported, ''jsish'' supports help for the Math module.
 
<pre>help Math
Math.method(...)
Commands performing math operations on numbers
Methods: abs acos asin atan atan2 ceil cos exp floor log max min pow random round sin sqrt tan</pre>
 
Angles passed to the trigonometric functions expect arguments in ''radians'' (Pi by 4 radians being 45 degrees). Degree to radian conversion is shown by multiplying radians by Pi over 180.
 
''Note the inexact nature of floating point approximations.''
 
<lang javascript>/* Trig in Jsish */
var x;
 
;x = Math.PI / 4;
;Math.sin(x);
;Math.cos(x);
;Math.tan(x);
;Math.asin(Math.sin(x)) * 4;
;Math.acos(Math.cos(x)) * 4;
;Math.atan(Math.tan(x));
;Math.atan2(Math.tan(x), 1.0);
;Math.atan2(Math.tan(x), -1.0);
 
;x = 45.0;
;Math.sin(x * Math.PI / 180);
;Math.cos(x * Math.PI / 180);
;Math.tan(x * Math.PI / 180);
 
/*
=!EXPECTSTART!=
x = Math.PI / 4 ==> 0.7853981633974483
Math.sin(x) ==> 0.7071067811865475
Math.cos(x) ==> 0.7071067811865476
Math.tan(x) ==> 0.9999999999999999
Math.asin(Math.sin(x)) * 4 ==> 3.141592653589793
Math.acos(Math.cos(x)) * 4 ==> 3.141592653589793
Math.atan(Math.tan(x)) ==> 0.7853981633974483
Math.atan2(Math.tan(x), 1.0) ==> 0.7853981633974483
Math.atan2(Math.tan(x), -1.0) ==> 2.356194490192345
x = 45.0 ==> 45
Math.sin(x * Math.PI / 180) ==> 0.7071067811865475
Math.cos(x * Math.PI / 180) ==> 0.7071067811865476
Math.tan(x * Math.PI / 180) ==> 0.9999999999999999
=!EXPECTEND!=
*/</lang>
 
{{out}}
<pre>prompt$ jsish --U trigonometric.jsi
x = Math.PI / 4 ==> 0.7853981633974483
Math.sin(x) ==> 0.7071067811865475
Math.cos(x) ==> 0.7071067811865476
Math.tan(x) ==> 0.9999999999999999
Math.asin(Math.sin(x)) * 4 ==> 3.141592653589793
Math.acos(Math.cos(x)) * 4 ==> 3.141592653589793
Math.atan(Math.tan(x)) ==> 0.7853981633974483
Math.atan2(Math.tan(x), 1.0) ==> 0.7853981633974483
Math.atan2(Math.tan(x), -1.0) ==> 2.356194490192345
x = 45.0 ==> 45
Math.sin(x * Math.PI / 180) ==> 0.7071067811865475
Math.cos(x * Math.PI / 180) ==> 0.7071067811865476
Math.tan(x * Math.PI / 180) ==> 0.9999999999999999
 
prompt$ jsish -u trigonometric.jsi
[PASS] trigonometric.jsi</pre>
 
=={{header|Julia}}==
Anonymous user