Trigonometric functions: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(add ZX Spectrum)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 747:
0.785398 45.000000
</pre>
 
=={{header|C sharp|C#}}==
<lang csharp>using System;
 
namespace RosettaCode {
class Program {
static void Main(string[] args) {
Console.WriteLine("=== radians ===");
Console.WriteLine("sin (pi/3) = {0}", Math.Sin(Math.PI / 3));
Console.WriteLine("cos (pi/3) = {0}", Math.Cos(Math.PI / 3));
Console.WriteLine("tan (pi/3) = {0}", Math.Tan(Math.PI / 3));
Console.WriteLine("arcsin (1/2) = {0}", Math.Asin(0.5));
Console.WriteLine("arccos (1/2) = {0}", Math.Acos(0.5));
Console.WriteLine("arctan (1/2) = {0}", Math.Atan(0.5));
Console.WriteLine("");
Console.WriteLine("=== degrees ===");
Console.WriteLine("sin (60) = {0}", Math.Sin(60 * Math.PI / 180));
Console.WriteLine("cos (60) = {0}", Math.Cos(60 * Math.PI / 180));
Console.WriteLine("tan (60) = {0}", Math.Tan(60 * Math.PI / 180));
Console.WriteLine("arcsin (1/2) = {0}", Math.Asin(0.5) * 180/ Math.PI);
Console.WriteLine("arccos (1/2) = {0}", Math.Acos(0.5) * 180 / Math.PI);
Console.WriteLine("arctan (1/2) = {0}", Math.Atan(0.5) * 180 / Math.PI);
 
Console.ReadLine();
}
}
}</lang>
 
=={{header|C++}}==
Line 781 ⟶ 808:
}</lang>
 
=={{header|C sharp|C#}}==
<lang csharp>using System;
 
namespace RosettaCode {
class Program {
static void Main(string[] args) {
Console.WriteLine("=== radians ===");
Console.WriteLine("sin (pi/3) = {0}", Math.Sin(Math.PI / 3));
Console.WriteLine("cos (pi/3) = {0}", Math.Cos(Math.PI / 3));
Console.WriteLine("tan (pi/3) = {0}", Math.Tan(Math.PI / 3));
Console.WriteLine("arcsin (1/2) = {0}", Math.Asin(0.5));
Console.WriteLine("arccos (1/2) = {0}", Math.Acos(0.5));
Console.WriteLine("arctan (1/2) = {0}", Math.Atan(0.5));
Console.WriteLine("");
Console.WriteLine("=== degrees ===");
Console.WriteLine("sin (60) = {0}", Math.Sin(60 * Math.PI / 180));
Console.WriteLine("cos (60) = {0}", Math.Cos(60 * Math.PI / 180));
Console.WriteLine("tan (60) = {0}", Math.Tan(60 * Math.PI / 180));
Console.WriteLine("arcsin (1/2) = {0}", Math.Asin(0.5) * 180/ Math.PI);
Console.WriteLine("arccos (1/2) = {0}", Math.Acos(0.5) * 180 / Math.PI);
Console.WriteLine("arctan (1/2) = {0}", Math.Atan(0.5) * 180 / Math.PI);
 
Console.ReadLine();
}
}
}</lang>
=={{header|Clojure}}==
 
Line 1,066 ⟶ 1,067:
{{out}}
true
 
=={{header|F_Sharp|F#}}==
<lang fsharp>open NUnit.Framework
open FsUnit
 
// radian
 
[<Test>]
let ``Verify that sin pi returns 0`` () =
let x = System.Math.Sin System.Math.PI
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that cos pi returns -1`` () =
let x = System.Math.Cos System.Math.PI
System.Math.Round(x,5) |> should equal -1
 
[<Test>]
let ``Verify that tan pi returns 0`` () =
let x = System.Math.Tan System.Math.PI
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that sin pi/2 returns 1`` () =
let x = System.Math.Sin (System.Math.PI / 2.0)
System.Math.Round(x,5) |> should equal 1
 
[<Test>]
let ``Verify that cos pi/2 returns -1`` () =
let x = System.Math.Cos (System.Math.PI / 2.0)
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that sin pi/3 returns sqrt 3/2`` () =
let actual = System.Math.Sin (System.Math.PI / 3.0)
let expected = System.Math.Round((System.Math.Sqrt 3.0) / 2.0, 5)
System.Math.Round(actual,5) |> should equal expected
 
[<Test>]
let ``Verify that cos pi/3 returns -1`` () =
let x = System.Math.Cos (System.Math.PI / 3.0)
System.Math.Round(x,5) |> should equal 0.5
 
[<Test>]
let ``Verify that cos and sin of pi/4 return same value`` () =
let c = System.Math.Cos (System.Math.PI / 4.0)
let s = System.Math.Sin (System.Math.PI / 4.0)
System.Math.Round(c,5) = System.Math.Round(s,5) |> should be True
 
[<Test>]
let ``Verify that acos pi/3 returns 1/2`` () =
let actual = System.Math.Acos 0.5
let expected = System.Math.Round((System.Math.PI / 3.0),5)
System.Math.Round(actual,5) |> should equal expected
 
[<Test>]
let ``Verify that asin 1 returns pi/2`` () =
let actual = System.Math.Asin 1.0
let expected = System.Math.Round((System.Math.PI / 2.0),5)
System.Math.Round(actual,5) |> should equal expected
 
[<Test>]
let ``Verify that atan 0 returns 0`` () =
let actual = System.Math.Atan 0.0
let expected = System.Math.Round(0.0,5)
System.Math.Round(actual,5) |> should equal expected
 
// degree
 
let toRadians d = d * System.Math.PI / 180.0
 
[<Test>]
let ``Verify that pi is 180 degrees`` () =
toRadians 180.0 |> should equal System.Math.PI
 
[<Test>]
let ``Verify that pi/2 is 90 degrees`` () =
toRadians 90.0 |> should equal (System.Math.PI / 2.0)
 
[<Test>]
let ``Verify that pi/3 is 60 degrees`` () =
toRadians 60.0 |> should equal (System.Math.PI / 3.0)
 
[<Test>]
let ``Verify that sin 180 returns 0`` () =
let x = System.Math.Sin (toRadians 180.0)
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that cos 180 returns -1`` () =
let x = System.Math.Cos (toRadians 180.0)
System.Math.Round(x,5) |> should equal -1
 
[<Test>]
let ``Verify that tan 180 returns 0`` () =
let x = System.Math.Tan (toRadians 180.0)
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that sin 90 returns 1`` () =
let x = System.Math.Sin (toRadians 90.0)
System.Math.Round(x,5) |> should equal 1
 
[<Test>]
let ``Verify that cos 90 returns -1`` () =
let x = System.Math.Cos (toRadians 90.0)
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that sin 60 returns sqrt 3/2`` () =
let actual = System.Math.Sin (toRadians 60.0)
let expected = System.Math.Round((System.Math.Sqrt 3.0) / 2.0, 5)
System.Math.Round(actual,5) |> should equal expected
 
[<Test>]
let ``Verify that cos 60 returns -1`` () =
let x = System.Math.Cos (toRadians 60.0)
System.Math.Round(x,5) |> should equal 0.5
 
[<Test>]
let ``Verify that cos and sin of 45 return same value`` () =
let c = System.Math.Cos (toRadians 45.0)
let s = System.Math.Sin (toRadians 45.0)
System.Math.Round(c,5) = System.Math.Round(s,5) |> should be True</lang>
 
=={{header|Factor}}==
Line 1,312 ⟶ 1,437:
Arc Tangent : 0.7853981633974483 45
</pre>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>open NUnit.Framework
open FsUnit
 
// radian
 
[<Test>]
let ``Verify that sin pi returns 0`` () =
let x = System.Math.Sin System.Math.PI
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that cos pi returns -1`` () =
let x = System.Math.Cos System.Math.PI
System.Math.Round(x,5) |> should equal -1
 
[<Test>]
let ``Verify that tan pi returns 0`` () =
let x = System.Math.Tan System.Math.PI
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that sin pi/2 returns 1`` () =
let x = System.Math.Sin (System.Math.PI / 2.0)
System.Math.Round(x,5) |> should equal 1
 
[<Test>]
let ``Verify that cos pi/2 returns -1`` () =
let x = System.Math.Cos (System.Math.PI / 2.0)
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that sin pi/3 returns sqrt 3/2`` () =
let actual = System.Math.Sin (System.Math.PI / 3.0)
let expected = System.Math.Round((System.Math.Sqrt 3.0) / 2.0, 5)
System.Math.Round(actual,5) |> should equal expected
 
[<Test>]
let ``Verify that cos pi/3 returns -1`` () =
let x = System.Math.Cos (System.Math.PI / 3.0)
System.Math.Round(x,5) |> should equal 0.5
 
[<Test>]
let ``Verify that cos and sin of pi/4 return same value`` () =
let c = System.Math.Cos (System.Math.PI / 4.0)
let s = System.Math.Sin (System.Math.PI / 4.0)
System.Math.Round(c,5) = System.Math.Round(s,5) |> should be True
 
[<Test>]
let ``Verify that acos pi/3 returns 1/2`` () =
let actual = System.Math.Acos 0.5
let expected = System.Math.Round((System.Math.PI / 3.0),5)
System.Math.Round(actual,5) |> should equal expected
 
[<Test>]
let ``Verify that asin 1 returns pi/2`` () =
let actual = System.Math.Asin 1.0
let expected = System.Math.Round((System.Math.PI / 2.0),5)
System.Math.Round(actual,5) |> should equal expected
 
[<Test>]
let ``Verify that atan 0 returns 0`` () =
let actual = System.Math.Atan 0.0
let expected = System.Math.Round(0.0,5)
System.Math.Round(actual,5) |> should equal expected
 
// degree
 
let toRadians d = d * System.Math.PI / 180.0
 
[<Test>]
let ``Verify that pi is 180 degrees`` () =
toRadians 180.0 |> should equal System.Math.PI
 
[<Test>]
let ``Verify that pi/2 is 90 degrees`` () =
toRadians 90.0 |> should equal (System.Math.PI / 2.0)
 
[<Test>]
let ``Verify that pi/3 is 60 degrees`` () =
toRadians 60.0 |> should equal (System.Math.PI / 3.0)
 
[<Test>]
let ``Verify that sin 180 returns 0`` () =
let x = System.Math.Sin (toRadians 180.0)
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that cos 180 returns -1`` () =
let x = System.Math.Cos (toRadians 180.0)
System.Math.Round(x,5) |> should equal -1
 
[<Test>]
let ``Verify that tan 180 returns 0`` () =
let x = System.Math.Tan (toRadians 180.0)
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that sin 90 returns 1`` () =
let x = System.Math.Sin (toRadians 90.0)
System.Math.Round(x,5) |> should equal 1
 
[<Test>]
let ``Verify that cos 90 returns -1`` () =
let x = System.Math.Cos (toRadians 90.0)
System.Math.Round(x,5) |> should equal 0
 
[<Test>]
let ``Verify that sin 60 returns sqrt 3/2`` () =
let actual = System.Math.Sin (toRadians 60.0)
let expected = System.Math.Round((System.Math.Sqrt 3.0) / 2.0, 5)
System.Math.Round(actual,5) |> should equal expected
 
[<Test>]
let ``Verify that cos 60 returns -1`` () =
let x = System.Math.Cos (toRadians 60.0)
System.Math.Round(x,5) |> should equal 0.5
 
[<Test>]
let ``Verify that cos and sin of 45 return same value`` () =
let c = System.Math.Cos (toRadians 45.0)
let s = System.Math.Sin (toRadians 45.0)
System.Math.Round(c,5) = System.Math.Round(s,5) |> should be True</lang>
 
=={{header|GAP}}==
Line 2,402 ⟶ 2,403:
 
(Lacking in this code but present in GNU Octave: sinh, cosh, tanh, coth and inverses)
 
 
=={{header|Oforth}}==
Line 3,700:
0.785398163397448 45
</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2016.01}}
 
<lang perl6>say sin(pi/3);
say cos(pi/4);
say tan(pi/6);
 
say asin(sqrt(3)/2);
say acos(1/sqrt 2);
say atan(1/sqrt 3);</lang>
 
=={{header|Phix}}==
Line 4,053 ⟶ 4,042:
(define arctan (atan (tan radians)))
(display (format "~a ~a" arctan (* arctan (/ 180 pi))))</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2016.01}}
 
<lang perl6>say sin(pi/3);
say cos(pi/4);
say tan(pi/6);
 
say asin(sqrt(3)/2);
say acos(1/sqrt 2);
say atan(1/sqrt 3);</lang>
 
=={{header|RapidQ}}==
Line 4,831 ⟶ 4,832:
45
</pre>
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
10,327

edits