Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JavaScript have double floating point number precision?

I know it's an odd question, but does JavaScript have the capacity to work with double's as opposed to single floats? (64 bit floats vs. 32 bits.)

like image 868
Travis Avatar asked Aug 31 '10 03:08

Travis


People also ask

What is floating point precision in JavaScript?

The representation of floating points in JavaScript follows the IEEE-754 format. It is a double precision format where 64 bits are allocated for every floating point.

Does JavaScript use floating point math?

JavaScript supports one mathematical type, 64-bit floating point numbers.

Why are floating point numbers inaccurate in JavaScript?

Because often-times, they are approximating rationals that cannot be represented finitely in base 2 (the digits repeat), and in general they are approximating real (possibly irrational) numbers which may not be representable in finitely many digits in any base.

Does double or float have more precision?

double has 2x more precision than float. float is a 32-bit IEEE 754 single precision Floating Point Number – 1 bit for the sign, 8 bits for the exponent, and 23* for the value. float has 7 decimal digits of precision.


1 Answers

According to the ECMA-262 specification (ECMAScript is the specification for Javascript), section 8.5:

The Number type has exactly 18437736874454810627 (that is, 264−253+3) values, representing the double-precision 64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic

Source: http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf (PDF)

like image 126
Daniel Vandersluis Avatar answered Sep 18 '22 11:09

Daniel Vandersluis