Assume that t,a,b are all double (IEEE Std 754) variables, and both values of a, b are NOT NaN (but may be Inf).
After t = a - b, do I necessarily have a == b + t?
Assume that t , a , b are all double (IEEE Std 754) variables,
Share
Absolutely not. One obvious case is
a=DBL_MAX,b=-DBL_MAX. Thent=INFINITY, sob+tis alsoINFINITY.What may be more surprising is that there are cases where this happens without any overflow. Basically, they’re all of the form where
a-bis inexact. For example, ifaisDBL_EPSILON/4andbis-1,a-bis 1 (assuming default rounding mode), anda-b+bis then 0.The reason I mention this second example is that this is the canonical way of forcing rounding to a particular precision in IEEE arithmetic. For instance, if you have a number in the range [0,1) and want to force rounding it to 4 bits of precision, you would add and then subtract
0x1p49.