the sin / cos / tan family

sin(float $num): float — cos(float $num): float — tan(float $num): float — asin(float $num): float …

Quick reference for the trigonometric family: basic (sin/cos/tan), inverse (asin/acos/atan) and hyperbolic (sinh/cosh/tanh) functions are built in across all languages — and every argument is in radians, not degrees; convert with deg2rad first.

C C23

C23
#include <math.h>
#include <stdio.h>

int main(void) {
    // all trig functions take radians, not degrees
    // (M_PI is a POSIX extension, not ISO C, so the literal is written out)
    const double PI = 3.14159265358979323846;
    printf("%.10f\n", sin(PI / 6));    // 30 degrees
    printf("%.10f\n", cos(PI / 3));    // 60 degrees
    printf("%.10f\n", tan(PI / 4));    // 45 degrees
    printf("%.10f\n", atan(1.0));      // the inverse family: atan(1) is pi/4
    printf("%.10f\n", asin(sin(0.5))); // inverse round-trips back to 0.5
    printf("%.10f\n", sinh(1.0));      // hyperbolic sine
    printf("%.10f\n", cosh(1.0));      // hyperbolic cosine
    return 0;
}
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

C++ C++26

C++26
#include <cmath>
#include <cstdio>

int main() {
    // the C++ family lives in <cmath> under std::
    const double PI = 3.14159265358979323846;
    std::printf("%.10f\n", std::sin(PI / 6));    // 30 degrees
    std::printf("%.10f\n", std::cos(PI / 3));    // 60 degrees
    std::printf("%.10f\n", std::tan(PI / 4));    // 45 degrees
    std::printf("%.10f\n", std::atan(1.0));      // atan(1) is pi/4
    std::printf("%.10f\n", std::asin(std::sin(0.5)));
    std::printf("%.10f\n", std::sinh(1.0));      // hyperbolic sine
    std::printf("%.10f\n", std::cosh(1.0));      // hyperbolic cosine
    return 0;
}
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

C# v11.0.100

v11.0.100
// the .NET family lives on System.Math (arguments in radians)
Console.WriteLine(Math.Sin(Math.PI / 6).ToString("F10"));   // 30 degrees
Console.WriteLine(Math.Cos(Math.PI / 3).ToString("F10"));   // 60 degrees
Console.WriteLine(Math.Tan(Math.PI / 4).ToString("F10"));   // 45 degrees
Console.WriteLine(Math.Atan(1).ToString("F10"));            // atan(1) is pi/4
Console.WriteLine(Math.Asin(Math.Sin(0.5)).ToString("F10")); // round trip
Console.WriteLine(Math.Sinh(1).ToString("F10"));            // hyperbolic sine
Console.WriteLine(Math.Cosh(1).ToString("F10"));            // hyperbolic cosine
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"math"
)

func main() {
	// the Go family lives in package math (arguments in radians)
	fmt.Printf("%.10f\n", math.Sin(math.Pi/6))   // 30 degrees
	fmt.Printf("%.10f\n", math.Cos(math.Pi/3))   // 60 degrees
	fmt.Printf("%.10f\n", math.Tan(math.Pi/4))   // 45 degrees
	fmt.Printf("%.10f\n", math.Atan(1))          // atan(1) is pi/4
	fmt.Printf("%.10f\n", math.Asin(math.Sin(0.5)))
	fmt.Printf("%.10f\n", math.Sinh(1))          // hyperbolic sine
	fmt.Printf("%.10f\n", math.Cosh(1))          // hyperbolic cosine
}
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        // the Java family lives on java.lang.Math (arguments in radians)
        System.out.printf("%.10f%n", Math.sin(Math.PI / 6));   // 30 degrees
        System.out.printf("%.10f%n", Math.cos(Math.PI / 3));   // 60 degrees
        System.out.printf("%.10f%n", Math.tan(Math.PI / 4));   // 45 degrees
        System.out.printf("%.10f%n", Math.atan(1));            // atan(1) is pi/4
        System.out.printf("%.10f%n", Math.asin(Math.sin(0.5)));
        System.out.printf("%.10f%n", Math.sinh(1));            // hyperbolic sine
        System.out.printf("%.10f%n", Math.cosh(1));            // hyperbolic cosine
    }
}
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

JavaScript v26.13.1

v26.13.1
// the JavaScript family lives on the global Math object (arguments in radians)
console.log(Math.sin(Math.PI / 6).toFixed(10));    // 30 degrees
console.log(Math.cos(Math.PI / 3).toFixed(10));    // 60 degrees
console.log(Math.tan(Math.PI / 4).toFixed(10));    // 45 degrees
console.log(Math.atan(1).toFixed(10));             // atan(1) is pi/4
console.log(Math.asin(Math.sin(0.5)).toFixed(10)); // round trip
console.log(Math.sinh(1).toFixed(10));             // hyperbolic sine
console.log(Math.cosh(1).toFixed(10));             // hyperbolic cosine
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

