I wrote some code to check if a type has a modulo representation:
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
    cout << "Whether float objects have a modulo representation: "
         << numeric_limits<float>::is_modulo << endl;
    cout << "Whether double objects have a modulo representation: "
         << numeric_limits<double>::is_modulo << endl;
}
Output:
Whether float objects have a modulo representation: 0
Whether double objects have a modulo representation: 0
But we can use fmod() (from <math.h>) to find modulo of float or double. So, why is is_modulo false if it is possible to find a modulo of a float or double?
From cppreference
The value of
std::numeric_limits<T>::is_moduloistruefor all arithmetic types T that handle overflows with modulo arithmetic, that is, if the result of addition, subtraction, multiplication, or division of this type would fall outside the range [min(),max()], the value returned by such operation differs from the expected value by a multiple ofmax()-min()+1.
Overflow of floating point numbers is undefined behavior, therefore std::numeric_limits::is_modulo for float and double is false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With