I was just porting a c code to JavaScript and got stumbled on a weird issue, the value from c cos
function is different from the value of Math.cos
value which results in wrong output.
First
c cos:
cos(-1.570796) is 0.000000
while
First
JavaScript cos:
Math.cos(-1.570796) is 3.2679489653813835e-7
Second
c cos:
cos(-1.570796) is -1.000000
while
Second
JavaScript cos:
Math.cos(-1.570796) is -0.99999999999994
I can see that JavaScript Second
one is close enough to -1.000000
but the first one is way off.
Can anyone please let me know how can i fix this?