Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What represents Math.IEEERemainder(x,y) in C++?

Tags:

c++

What represents Math.IEEERemainder(x,y) in C++?

like image 497
Ahmad Farid Avatar asked Dec 18 '22 04:12

Ahmad Farid


2 Answers

Try the fmod function.

like image 179
SLaks Avatar answered Dec 27 '22 23:12

SLaks


In the C++11 standard library, std::remainder(x,y), is now the equivalent function of C#'s Math.IEEERemainder(x,y) in C++.

From: http://en.cppreference.com/w/cpp/numeric/math/remainder

Computes the IEEE remainder of the floating point division operation x/y

The IEEE remainder is x–(round(x/y)*y)

Whereas, the fmod remainder is x - trunc(x/y)*y, which can lead to different answers such as was raised in this question: Why am I getting a different result from std::fmod and std::remainder

If you really want to get the IEEE-defined remainder, you need std::remainder(x,y) (or define your own function if you can't use C++11)

like image 23
decvalts Avatar answered Dec 27 '22 22:12

decvalts