PHP sin() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

In PHP, sin() returns the sine of an angle given in radians.

Sine is a basic trigonometry function. It returns a value between -1 and 1. If your angle is in degrees, convert it with deg2rad() first.

Syntax

Call sin() with the values you need. Start with this line.

PHP
$result = sin(M_PI_2);
CallWhat it does
sin(0)Returns 0.
sin(M_PI_2)Returns 1, the sine of 90 degrees.
sin(deg2rad(30))Returns about 0.5.

The angle must be in radians. Because computers store pi approximately, sin(M_PI) is a tiny number such as 1.2246E-16 instead of exactly 0. Use round() to clean it up.

Library declarations
PHP
sin(float $num): float

Parameters

ParameterDescription
numRequired. The angle in radians.

Return Value

Return ValueDescription
floatThe sine of the angle, between -1 and 1. Returns NAN for infinite input.

PHP Examples

Example 1 — Sine of Common Angles

Use radian constants to try sin() with well-known angles.

PHP
<?php
echo sin(0), PHP_EOL;
echo sin(M_PI_2), PHP_EOL;
echo round(sin(deg2rad(30)), 2), PHP_EOL;

How It Works

  1. sin(0) is 0.
  2. M_PI_2 is 90 degrees in radians, and its sine is 1.
  3. deg2rad(30) converts 30 degrees to radians.
  4. round() cleans up tiny floating-point errors and shows 0.5.

Example 2 — Floating-Point Noise and Infinity

The sine of pi should be 0, but floats are not perfectly exact.

PHP
<?php
echo sin(M_PI), PHP_EOL;
echo round(sin(M_PI), 10), PHP_EOL;
echo sin(INF), PHP_EOL;

How It Works

  1. M_PI is only an approximation of pi, so sin(M_PI) is a very tiny number, not exactly 0.
  2. PHP prints it in scientific notation, E-16 meaning 0.0000000000000001.
  3. round(..., 10) removes the noise and shows 0.
  4. sin(INF) is undefined, so PHP returns NAN.

Example 3 — Sine for Angles in Degrees

Convert each degree value to radians before calling sin().

PHP
<?php
$angles = [0, 30, 90, 270];

foreach ($angles as $deg) {
    $value = round(sin(deg2rad($deg)), 2);
    echo $deg, " degrees: ", $value, PHP_EOL;
}

How It Works

  1. Create an array of angles in degrees.
  2. deg2rad() converts each angle to radians.
  3. sin() returns the sine, and round() keeps two decimals.
  4. The output shows that sine goes up to 1 at 90 degrees and down to -1 at 270 degrees.

Frequently Asked Questions

sin() returns the sine of an angle in radians. The result is always between -1 and 1.
Radians. To use degrees, convert them first with deg2rad(), for example sin(deg2rad(30)).
M_PI is a floating-point approximation of pi, so the result is a tiny number near zero. Use round() to display it as 0.
From -1 to 1. Infinite input returns NAN.
The inverse is asin(), which returns the angle in radians for a given sine value.

Next: sinh()

sinh() returns the hyperbolic sine of a number.

sinh() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful