What is the biggest "no-floating" integer that can be stored in an IEEE 754 double type without losing precision ?
Biggest integer that can be stored in a double
doublefloating pointieee-754types
Related Topic
- Python – How to force division to be floating point? Division keeps rounding down to 0
- Javascript – How to deal with floating point number precision in JavaScript
- C++ – the difference between float and double
- Why not use Double or Float to represent currency
- Which is the first integer that an IEEE 754 float is incapable of representing exactly
- Html – float input type in HTML5
- Java – Float and double datatype in Java
Best Answer
The biggest/largest integer that can be stored in a double without losing precision is the same as the largest possible value of a double. That is,
DBL_MAX
or approximately 1.8 × 10308 (if your double is an IEEE 754 64-bit double). It's an integer. It's represented exactly. What more do you want?Go on, ask me what the largest integer is, such that it and all smaller integers can be stored in IEEE 64-bit doubles without losing precision. An IEEE 64-bit double has 52 bits of mantissa, so I think it's 253:
Or another way of looking at it: once the bias has been taken off the exponent, and ignoring the sign bit as irrelevant to the question, the value stored by a double is a power of 2, plus a 52-bit integer multiplied by 2exponent − 52. So with exponent 52 you can store all values from 252 through to 253 − 1. Then with exponent 53, the next number you can store after 253 is 253 + 1 × 253 − 52. So loss of precision first occurs with 253 + 1.