javascript - Math.cos inaccurancy -
alert(math.cos(math.pi/2));
why result not exact zero? inaccurancy, or implementation error?
math.pi/2 approximation of real value of pi/2. taking exact cosine of approximated value won't yield zero. value approximation of exact value precision of underlying floating point datatype.
using arbitrary precision library, can evaluate difference between pi/2 in double precision , exact value to
0.0000000000000000612323399573676588613032966137500529104874722961... since slope of cosine close zeros 1, expect cosine of approximation of pi/2 approximately equal difference, , indeed is.
javascript math floating-point
No comments:
Post a Comment