Trigonometric functions: Difference between revisions

Updated for D2
(added Fantom example)
(Updated for D2)
Line 313:
=={{header|D}}==
{{trans|C}}
<lang d>import std.stdio, std.math ;
 
intvoid main() {
double enum real degrees = 45.0;
double Pi = 4.0 * atan(1.0); // in D math module, PI is a _real_ constant of p
/*Pi / 4enum isreal 45t0 = degrees. All* answersPI should/ be the same180.*/0;
writeln("Reference: 0.7071067811865475244008");
double radians = Pi / 4.0;
writefln("Sine: %.20f %.20f", sin(PI_4), sin(t0));
double degrees = 45.0;
writefln("Cosine: %.20f %.20f", cos(PI_4), cos(t0));
double temp;
writefln("Tangent: %.20f %.20f", tan(PI_4), tan(t0));
/*sine*/
 
writef("%f %f\n", sin(radians), sin(degrees * Pi / 180.0));
writeln();
/*cosine*/
writeln("Reference: 0.7853981633974483096156");
writef("%f %f\n", cos(radians), cos(degrees * Pi / 180.0));
immutable real t1 = asin(sin(PI_4));
/*tangent*/
writef writefln("Arcsine: %f.20f %f\n.20f", tan(radians)t1, tan(degreest1 * Pi / 180.0) / PI);
 
/*arcsine*/
temp immutable real t2 = asinacos(sincos(radiansPI_4));
writef writefln("Arccosine: %f.20f %f\n.20f", tempt2, tempt2 * 180.0 / PiPI);
 
/*arccosine*/
temp immutable real t3 = acosatan(costan(radiansPI_4));
writef writefln("Arctangent: %f.20f %f\n.20f", tempt3, tempt3 * 180.0 / PiPI);
/*arctangent*/
temp = atan(tan(radians));
writef("%f %f\n", temp, temp * 180.0 / Pi);
return 0;
}</lang>
Output:
<pre>Reference: 0.7071067811865475244008
Sine: 0.70710678118654752442 0.70710678118654752442
Cosine: 0.70710678118654752438 0.70710678118654752438
Tangent: 1.00000000000000000000 1.00000000000000000000
 
Reference: 0.7853981633974483096156
Arcsine: 0.78539816339744830970 45.00000000000000000400
Arccosine: 0.78539816339744830961 45.00000000000000000000
Arctangent: 0.78539816339744830961 45.00000000000000000000</pre>
 
=={{header|E}}==
Anonymous user