Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the standard provide both is_integer and is_exact?

std::numeric_limits provides 2 constants that are mutually exclusive:

  • is_integer : "true for all integer arithmetic types T"

  • is_exact: "true for all arithmetic types T that use exact representation"

Is there the possibility of a non-exact integral type? What is trying to be allowed for here?

In all my templates where I to know if I am dealing with precise numbers, I used is_integer, do I need to go add a check for is_exact as well now?

like image 214
Jonathan Mee Avatar asked Jan 12 '18 13:01

Jonathan Mee


1 Answers

From is_exact cppreference page:

Notes

While all fundamental types T for which std::numeric_limits<T>::is_exact==true are integer types, a library may define exact types that aren't integers, e.g. a rational arithmetics type representing fractions.


And, as @Holt has mentioned, the standard describes it as well:

21.3.4.1 numeric_limits members [numeric.limits.members]

static constexpr bool is_exact;

true if the type uses an exact representation. All integer types are exact, but not all exact types are integer. For example, rational and fixed-exponent representations are exact but not integer.

like image 171
Edgar Rokjān Avatar answered Nov 17 '22 07:11

Edgar Rokjān