PHP asin() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

The PHP asin() function returns the arc sine of a number, which is the angle whose sine is that number.

The angle is returned in radians, and the input must be between -1 and 1.

Syntax

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

PHP
$angle = asin($num);
CallWhat it does
asin(0)Returns 0 because sin(0) is 0.
asin(0.5)Returns about 0.5236 (pi / 6).
asin(1)Returns about 1.5708 (pi / 2).

asin() is the opposite of sin(). Use rad2deg() to see the angle in degrees.

Library declarations
PHP
asin(float $num): float

Parameters

ParameterDescription
numRequired. The sine value to work on. It must be between -1 and 1 to get a real result.

Return Value

Return ValueDescription
floatThe arc sine of $num in radians, from -pi/2 to pi/2. Returns NAN if $num is outside -1 to 1.

PHP Examples

Example 1 — Basic asin() usage

This example finds the arc sine of a few well-known values and rounds the results.

PHP
<?php
echo asin(0) . PHP_EOL;
echo round(asin(0.5), 4) . PHP_EOL;
echo round(asin(1), 4) . PHP_EOL;
echo round(asin(-1), 4) . PHP_EOL;

How It Works

  1. asin(0) returns 0 because the sine of 0 is 0.
  2. asin(0.5) is pi / 6, which rounds to 0.5236.
  3. asin(1) is pi / 2, which rounds to 1.5708.
  4. asin(-1) is -pi / 2, so the result is negative: -1.5708.

Example 2 — Out of range input

No angle has a sine bigger than 1 or smaller than -1, so asin() returns NAN for those inputs.

PHP
<?php
var_dump(asin(1.5));
var_dump(asin(-2));

$angle = asin(3);
echo is_nan($angle) ? 'Not a valid sine value' : 'OK';
echo PHP_EOL;

How It Works

  1. asin(1.5) is outside -1 to 1, so PHP returns float(NAN).
  2. asin(-2) is also outside the range and returns NAN.
  3. We save asin(3) in $angle and test it with is_nan().
  4. is_nan() is true, so the message Not a valid sine value is printed.

Example 3 — Find an angle in degrees

Imagine a ramp that rises 1 meter over a 2 meter long slope. asin() can tell us the angle of that ramp.

PHP
<?php
$height = 1;
$slope = 2;

$radians = asin($height / $slope);
$degrees = rad2deg($radians);

echo "Ramp angle: " . round($degrees, 2) . " degrees" . PHP_EOL;

How It Works

  1. The sine of an angle is height divided by slope length, so 1 / 2 = 0.5.
  2. asin(0.5) gives the angle in radians.
  3. rad2deg() converts it to degrees, which is 30.000000000000004.
  4. round(..., 2) cleans it up, so the ramp angle prints as 30 degrees.

Frequently Asked Questions

It returns the arc sine of a number as a float in radians, between -pi/2 and pi/2.
PHP returns NAN. It does not throw an error.
Wrap the result in rad2deg(), for example rad2deg(asin(0.5)). That gives 30 degrees after rounding.
sin() takes an angle and returns its sine. asin() takes a sine value and returns the angle.
It is about 1.5708, which is pi / 2 radians or 90 degrees.

Next: asinh()

asinh() function returns the inverse hyperbolic sine of a number.

asinh() 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