Why is there a Math.SQRT2 property in JavaScript?
Why is there a a property in Javascript that returns the approximate square root of 2. Isn't Math.sqrt(2) enough? There is also开发者_运维知识库 a property that returns the square root of 0.5.
I'm wondering out of pure curiosity.
This is a constant used in many math equations. Since it is a constant it doesn't need to be calculated each time it's used, and it has high precision.
Convience factor, as seen here, it is actually a widely used constant.
Some values are used often enough that it's faster to store them as constants than to recompute them. The square roots of 2 and 0.5 are two such constants.
精彩评论