开发者

Why is there a Math.SQRT2 property in JavaScript?

开发者 https://www.devze.com 2023-02-18 21:51 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消