GingerRobot Posted August 27, 2007 Share Posted August 27, 2007 I've just noticed that this statement: echo tan(deg2rad(360)); Produces an answer of -2.44921270764E-016. Yet if i put tan(360) into my calculator, the answer is 0 - which i always thought it was. Perhaps ive missed some crucial part of maths somewhere along the line. As far as i know, tanx = sinx/cosx. So tanx = 0/1 (where x is 360). It was my understanding that 0 divided by anything is 0. Is this not the case? Any information would be appreciated. Edit: Ive just noticed that the problems seem to stem from the sin function. sin(deg2rad(360)) gives -2.44921270764E-016, rather than 0. Yet sin(deg2rad(0) does give the answer as 0. Any thoughts? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 27, 2007 Share Posted August 27, 2007 Bug? Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 27, 2007 Share Posted August 27, 2007 It was my understanding that 0 divided by anything is 0. Is this not the case? Nope. 0/0 is undefined. http://mathforum.org/dr.math/faq/faq.divideby0.html Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 27, 2007 Author Share Posted August 27, 2007 Daniel: I suppose its possible. I can't believe im the first person ever to notice, however. Tibberous: Yeah, ok, Anything divided by 0 is undefined, im with you there. However, im talking about dividing 0 by something else - which should be 0. Perhaps my original statement should have been "0 divided by any other non-zero number is 0" Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 27, 2007 Share Posted August 27, 2007 It was my understanding that 0 divided by anything is 0. Is this not the case? Nope. 0/0 is undefined. http://mathforum.org/dr.math/faq/faq.divideby0.html Sure, but sin 360 = 0 and cos 360 = 1. tan x is defined as sin x/cos x therefore must tan 360 = sin 360/cos 360 = 0/1 = 0 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 27, 2007 Share Posted August 27, 2007 It has to do with the nature of the discovery of this answer. As i've stated in the board on higher order differentials the way computers solve trig functions is not based on a known table of values, but based on the summing of an infinite series. http://en.wikipedia.org/wiki/Taylor_series In this case it is solving the first X (x is probably like 100 cause a computer can do that) values of the infinite series of sin/cos thus why you are producing an answer that is approximately zero. The reason one produces it and the other doesn't is because there is a table of the special values predefine in most caluclations 0pi, pi/3, pi/4, pi/2 pi/6 etc etc and all variants of these. However since you are producing an integer value from the deg2rad (using a formula) it probably isn't recognizing it as the special angle thus it calculates off the series. try saying this and see what u get <?php $angle = 360; $rad_angle = deg2rad($angle); echo "The Tan of the angle based of its Radian Calculation is: ".tan($rad_angle)."<br/>\" \" its degree is: ".tan($angle); ?> and see what u get Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 27, 2007 Author Share Posted August 27, 2007 It has to do with the nature of the discovery of this answer. As i've stated in the board on higher order differentials the way computers solve trig functions is not based on a known table of values, but based on the summing of an infinite series. Makes sense. Thanks for the information. The reason one produces it and the other doesn't is because there is a table of the special values predefine in most caluclations 0pi, pi/3, pi/4, pi/2 pi/6 etc etc and all variants of these. However since you are producing an integer value from the deg2rad (using a formula) it probably isn't recognizing it as the special angle thus it calculates off the series. Presumably PHP doesn't have a 'table' of special values then? Otherwise you would expect : echo sin(pi()); To produce 0? Or have i misunderstood? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 27, 2007 Share Posted August 27, 2007 Well, your code confirms tan (2 * PI) comes out wrong and tan(360) is more wrong as the arg should be in radians. $rad_angle = deg2rad(360); // 6.28318530718 - When was this an integer? I suppose one way around it is $angle=360; $rad = deg2rad($angle%360) Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 27, 2007 Share Posted August 27, 2007 Yeah math programing is fuzzy, because its all done via series my assumption is that php doesn't know special angles and get exact answers for them as you said but i think we have this figured out. When in doubt round answers within a reasonable degree of certainty for your given function. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 27, 2007 Share Posted August 27, 2007 Rounding indeed does it (6 dec places should be near enough for most purposes) $rad_angle = deg2rad(360); echo round(sin($rad_angle), 6); // -> 0 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 27, 2007 Author Share Posted August 27, 2007 Yeah, i had noticed you could round. Thanks to you both for the help and information. I'll mark this as solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.