Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 419
u840903 Avatar asked Sep 02 '25 16:09

u840903


2 Answers

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.

like image 136
Winger Avatar answered Sep 04 '25 06:09

Winger


Convience factor, as seen here, it is actually a widely used constant.

like image 23
Mike Lewis Avatar answered Sep 04 '25 07:09

Mike Lewis