This fragment means narrowing conversions between integer and floating types, respectively. That is, he argues that although conversion between integral types or between floating point types is valid, the resulting value will be determined by the implementation.
As an example, consider the following code snippet:
#include <iostream> #include <limits> int main() { long long lgm = std::numeric_limits<long long>::max(); std::cout << std::hex << lgm << std::endl; int i = lgm; std::cout << std::hex << i << std::endl; long double ldb = std::numeric_limits<long double>::max(); std::cout << std::hex << ldb << std::endl; double db = ldb; std::cout << std::hex << db << std::endl; }
Output:
7fffffffffffffff ffffffff 1.18973e+4932 inf
As you can see, the maximum value of long long integer exceeds the capacity of a simple integer. However, you can convert a long long to int (i.e., the Transformation is valid), but because int cannot hold the maximum value of a long long , there cannot be an exact conversion, Thus, the value of the resulting int stays away from implementation. The same is true for conversion between long double and double .
source share