Inverse of fmod

If I have the following in C++ :

fmod(x, n) = o

how to restor x value from o ? when n value is known.

I have tried to use the normal mod where

a%b=c 
if a>=b then 
b+c -> a 
else 
c -> a 

but that doesn’t work when we are using floating point numbers

>Solution :

From this std::fmod reference:

The floating-point remainder of the division operation x / y calculated by this function is exactly the value x - rem * y, where rem is x / y with its fractional part truncated.

[Emphasis mine]

Because the fractional part is truncated, it’s impossible to get back the original value.

And that’s before involving this.

Leave a Reply