WeixiangYan/CodeTransOcean huggingface dataset:
Task: Trigonometric functions




Go: package main

import (
    "fmt"
    "math"
)

const d = 30.
const r = d * math.Pi / 180

var s = .5
var c = math.Sqrt(3) / 2
var t = 1 / math.Sqrt(3)

func main() {
    fmt.Printf("sin(%9.6f deg) = %f\n", d, math.Sin(d*math.Pi/180))
    fmt.Printf("sin(%9.6f rad) = %f\n", r, math.Sin(r))
    fmt.Printf("cos(%9.6f deg) = %f\n", d, math.Cos(d*math.Pi/180))
    fmt.Printf("cos(%9.6f rad) = %f\n", r, math.Cos(r))
    fmt.Printf("tan(%9.6f deg) = %f\n", d, math.Tan(d*math.Pi/180))
    fmt.Printf("tan(%9.6f rad) = %f\n", r, math.Tan(r))
    fmt.Printf("asin(%f) = %9.6f deg\n", s, math.Asin(s)*180/math.Pi)
    fmt.Printf("asin(%f) = %9.6f rad\n", s, math.Asin(s))
    fmt.Printf("acos(%f) = %9.6f deg\n", c, math.Acos(c)*180/math.Pi)
    fmt.Printf("acos(%f) = %9.6f rad\n", c, math.Acos(c))
    fmt.Printf("atan(%f) = %9.6f deg\n", t, math.Atan(t)*180/math.Pi)
    fmt.Printf("atan(%f) = %9.6f rad\n", t, math.Atan(t))
}








Ada: with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_IO; use Ada.Text_IO;

procedure Trig is
   Degrees_Cycle : constant Float := 360.0;
   Radians_Cycle : constant Float := 2.0 * Ada.Numerics.Pi;
   Angle_Degrees : constant Float := 45.0;
   Angle_Radians : constant Float := Ada.Numerics.Pi / 4.0;
   procedure Put (V1, V2 : Float) is
   begin
      Put (V1, Aft => 5, Exp => 0);
      Put (" ");
      Put (V2, Aft => 5, Exp => 0);
      New_Line;
   end Put;
begin
   Put (Sin (Angle_Degrees, Degrees_Cycle), 
        Sin (Angle_Radians, Radians_Cycle));
   Put (Cos (Angle_Degrees, Degrees_Cycle), 
        Cos (Angle_Radians, Radians_Cycle));
   Put (Tan (Angle_Degrees, Degrees_Cycle), 
        Tan (Angle_Radians, Radians_Cycle));
   Put (Cot (Angle_Degrees, Degrees_Cycle), 
        Cot (Angle_Radians, Radians_Cycle));
   Put (ArcSin (Sin (Angle_Degrees, Degrees_Cycle), Degrees_Cycle), 
        ArcSin (Sin (Angle_Radians, Radians_Cycle), Radians_Cycle));
   Put (Arccos (Cos (Angle_Degrees, Degrees_Cycle), Degrees_Cycle), 
        Arccos (Cos (Angle_Radians, Radians_Cycle), Radians_Cycle));
   Put (Arctan (Y => Tan (Angle_Degrees, Degrees_Cycle)),
        Arctan (Y => Tan (Angle_Radians, Radians_Cycle)));
   Put (Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)), 
        Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)));
end Trig;
Task: Trigonometric functions





Java: public class Trig {
        public static void main(String[] args) {
                
                double radians = Math.PI / 4;
                double degrees = 45.0;
                
                System.out.println(Math.sin(radians) + " " + Math.sin(Math.toRadians(degrees)));
                
                System.out.println(Math.cos(radians) + " " + Math.cos(Math.toRadians(degrees)));
                
                System.out.println(Math.tan(radians) + " " + Math.tan(Math.toRadians(degrees)));
                
                double arcsin = Math.asin(Math.sin(radians));
                System.out.println(arcsin + " " + Math.toDegrees(arcsin));
                
                double arccos = Math.acos(Math.cos(radians));
                System.out.println(arccos + " " + Math.toDegrees(arccos));
                
                double arctan = Math.atan(Math.tan(radians));
                System.out.println(arctan + " " + Math.toDegrees(arctan));
        }
}







Ada: with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_IO; use Ada.Text_IO;

procedure Trig is
   Degrees_Cycle : constant Float := 360.0;
   Radians_Cycle : constant Float := 2.0 * Ada.Numerics.Pi;
   Angle_Degrees : constant Float := 45.0;
   Angle_Radians : constant Float := Ada.Numerics.Pi / 4.0;
   procedure Put (V1, V2 : Float) is
   begin
      Put (V1, Aft => 5, Exp => 0);
      Put (" ");
      Put (V2, Aft => 5, Exp => 0);
      New_Line;
   end Put;
begin
   Put (Sin (Angle_Degrees, Degrees_Cycle), 
        Sin (Angle_Radians, Radians_Cycle));
   Put (Cos (Angle_Degrees, Degrees_Cycle), 
        Cos (Angle_Radians, Radians_Cycle));
   Put (Tan (Angle_Degrees, Degrees_Cycle), 
        Tan (Angle_Radians, Radians_Cycle));
   Put (Cot (Angle_Degrees, Degrees_Cycle), 
        Cot (Angle_Radians, Radians_Cycle));
   Put (ArcSin (Sin (Angle_Degrees, Degrees_Cycle), Degrees_Cycle), 
        ArcSin (Sin (Angle_Radians, Radians_Cycle), Radians_Cycle));
   Put (Arccos (Cos (Angle_Degrees, Degrees_Cycle), Degrees_Cycle), 
        Arccos (Cos (Angle_Radians, Radians_Cycle), Radians_Cycle));
   Put (Arctan (Y => Tan (Angle_Degrees, Degrees_Cycle)),
        Arctan (Y => Tan (Angle_Radians, Radians_Cycle)));
   Put (Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)), 
        Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)));
end Trig;
Task: Trigonometric functions







Python: Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from math import degrees, radians, sin, cos, tan, asin, acos, atan, pi
>>> rad, deg = pi/4, 45.0
>>> print("Sine:", sin(rad), sin(radians(deg)))
Sine: 0.7071067811865475 0.7071067811865475
>>> print("Cosine:", cos(rad), cos(radians(deg)))
Cosine: 0.7071067811865476 0.7071067811865476
>>> print("Tangent:", tan(rad), tan(radians(deg)))
Tangent: 0.9999999999999999 0.9999999999999999
>>> arcsine = asin(sin(rad))
>>> print("Arcsine:", arcsine, degrees(arcsine))
Arcsine: 0.7853981633974482 44.99999999999999
>>> arccosine = acos(cos(rad))
>>> print("Arccosine:", arccosine, degrees(arccosine))
Arccosine: 0.7853981633974483 45.0
>>> arctangent = atan(tan(rad))
>>> print("Arctangent:", arctangent, degrees(arctangent))
Arctangent: 0.7853981633974483 45.0
>>>





Ada: with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_IO; use Ada.Text_IO;

procedure Trig is
   Degrees_Cycle : constant Float := 360.0;
   Radians_Cycle : constant Float := 2.0 * Ada.Numerics.Pi;
   Angle_Degrees : constant Float := 45.0;
   Angle_Radians : constant Float := Ada.Numerics.Pi / 4.0;
   procedure Put (V1, V2 : Float) is
   begin
      Put (V1, Aft => 5, Exp => 0);
      Put (" ");
      Put (V2, Aft => 5, Exp => 0);
      New_Line;
   end Put;
begin
   Put (Sin (Angle_Degrees, Degrees_Cycle), 
        Sin (Angle_Radians, Radians_Cycle));
   Put (Cos (Angle_Degrees, Degrees_Cycle), 
        Cos (Angle_Radians, Radians_Cycle));
   Put (Tan (Angle_Degrees, Degrees_Cycle), 
        Tan (Angle_Radians, Radians_Cycle));
   Put (Cot (Angle_Degrees, Degrees_Cycle), 
        Cot (Angle_Radians, Radians_Cycle));
   Put (ArcSin (Sin (Angle_Degrees, Degrees_Cycle), Degrees_Cycle), 
        ArcSin (Sin (Angle_Radians, Radians_Cycle), Radians_Cycle));
   Put (Arccos (Cos (Angle_Degrees, Degrees_Cycle), Degrees_Cycle), 
        Arccos (Cos (Angle_Radians, Radians_Cycle), Radians_Cycle));
   Put (Arctan (Y => Tan (Angle_Degrees, Degrees_Cycle)),
        Arctan (Y => Tan (Angle_Radians, Radians_Cycle)));
   Put (Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)), 
        Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)));
end Trig;
Task: Trigonometric functions








