I don't know if it is possible to do this, but i need to split a floating point number in sum of two number...
For example assuming x is a floating point number and we want to split this in x = I + f, where I is the signed integer part while f is the signed fractional part, both floating number i guess such split could be implemented exactly (i.e. without fp error i mean).
I was wondering if it is possible to split somehow x = (I-1.0) + (f + 1.0), namely without floating point rounding error.
I've implemented on my own the split x = I + f then summing and adding 1.0 i have the second split i presented, but basically it's affected from floating point rounding error such operation.
(using double-precision for the examples)
There is no chance of obtaining such a split for all values. Take
0x1.0p-60, the integral part of which is0.0and the fractional part is0x1.0p-60.f + 1.0is inexact and produces1.0, whereasI-1.0is exact and produces-1.0.It's not just that the addition in
f + 1.0is inexact: the floating-point value such that, when added-1.0, produces0x1.0p-60, does not exist.A floating-point value
vcan always be split exactly into the sum offmod(v, 1.0)andv - fmod(v, 1.0), where the latter is an integer, and there is at least another way to splitvexactly between an integer part and a fractional part using IEEE 754 “Floating-point remainder”, which is subtly distinct fromfmod, but there is no way to split numbers close to 0 into the floating-point sum of1.0and another value.