轉換為浮點型別或從浮點型別轉換時溢位
如果,在轉換期間:
- 整數型別到浮點型別,
- 浮點型別為整數型別,或
- 浮點型別到較短的浮點型別,
源值超出了可以在目標型別中表示的值範圍,結果是未定義的行為。例:
double x = 1e100;
int y = x; // int probably cannot hold numbers that large, so this is UB
如果,在轉換期間:
源值超出了可以在目標型別中表示的值範圍,結果是未定義的行為。例:
double x = 1e100;
int y = x; // int probably cannot hold numbers that large, so this is UB