PHP v8.6.0

v8.6.0
// PHP's trig family: sin/cos/tan, asin/acos/atan, sinh/cosh/tanh
// every argument is in radians - convert degrees with deg2rad() first
printf("%.10f\n", sin(M_PI / 6));    // 30 degrees
printf("%.10f\n", cos(M_PI / 3));    // 60 degrees
printf("%.10f\n", tan(M_PI / 4));    // 45 degrees
printf("%.10f\n", atan(1));          // atan(1) is pi/4
printf("%.10f\n", asin(sin(0.5)));   // inverse round-trips back to 0.5
printf("%.10f\n", sinh(1));          // hyperbolic sine
printf("%.10f\n", cosh(1));          // hyperbolic cosine
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

Python v3.15.2

v3.15.2
import math

# the Python family lives in the math module (arguments in radians)
print(f"{math.sin(math.pi / 6):.10f}")    # 30 degrees
print(f"{math.cos(math.pi / 3):.10f}")    # 60 degrees
print(f"{math.tan(math.pi / 4):.10f}")    # 45 degrees
print(f"{math.atan(1):.10f}")             # atan(1) is pi/4
print(f"{math.asin(math.sin(0.5)):.10f}") # round trip
print(f"{math.sinh(1):.10f}")             # hyperbolic sine
print(f"{math.cosh(1):.10f}")             # hyperbolic cosine
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

Rust v1.99.1

v1.99.1
fn main() {
    // Rust exposes the family as f64 methods (arguments in radians)
    let pi = std::f64::consts::PI;
    println!("{:.10}", (pi / 6.0).sin());    // 30 degrees
    println!("{:.10}", (pi / 3.0).cos());    // 60 degrees
    println!("{:.10}", (pi / 4.0).tan());    // 45 degrees
    println!("{:.10}", 1.0_f64.atan());      // atan(1) is pi/4
    println!("{:.10}", 0.5_f64.sin().asin()); // round trip
    println!("{:.10}", 1.0_f64.sinh());      // hyperbolic sine
    println!("{:.10}", 1.0_f64.cosh());      // hyperbolic cosine
}
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

TypeScript v26.13.1

v26.13.1
// TypeScript shares JavaScript's Math family (arguments in radians)
console.log(Math.sin(Math.PI / 6).toFixed(10));    // 30 degrees
console.log(Math.cos(Math.PI / 3).toFixed(10));    // 60 degrees
console.log(Math.tan(Math.PI / 4).toFixed(10));    // 45 degrees
console.log(Math.atan(1).toFixed(10));             // atan(1) is pi/4
console.log(Math.asin(Math.sin(0.5)).toFixed(10)); // round trip
console.log(Math.sinh(1).toFixed(10));             // hyperbolic sine
console.log(Math.cosh(1).toFixed(10));             // hyperbolic cosine
Output
0.5000000000
0.5000000000
1.0000000000
0.7853981634
0.5000000000
1.1752011936
1.5430806348

Language differences

PHP: basic trig sin/cos/tan, inverse asin/acos/atan and hyperbolic sinh/cosh/tanh are all built in; every argument is in radians — convert degrees with deg2rad() first (see the deg2rad_rad2deg entry), or 30 will be read as 30 radians.

The radians lesson: pi/6 radians = 30 degrees and sin(pi/6) = 0.5; atan(1) = pi/4 ~ 0.7853981634 — the demos use fixed radian values with %.10f formatted assertions to sidestep ULP literal differences.

Cross-language family map: C/C++ <math.h>/std::, Java Math., C# Math., Go math., Rust f64 methods, Python math, JS/TS Math — names follow each language's casing convention, all are native built-ins with identical semantics; "no difference" is itself the comparison conclusion of this entry.

Inverse-trig domain: asin/acos arguments must lie in [-1, 1]; out of range yields NAN (measured on this machine: PHP's asin(2) silently returns NAN — clamp in production code); atan has no such limit.

Round-trip assertion: asin(sin(0.5)) returns 0.5, identical across all ten languages under %.10f; longer chains (sin -> asin -> sin) can differ by 1 ulp, which fixed-precision printing absorbs.

Hyperbolic family: sinh(1) ~ 1.1752011936, cosh(1) ~ 1.5430806348; the identity cosh^2 x - sinh^2 x = 1 is a handy self-check (it holds here to the 10th decimal).

tanh(1) is deliberately not demoed: its value 0.7615941559... sits exactly on a rounding boundary at the 10th decimal, and some implementations disagree in the last digit by 1 ulp — a teaching entry only asserts values far from rounding boundaries.

See also: inverse hyperbolics asinh/acosh/atanh exist in all languages (not demoed); the pi constant has its own entry.