What happens if I cast a double to an int, but the value of the double is out of range?

c++, casting

Solution

Precisely. Quoting from the Standard, 4.9, "The behavior is undefined if the truncated value cannot be represented in the destination type."

Problem

What happens if I cast a double to an int, but the value of the double is out of range? Lets say I do something like this? ``` double d = double(INT_MIN) - 10000.0; int a = (int)d; ``` What is the value of a? Is it undefined?

Original source