Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading