PHPServer Side ProgrammingProgramming

## Definition and Usage

Most trigonometric functions like sin, cos, tan etc require angle argument in radians. Whereas, in practice angle is represented in degrees. The rad2deg() function proves useful in conversion of radian angle to degrees.

This function returns a float number such that number=rad2deg(x) where x is angle in radians. angle in radian = angle in deg *180/pi

For example rad2deg(Π) is equal to 180 degrees

echo "angle in degrees = " . rad2deg($angle); ?> ## Output This will produce following result − rad2deg(3.1415926535898) = 180 ## Example Live Demo PHP constant M_PI_4 is equal to 45 degrees. We can confirm the result by following example. − <?php$angle=M_PI_4;
echo "rad2deg(" . $angle . ") = " . rad2deg($angle);
?>

## Output

This will produce following result −

rad2deg(0.78539816339745) = 45

## Example

Live Demo

Non numeric argument produces error: −

<?php
$angle="Hello"; echo "rad2deg(" .$angle . ") = " . rad2deg($angle); ?> ## Output This will produce following result − PHP Warning: rad2deg() expects parameter 1 to be float, string given ## Example Live Demo The argument number can be a binary, octal or hexadecimal decimal number. Following example converts ox0110 angle (in radians) to degrees <?php$angle=0b0110;
echo "rad2deg(" . $angle . ") = " . rad2deg($angle);
?>

## Output

This will produce following result −

rad2deg(6) = 343.77467707849