VB: Public Sub trig()
    Pi = WorksheetFunction.Pi()
    Debug.Print Sin(Pi / 2)
    Debug.Print Sin(90 * Pi / 180)
    Debug.Print Cos(0)
    Debug.Print Cos(0 * Pi / 180)
    Debug.Print Tan(Pi / 4)
    Debug.Print Tan(45 * Pi / 180)
    Debug.Print WorksheetFunction.Asin(1) * 2
    Debug.Print WorksheetFunction.Asin(1) * 180 / Pi
    Debug.Print WorksheetFunction.Acos(0) * 2
    Debug.Print WorksheetFunction.Acos(0) * 180 / Pi
    Debug.Print Atn(1) * 4
    Debug.Print Atn(1) * 180 / Pi
End Sub




Ada: with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_IO; use Ada.Text_IO;

procedure Trig is
   Degrees_Cycle : constant Float := 360.0;
   Radians_Cycle : constant Float := 2.0 * Ada.Numerics.Pi;
   Angle_Degrees : constant Float := 45.0;
   Angle_Radians : constant Float := Ada.Numerics.Pi / 4.0;
   procedure Put (V1, V2 : Float) is
   begin
      Put (V1, Aft => 5, Exp => 0);
      Put (" ");
      Put (V2, Aft => 5, Exp => 0);
      New_Line;
   end Put;
begin
   Put (Sin (Angle_Degrees, Degrees_Cycle), 
        Sin (Angle_Radians, Radians_Cycle));
   Put (Cos (Angle_Degrees, Degrees_Cycle), 
        Cos (Angle_Radians, Radians_Cycle));
   Put (Tan (Angle_Degrees, Degrees_Cycle), 
        Tan (Angle_Radians, Radians_Cycle));
   Put (Cot (Angle_Degrees, Degrees_Cycle), 
        Cot (Angle_Radians, Radians_Cycle));
   Put (ArcSin (Sin (Angle_Degrees, Degrees_Cycle), Degrees_Cycle), 
        ArcSin (Sin (Angle_Radians, Radians_Cycle), Radians_Cycle));
   Put (Arccos (Cos (Angle_Degrees, Degrees_Cycle), Degrees_Cycle), 
        Arccos (Cos (Angle_Radians, Radians_Cycle), Radians_Cycle));
   Put (Arctan (Y => Tan (Angle_Degrees, Degrees_Cycle)),
        Arctan (Y => Tan (Angle_Radians, Radians_Cycle)));
   Put (Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)), 
        Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)));
end Trig;
Task: Trigonometric functions

C: #include <math.h>
#include <stdio.h>

int main() {
  double pi = 4 * atan(1);
  
  double radians = pi / 4;
  double degrees = 45.0;
  double temp;
  
  printf("%f %f\n", sin(radians), sin(degrees * pi / 180));
  
  printf("%f %f\n", cos(radians), cos(degrees * pi / 180));
  
  printf("%f %f\n", tan(radians), tan(degrees * pi / 180));
  
  temp = asin(sin(radians));
  printf("%f %f\n", temp, temp * 180 / pi);
  
  temp = acos(cos(radians));
  printf("%f %f\n", temp, temp * 180 / pi);
  
  temp = atan(tan(radians));
  printf("%f %f\n", temp, temp * 180 / pi);

  return 0;
}
Task: Trigonometric functions



C#: 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();
        }
    }
}
Task: Trigonometric functions


C++: #include <iostream>
#include <cmath>

#ifdef M_PI 
double const pi = M_PI;
#else
double const pi = 4*std::atan(1);
#endif

double const degree = pi/180;

int main()
{
  std::cout << "=== radians ===\n";
  std::cout << "sin(pi/3) = " << std::sin(pi/3) << "\n";
  std::cout << "cos(pi/3) = " << std::cos(pi/3) << "\n";
  std::cout << "tan(pi/3) = " << std::tan(pi/3) << "\n";
  std::cout << "arcsin(1/2) = " << std::asin(0.5) << "\n";
  std::cout << "arccos(1/2) = " << std::acos(0.5) << "\n";
  std::cout << "arctan(1/2) = " << std::atan(0.5) << "\n";

  std::cout << "\n=== degrees ===\n";
  std::cout << "sin(60°) = " << std::sin(60*degree) << "\n";
  std::cout << "cos(60°) = " << std::cos(60*degree) << "\n";
  std::cout << "tan(60°) = " << std::tan(60*degree) << "\n";
  std::cout << "arcsin(1/2) = " << std::asin(0.5)/degree << "°\n";
  std::cout << "arccos(1/2) = " << std::acos(0.5)/degree << "°\n";
  std::cout << "arctan(1/2) = " << std::atan(0.5)/degree << "°\n";

  return 0;
}
Task: Trigonometric functions





