rad2deg() function in PHP

The rad2deg() function converts radian values to degree values. It returns the equivalent of a radian value in degrees, making it useful for mathematical calculations and geometric computations.

Syntax

rad2deg(val)

Parameters

  • val − The radian value to be converted into degrees. This should be a numeric value representing an angle in radians.

Return Value

The rad2deg() function returns the equivalent of the input value in degrees as a float.

Example 1: Converting Pi Radians

Converting ? radians (180 degrees) to degrees −

<?php
    echo rad2deg(pi());
?>
180

Example 2: Converting Pi/2 Radians

Converting ?/2 radians (90 degrees) to degrees −

<?php
    echo rad2deg(pi()/2);
?>
90

Example 3: Converting Pi/8 Radians

Converting ?/8 radians (22.5 degrees) to degrees −

<?php
    echo rad2deg(pi()/8);
?>
22.5

Example 4: Multiple Conversions

Converting various radian values in a single script −

<?php
    $radians = array(0, pi()/6, pi()/4, pi()/3, pi()/2, pi());
    
    foreach($radians as $rad) {
        echo $rad . " radians = " . rad2deg($rad) . " degrees<br>";
    }
?>
0 radians = 0 degrees
0.52359877559830 radians = 30 degrees
0.78539816339745 radians = 45 degrees
1.0471975511966 radians = 60 degrees
1.5707963267949 radians = 90 degrees
3.1415926535898 radians = 180 degrees

Conclusion

The rad2deg() function is essential for converting radian measurements to degrees in mathematical calculations. It's commonly used with trigonometric functions and geometric computations where angle conversions are required.

Updated on: 2026-03-15T07:29:59+05:30

115 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements