I use Meteor. It uses Javascript on both the server and client.
When I run Math.sin(356644061314425) * 10000
i get:
-9986.46139381927
on the server and
-9986.46115497749
on the client / browser / app
Why is this? How can I prevent this?
EDIT: The proposed duplicate questions refer to degrees / radians. I think mine is more a runtime problem.
The Math. sin() function returns the sine of a number in radians.
The sine is equal to the ratio of the side opposite the angle and the hypotenuse of the right-angled triangle they define. The angle must be measured in radians.
I think the answer to "How do I prevent this?" is "you can't".
The answer to "Why is this?" is that the javascript implementation of Math.sin is not determined.
See http://www.ecma-international.org/ecma-262/5.1/#sec-15.8.2.16
Specifically "sin (x) Returns an implementation-dependent approximation to the sine of x. The argument is expressed in radians." (my italics).
But my experimentation suggests that modern browsers currently only use one of two implementations, with Chrome being different to (and seemingly more accurate than) other browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With