Trigonometric functions: Difference between revisions

no edit summary
(Logo)
No edit summary
Line 115:
int main() {
double Pi = 4.0 * atan(1.0); // in D math module, PI is a _real_ constant of πp
/*Pi / 4 is 45 degrees. All answers should be the same.*/
double radians = Pi / 4.0;
Line 139:
}</d>
=={{header|Forth}}==
45e pi f* 180e f/ \ radians
cr fdup fsin f. \ also available: fsincos ( r -- sin cos )
cr fdup fcos f.
cr fdup ftan f.
cr fdup fasin f.
cr fdup facos f.
cr fatan f. \ also available: fatan2 ( r1 r2 -- atan[r1/r2] )
 
=={{header|Haskell}}==
Line 222:
 
<java>public class Trig {
public static void main(String[] args) {
//Pi / 4 is 45 degrees. All answers should be the same.
double radians = Math.PI / 4;
double degrees = 45.0;
//sine
System.out.println(Math.sin(radians) + " " + Math.sin(Math.toRadians(degrees)));
//cosine
System.out.println(Math.cos(radians) + " " + Math.cos(Math.toRadians(degrees)));
//tangent
System.out.println(Math.tan(radians) + " " + Math.tan(Math.toRadians(degrees)));
//arcsine
double arcsin = Math.asin(Math.sin(radians));
System.out.println(arcsin + " " + Math.toDegrees(arcsin));
//arccosine
double arccos = Math.acos(Math.cos(radians));
System.out.println(arccos + " " + Math.toDegrees(arccos));
//arctangent
double arctan = Math.atan(Math.tan(radians));
System.out.println(arctan + " " + Math.toDegrees(arctan));
}
}
}</java>
 
Line 321:
0.785398163397448 45
0.785398163397448 45
</pre>
 
=={{header|Pop11}}==
 
Pop11 trigonometric functions accept both degrees and radians.
In default mode argument is in degrees, after setting 'popradians'
flag to 'true' arguments are in radians.
 
<pre>
sin(30) =>
cos(45) =>
tan(45) =>
arcsin(0.7) =>
arccos(0.7) =>
arctan(0.7) =>
;;; switch to radians
true -> popradians;
 
sin(pi*30/180) =>
cos(pi*45/180) =>
tan(pi*45/180) =>
arcsin(0.7) =>
arccos(0.7) =>
arctan(0.7) =>
</pre>
 
Anonymous user