W3docs

asin()

Today, we will discuss the asin() function in PHP. This function is used to get the arc sine of a number, which is the angle whose sine is the given number.

The asin() function in PHP returns the arc sine (inverse sine) of a number — that is, the angle whose sine equals the given value. It is the mathematical reverse of sin(): where sin() turns an angle into a ratio, asin() turns that ratio back into an angle. The returned angle is expressed in radians.

This page covers the syntax, the valid input range, how to convert the result to degrees, edge cases like out-of-range input, and how asin() relates to the other PHP trigonometric functions.

Syntax

asin(float $num): float
  • $num — a float in the range -1 to 1 (inclusive). This is required because the sine of any real angle always falls in that range.
  • Return value — the arc sine of $num, in radians, in the range -π/2 to π/2 (about -1.5708 to 1.5708). If $num is outside -1..1, the function returns NAN (Not a Number).

A Basic Example

php— editable, runs on the server

We pass 0.5 to asin() and it returns roughly 0.5236 radians — which is exactly π / 6, the angle whose sine is 0.5.

Converting the Result to Degrees

Because asin() returns radians, you almost always convert to degrees for human-readable output. Use rad2deg() or multiply by 180 / pi():

<?php
$angle_in_radians = asin(0.5);
$angle_in_degrees = rad2deg($angle_in_radians);

echo $angle_in_degrees; // 30
?>

So the angle whose sine is 0.5 is 30 degrees. The reverse conversion — turning degrees into radians before calling a trig function — is done with deg2rad().

Common Values

These reference points are useful to memorize when working with asin():

<?php
echo asin(-1);  // -1.5707963… (-π/2, i.e. -90°)
echo "\n";
echo asin(0);   // 0           (sin 0° = 0)
echo "\n";
echo asin(1);   // 1.5707963…  (π/2, i.e. 90°)
?>

Handling Out-of-Range Input

If you pass a value smaller than -1 or larger than 1, the sine of no real angle could produce it, so asin() returns NAN. Guard against this when the input comes from user data or calculations:

<?php
$value = 2; // outside the valid -1..1 range

if ($value >= -1 && $value <= 1) {
    echo rad2deg(asin($value));
} else {
    echo "Input must be between -1 and 1.";
}
// Output: Input must be between -1 and 1.
?>

You can also detect the result with is_nan() after calling the function.

When Would I Use asin()?

asin() shows up whenever you need to recover an angle from a sine ratio:

  • Geometry and graphics — finding an angle of elevation from the ratio of opposite side to hypotenuse.
  • Navigation — computing latitudes and bearings in spherical trigonometry.
  • Physics — resolving angles in oscillation, optics (Snell's law), and projectile problems.

It belongs to the same family as acos() (arc cosine) and atan() (arc tangent). For the hyperbolic variant, see asinh().

Conclusion

The asin() function returns the arc sine of a number as an angle in radians, accepting input from -1 to 1 and returning NAN for anything outside that range. Remember to convert the result to degrees with rad2deg() when you need readable output, and to validate input that may fall outside the valid domain.

Practice

Practice
What is the function of 'asin' in PHP?
What is the function of 'asin' in PHP?
Was this page helpful?