Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Over what range will integer arithmetic addition and subtraction be accurate to the integer in IEEE double precision floating point?

According to Wikipedia on the IEEE 64-bit floating point standard:

Between 252=4,503,599,627,370,496 and 253=9,007,199,254,740,992 the representable numbers are exactly the integers. For the next range, from 253 to 254, everything is multiplied by 2, so the representable numbers are the even ones, etc.

Does this mean contiguous integers can be represented up to 253?

In short I am trying to find the range of integer values upon which integer addition and subtraction operations will result in an exactly correct result.

like image 858
Ben Aston Avatar asked Mar 22 '23 02:03

Ben Aston


1 Answers

Yes, all integers from -253 to +253, inclusive, are representable in IEEE-754 64-bit floating-point. An implementation that conforms to IEEE 754 will return exactly correct results for all operations a+b and a-b where a, b, and the mathematical result are integers in that interval.

Obviously, some results will be outside that interval, such as 253+1, so many operations that produce such results will produce a value that is not exact due to rounding to a representable value.

An interval such that a and b being integers in the interval guarantees that a+b and a-b are exact is -252 to +252, inclusive.

like image 104
Eric Postpischil Avatar answered Mar 30 '23 00:03

Eric Postpischil