Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is php deg2rad() equal to mysql radians()

Are these functions the same? If not, what is an appropriate php equivalent to mysql's radians()

like image 975
JLeonard Avatar asked Dec 13 '09 21:12

JLeonard


2 Answers

Judging from their documentations (deg2rad, radians), they seem to do the same.

And a quick verification on a simple test-case :

mysql> select radians(0), radians(45), radians(90);
+------------+-------------------+-----------------+
| radians(0) | radians(45)       | radians(90)     |
+------------+-------------------+-----------------+
|          0 | 0.785398163397448 | 1.5707963267949 |
+------------+-------------------+-----------------+
1 row in set (0,00 sec)

And, in PHP :

var_dump(deg2rad(0), deg2rad(45), deg2rad(90));

also gives :

float 0
float 0.785398163397
float 1.57079632679

So, it seems they do quite the same...

like image 92
Pascal MARTIN Avatar answered Nov 17 '22 23:11

Pascal MARTIN


Consulting the documentation:

  • MySQL's RADIANS(x): returns the argument x, converted from degrees to radians.
  • PHP's DEG2RAD(): converts the number in degrees to the radian equivalent

...so yes, they are equivalent.

Was there something more specific you were looking for?

like image 45
OMG Ponies Avatar answered Nov 17 '22 23:11

OMG Ponies