Can Std: :Isfinite(Integraltype) Ever Return False?
According to the Documentation of Std: :Isfinite, the Overload Bool Isfinite( Integraltype Arg ) Always Casts Arg to Double and Calls Bool Isfinite( Double Arg...
According to the documentation of std::isfinite, the overload bool isfinite( IntegralType arg ) always casts arg to double and calls bool isfinite( double arg ).
How would this be different from saying "bool isfinite( IntegralType arg ) always returns true"? In other words, under what scenario would bool isfinite( IntegralType arg ) return false?
1 Answer
Most (all?) other functions in <cmath> also accept integers and automatically convert them to doubles. std::isfinite likely does it for consistency.
In theory it could return false if the conversion to double overflowed, but in practice we don't have large enough integral types. In fact, GCC & Clang with -O3 (targeting x86-64) appear to replace the call with true (even with [unsigned]long long arguments).
Such an overflow could happen if the integral type is 128 bits wide and the floating-point type is single-precision (32 bits wide), for example std::isfinite(float(__uint128_t(-1))) evaluates to false, but since double is not allowed to be 32-bit (see comments), this doesn't matter.