#includ...">

Why is "is_modulo" incorrect for double and float?

I wrote code to check if the 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()(of <math.h>) to find modulo floator double. So why is_modulofalse if you can find modulo float or double?

+4
source share
3 answers

From cppreference

std::numeric_limits<T>::is_modulo true T, , , , [ min(), max()], , , max()-min()+1.

- undefined, std::numeric_limits::is_modulo float double - false.

+6

fmod. .

" ", unsigned int .

float, double , is_modulo false.

+3

:

std::numeric_limits<T>::is_modulo T, , , , [min(), max()], , , max()-min()+1.

therefore, he does not speak of a β€œmodulo search”, but how he a + bwill behave. Floating-point arithmetic does not overflow, as there may be a whole arithmetic.

+2
source

All Articles