Open In App

PHP rad2deg() Function

Measurement of Angle is one of the foundation stones of Geometry and Trigonometry, and the two most commonly used methods of measurement are Degrees and Radians. Because of it’s simplicity many prefer to use degree over Radian. Some of the reasons that makes degrees more preferable are:

Thus in some cases we may require to convert from radians to degrees, this is where the method rad2deg() comes in aid.



Syntax:

float rad2deg($value)

Parameters: The function takes a single parameter $value which is of type float that represents an angle in Radians.



Return Type: This function returns a float value that represents the Degree equivalent of the given angle $value.

Examples:

Input :  $value = M_PI_4;
Output : 45

Input : $value = M_PI_2;
Output : 90

Input : $value = M_PI;
Output : 180
         

Below program illustrates the working of rad2deg() in PHP:




<?php
  
// PHP code to illustrate the working of rad2deg()
  
$rad = M_PI;
$k = 1;
  
for(;$k<=8;$k*=2, $rad/=2)
{
    if($k!=1)
       echo 'pi/'.$k.' = '.rad2deg($rad)."\n";
    else
       echo 'pi = '.rad2deg($rad)."\n";
}
  
?>

Output:

pi = 180
pi/2 = 90
pi/4 = 45
pi/8 = 22.5

Important points to note:

Reference:
http://php.net/manual/en/function.rad2deg.php

Article Tags :