Java: public class Trig {
        public static void main(String[] args) {
                
                double radians = Math.PI / 4;
                double degrees = 45.0;
                
                System.out.println(Math.sin(radians) + " " + Math.sin(Math.toRadians(degrees)));
                
                System.out.println(Math.cos(radians) + " " + Math.cos(Math.toRadians(degrees)));
                
                System.out.println(Math.tan(radians) + " " + Math.tan(Math.toRadians(degrees)));
                
                double arcsin = Math.asin(Math.sin(radians));
                System.out.println(arcsin + " " + Math.toDegrees(arcsin));
                
                double arccos = Math.acos(Math.cos(radians));
                System.out.println(arccos + " " + Math.toDegrees(arccos));
                
                double arctan = Math.atan(Math.tan(radians));
                System.out.println(arctan + " " + Math.toDegrees(arctan));
        }
}
Task: Trigonometric functions







Python: Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from math import degrees, radians, sin, cos, tan, asin, acos, atan, pi
>>> rad, deg = pi/4, 45.0
>>> print("Sine:", sin(rad), sin(radians(deg)))
Sine: 0.7071067811865475 0.7071067811865475
>>> print("Cosine:", cos(rad), cos(radians(deg)))
Cosine: 0.7071067811865476 0.7071067811865476
>>> print("Tangent:", tan(rad), tan(radians(deg)))
Tangent: 0.9999999999999999 0.9999999999999999
>>> arcsine = asin(sin(rad))
>>> print("Arcsine:", arcsine, degrees(arcsine))
Arcsine: 0.7853981633974482 44.99999999999999
>>> arccosine = acos(cos(rad))
>>> print("Arccosine:", arccosine, degrees(arccosine))
Arccosine: 0.7853981633974483 45.0
>>> arctangent = atan(tan(rad))
>>> print("Arctangent:", arctangent, degrees(arctangent))
Arctangent: 0.7853981633974483 45.0
>>>
Task: Trigonometric functions








VB: Public Sub trig()
    Pi = WorksheetFunction.Pi()
    Debug.Print Sin(Pi / 2)
    Debug.Print Sin(90 * Pi / 180)
    Debug.Print Cos(0)
    Debug.Print Cos(0 * Pi / 180)
    Debug.Print Tan(Pi / 4)
    Debug.Print Tan(45 * Pi / 180)
    Debug.Print WorksheetFunction.Asin(1) * 2
    Debug.Print WorksheetFunction.Asin(1) * 180 / Pi
    Debug.Print WorksheetFunction.Acos(0) * 2
    Debug.Print WorksheetFunction.Acos(0) * 180 / Pi
    Debug.Print Atn(1) * 4
    Debug.Print Atn(1) * 180 / Pi
End Sub
Task: Trigonometric functions




Go: package main

import (
    "fmt"
    "math"
)

const d = 30.
const r = d * math.Pi / 180

var s = .5
var c = math.Sqrt(3) / 2
var t = 1 / math.Sqrt(3)

func main() {
    fmt.Printf("sin(%9.6f deg) = %f\n", d, math.Sin(d*math.Pi/180))
    fmt.Printf("sin(%9.6f rad) = %f\n", r, math.Sin(r))
    fmt.Printf("cos(%9.6f deg) = %f\n", d, math.Cos(d*math.Pi/180))
    fmt.Printf("cos(%9.6f rad) = %f\n", r, math.Cos(r))
    fmt.Printf("tan(%9.6f deg) = %f\n", d, math.Tan(d*math.Pi/180))
    fmt.Printf("tan(%9.6f rad) = %f\n", r, math.Tan(r))
    fmt.Printf("asin(%f) = %9.6f deg\n", s, math.Asin(s)*180/math.Pi)
    fmt.Printf("asin(%f) = %9.6f rad\n", s, math.Asin(s))
    fmt.Printf("acos(%f) = %9.6f deg\n", c, math.Acos(c)*180/math.Pi)
    fmt.Printf("acos(%f) = %9.6f rad\n", c, math.Acos(c))
    fmt.Printf("atan(%f) = %9.6f deg\n", t, math.Atan(t)*180/math.Pi)
    fmt.Printf("atan(%f) = %9.6f rad\n", t, math.Atan(t))
}
Task: Trigonometric functions



C#: 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();
        }
    }
}








Fortran: PROGRAM Trig

  REAL pi, dtor, rtod, radians, degrees
 
  pi = 4.0 * ATAN(1.0)
  dtor = pi / 180.0
  rtod = 180.0 / pi
  radians = pi / 4.0
  degrees = 45.0 
 
  WRITE(*,*) SIN(radians), SIN(degrees*dtor)
  WRITE(*,*) COS(radians), COS(degrees*dtor)
  WRITE(*,*) TAN(radians), TAN(degrees*dtor)
  WRITE(*,*) ASIN(SIN(radians)), ASIN(SIN(degrees*dtor))*rtod
  WRITE(*,*) ACOS(COS(radians)), ACOS(COS(degrees*dtor))*rtod
  WRITE(*,*) ATAN(TAN(radians)), ATAN(TAN(degrees*dtor))*rtod

END PROGRAM Trig
Task: Trigonometric functions


C++: #include <iostream>
#include <cmath>

#ifdef M_PI 
double const pi = M_PI;
#else
double const pi = 4*std::atan(1);
#endif

double const degree = pi/180;

int main()
{
  std::cout << "=== radians ===\n";
  std::cout << "sin(pi/3) = " << std::sin(pi/3) << "\n";
  std::cout << "cos(pi/3) = " << std::cos(pi/3) << "\n";
  std::cout << "tan(pi/3) = " << std::tan(pi/3) << "\n";
  std::cout << "arcsin(1/2) = " << std::asin(0.5) << "\n";
  std::cout << "arccos(1/2) = " << std::acos(0.5) << "\n";
  std::cout << "arctan(1/2) = " << std::atan(0.5) << "\n";

  std::cout << "\n=== degrees ===\n";
  std::cout << "sin(60°) = " << std::sin(60*degree) << "\n";
  std::cout << "cos(60°) = " << std::cos(60*degree) << "\n";
  std::cout << "tan(60°) = " << std::tan(60*degree) << "\n";
  std::cout << "arcsin(1/2) = " << std::asin(0.5)/degree << "°\n";
  std::cout << "arccos(1/2) = " << std::acos(0.5)/degree << "°\n";
  std::cout << "arctan(1/2) = " << std::atan(0.5)/degree << "°\n";

  return 0;
}









Fortran: PROGRAM Trig

  REAL pi, dtor, rtod, radians, degrees
 
  pi = 4.0 * ATAN(1.0)
  dtor = pi / 180.0
  rtod = 180.0 / pi
  radians = pi / 4.0
  degrees = 45.0 
 
  WRITE(*,*) SIN(radians), SIN(degrees*dtor)
  WRITE(*,*) COS(radians), COS(degrees*dtor)
  WRITE(*,*) TAN(radians), TAN(degrees*dtor)
  WRITE(*,*) ASIN(SIN(radians)), ASIN(SIN(degrees*dtor))*rtod
  WRITE(*,*) ACOS(COS(radians)), ACOS(COS(degrees*dtor))*rtod
  WRITE(*,*) ATAN(TAN(radians)), ATAN(TAN(degrees*dtor))*rtod

END PROGRAM Trig
Task: Trigonometric functions

C: #include <math.h>
#include <stdio.h>

int main() {
  double pi = 4 * atan(1);
  
  double radians = pi / 4;
  double degrees = 45.0;
  double temp;
  
  printf("%f %f\n", sin(radians), sin(degrees * pi / 180));
  
  printf("%f %f\n", cos(radians), cos(degrees * pi / 180));
  
  printf("%f %f\n", tan(radians), tan(degrees * pi / 180));
  
  temp = asin(sin(radians));
  printf("%f %f\n", temp, temp * 180 / pi);
  
  temp = acos(cos(radians));
  printf("%f %f\n", temp, temp * 180 / pi);
  
  temp = atan(tan(radians));
  printf("%f %f\n", temp, temp * 180 / pi);

  return 0;
}










Fortran: PROGRAM Trig

  REAL pi, dtor, rtod, radians, degrees
 
  pi = 4.0 * ATAN(1.0)
  dtor = pi / 180.0
  rtod = 180.0 / pi
  radians = pi / 4.0
  degrees = 45.0 
 
  WRITE(*,*) SIN(radians), SIN(degrees*dtor)
  WRITE(*,*) COS(radians), COS(degrees*dtor)
  WRITE(*,*) TAN(radians), TAN(degrees*dtor)
  WRITE(*,*) ASIN(SIN(radians)), ASIN(SIN(degrees*dtor))*rtod
  WRITE(*,*) ACOS(COS(radians)), ACOS(COS(degrees*dtor))*rtod
  WRITE(*,*) ATAN(TAN(radians)), ATAN(TAN(degrees*dtor))*rtod

