Math.sin(75 * (180/3.14)); -> 0.9956310419973837
Math.sin(75 * (180/Math.PI)); -> -0.4927842805101025
The above is copied from js debugger in acrobat. I am not understanding why. The first value (.995....) is correct. Any help/explanations would be appreciated.
Your problem is scale combined with precision. 75*180 is approximately 13,500, which is what you're multiplying your approximation of pi. At this scale, even small multiplicative variations will result in a large difference in the range. Combine that with the fact that you're using a crude approximation of pi (3.14) vs a more precise approximation (Math.PI
) gives you a lot of variability around this point. Try both of these calculations on Wolfram Alpha, and you'll see that JavaScript is giving consistent and correct answers.
The sine function will return a result that corresponds to the y-value of the sine function. So at this scale, a very small multiplicative error (Math.PI - 3.14
) will be magnified. Consider:
1 * (Math.PI - 3.14) = 0.0015926535897929917
13500 * (Math.PI - 3.14) = 21.50082346220539
(This is not a full calculation of error, just a demonstration that scale matters.)
This suggests that, around 1, the difference between 3.14 and Math.PI
doesn't really move you that far (0.00159 radians or 0.09 degrees). Around 4298, it moves you 21.5 radians (or 1231.9 degrees), which gives you a completely different location on the sine wave!