Trigonometric functions: Difference between revisions

Added Easylang
No edit summary
(Added Easylang)
 
(3 intermediate revisions by 3 users not shown)
Line 1,106:
Arccosine: 0.78539816339744830961 45.00000000000000000000
Arctangent: 0.78539816339744830961 45.00000000000000000000</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
procedure ShowTrigFunctions(Memo: TMemo);
const AngleDeg = 45.0;
var AngleRad,ArcSine,ArcCosine,ArcTangent: double;
begin
AngleRad:=DegToRad(AngleDeg);
 
Memo.Lines.Add(Format('Angle: Degrees: %3.5f Radians: %3.6f',[AngleDeg,AngleRad]));
Memo.Lines.Add('-------------------------------------------------');
Memo.Lines.Add(Format('Sine: Degrees: %3.6f Radians: %3.6f',[sin(DegToRad(AngleDeg)),sin(AngleRad)]));
Memo.Lines.Add(Format('Cosine: Degrees: %3.6f Radians: %3.6f',[cos(DegToRad(AngleDeg)),cos(AngleRad)]));
Memo.Lines.Add(Format('Tangent: Degrees: %3.6f Radians: %3.6f',[tan(DegToRad(AngleDeg)),tan(AngleRad)]));
ArcSine:=ArcSin(Sin(AngleRad));
Memo.Lines.Add(Format('Arcsine: Degrees: %3.6f Radians: %3.6f',[DegToRad(ArcSine),ArcSine]));
ArcCosine:=ArcCos(cos(AngleRad));
Memo.Lines.Add(Format('Arccosine: Degrees: %3.6f Radians: %3.6f',[DegToRad(ArcCosine),ArcCosine]));
ArcTangent:=ArcTan(tan(AngleRad));
Memo.Lines.Add(Format('Arctangent: Degrees: %3.6f Radians: %3.6f',[DegToRad(ArcTangent),ArcTangent]));
end;
 
 
 
</syntaxhighlight>
{{out}}
<pre>
Angle: Degrees: 45.00000 Radians: 0.785398
-------------------------------------------------
Sine: Degrees: 0.707107 Radians: 0.707107
Cosine: Degrees: 0.707107 Radians: 0.707107
Tangent: Degrees: 1.000000 Radians: 1.000000
Arcsine: Degrees: 0.013708 Radians: 0.785398
Arccosine: Degrees: 0.013708 Radians: 0.785398
Arctangent: Degrees: 0.013708 Radians: 0.785398
 
Elapsed Time: 9.118 ms.
 
</pre>
 
 
=={{header|E}}==
Line 1,134 ⟶ 1,179:
0.7853981633974483 45.0
0.7853981633974483 45.0
 
=={{header|EasyLang}}==
<syntaxhighlight>
r = pi / 4
d = 45
#
func r2d r .
return r / pi * 180
.
func d2r d .
return d * pi / 180
.
#
numfmt 4 0
print sin d & " " & sin r2d r
print cos d & " " & cos r2d r
print tan d & " " & tan r2d r
print ""
h = asin sin d
print h & " " & d2r h
h = acos cos d
print h & " " & d2r h
h = atan tan d
print h & " " & d2r h
</syntaxhighlight>
 
{{out}}
<pre>
0.7071 0.7071
0.7071 0.7071
1.0000 1.0000
 
45.0000 0.7854
45 0.7854
45 0.7854
</pre>
 
=={{header|Elena}}==
Line 4,760 ⟶ 4,841:
</syntaxhighlight>
 
=={{header|RPL}}==
RPL has somewhere a system flag that defines if arguments passed to trigonometric functions are in degrees or radians. The words <code>DEG</code> and <code>RAD</code> set the flag appropriately.
We can therefore answer the task so:
π 4 / →NUM 'XRAD' STO
45 'XDEG' STO
XRAD RAD SIN XDEG DEG SIN
which will return <code>.707106781187</code> 2 times.
Another way is to stay in the same trigonometric mode and use <code>D→R</code> or <code>R→D</code> conversion words. This is the way used below:
RAD
π 4 / →NUM SIN 45 D→R SIN
π 3 / →NUM COS 60 D→R COS
π 6 / →NUM TAN 30 D→R TAN
{{out}}
<pre>
6: .707106781187
5: .707106781187
4: .499999999997
3: .499999999997
2: .577350269189
1: .577350269189
</pre>
As we have now in the stack the 6 values to be inversed, let's call the required functions in reverse order. The <code>6 ROLLD</code> instruction pushes the number from level 1 to level 6 of the stack, making thus the next number available for inversion.
ATAN R→D 6 ROLLD
ATAN 6 ROLLD
ACOS R→D 6 ROLLD
ACOS 6 ROLLD
ASIN R→D 6 ROLLD
ASIN 6 ROLLD
{{out}}
<pre>
6: .785398163397
5: 45
4: 1.0471975512
3: 60.0000000002
2: .523598775598
1: 30
</pre>
Calculations made with a HP-28S. Emulator has better precision and returns 60 for <code>60 D→R COS ACOS R→D</code>
=={{header|Ruby}}==
 
Line 5,440 ⟶ 5,559:
{{trans|Go}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var d = 30
1,978

edits