END PROGRAM Trig
Task: Trigonometric functions




Go: package main

import (
    "fmt"
    "math"
)

const d = 30.
const r = d * math.Pi / 180

var s = .5
var c = math.Sqrt(3) / 2
var t = 1 / math.Sqrt(3)

func main() {
    fmt.Printf("sin(%9.6f deg) = %f\n", d, math.Sin(d*math.Pi/180))
    fmt.Printf("sin(%9.6f rad) = %f\n", r, math.Sin(r))
    fmt.Printf("cos(%9.6f deg) = %f\n", d, math.Cos(d*math.Pi/180))
    fmt.Printf("cos(%9.6f rad) = %f\n", r, math.Cos(r))
    fmt.Printf("tan(%9.6f deg) = %f\n", d, math.Tan(d*math.Pi/180))
    fmt.Printf("tan(%9.6f rad) = %f\n", r, math.Tan(r))
    fmt.Printf("asin(%f) = %9.6f deg\n", s, math.Asin(s)*180/math.Pi)
    fmt.Printf("asin(%f) = %9.6f rad\n", s, math.Asin(s))
    fmt.Printf("acos(%f) = %9.6f deg\n", c, math.Acos(c)*180/math.Pi)
    fmt.Printf("acos(%f) = %9.6f rad\n", c, math.Acos(c))
    fmt.Printf("atan(%f) = %9.6f deg\n", t, math.Atan(t)*180/math.Pi)
    fmt.Printf("atan(%f) = %9.6f rad\n", t, math.Atan(t))
}







Fortran: PROGRAM Trig

  REAL pi, dtor, rtod, radians, degrees
 
  pi = 4.0 * ATAN(1.0)
  dtor = pi / 180.0
  rtod = 180.0 / pi
  radians = pi / 4.0
  degrees = 45.0 
 
  WRITE(*,*) SIN(radians), SIN(degrees*dtor)
  WRITE(*,*) COS(radians), COS(degrees*dtor)
  WRITE(*,*) TAN(radians), TAN(degrees*dtor)
  WRITE(*,*) ASIN(SIN(radians)), ASIN(SIN(degrees*dtor))*rtod
  WRITE(*,*) ACOS(COS(radians)), ACOS(COS(degrees*dtor))*rtod
  WRITE(*,*) ATAN(TAN(radians)), ATAN(TAN(degrees*dtor))*rtod

END PROGRAM Trig
Task: Trigonometric functions





Java: public class Trig {
        public static void main(String[] args) {
                
                double radians = Math.PI / 4;
                double degrees = 45.0;
                
                System.out.println(Math.sin(radians) + " " + Math.sin(Math.toRadians(degrees)));
                
                System.out.println(Math.cos(radians) + " " + Math.cos(Math.toRadians(degrees)));
                
                System.out.println(Math.tan(radians) + " " + Math.tan(Math.toRadians(degrees)));
                
                double arcsin = Math.asin(Math.sin(radians));
                System.out.println(arcsin + " " + Math.toDegrees(arcsin));
                
                double arccos = Math.acos(Math.cos(radians));
                System.out.println(arccos + " " + Math.toDegrees(arccos));
                
                double arctan = Math.atan(Math.tan(radians));
                System.out.println(arctan + " " + Math.toDegrees(arctan));
        }
}






Fortran: PROGRAM Trig

  REAL pi, dtor, rtod, radians, degrees
 
  pi = 4.0 * ATAN(1.0)
  dtor = pi / 180.0
  rtod = 180.0 / pi
  radians = pi / 4.0
  degrees = 45.0 
 
  WRITE(*,*) SIN(radians), SIN(degrees*dtor)
  WRITE(*,*) COS(radians), COS(degrees*dtor)
  WRITE(*,*) TAN(radians), TAN(degrees*dtor)
  WRITE(*,*) ASIN(SIN(radians)), ASIN(SIN(degrees*dtor))*rtod
  WRITE(*,*) ACOS(COS(radians)), ACOS(COS(degrees*dtor))*rtod
  WRITE(*,*) ATAN(TAN(radians)), ATAN(TAN(degrees*dtor))*rtod

END PROGRAM Trig