C++의 부동소수점→정수 변환이 정의되지 않은 동작을 일으키는 경우
C++에서 부동소수점에서 정수로의 변환 시 정의되지 않은 동작이 발생할 수 있음.
C++의 부동소수점 타입인 <code>float</code>의 소수부를 버린 후, 해당 정수가 정수형 범위를 초과하면 정의되지 않은 동작(UB)이 발생하게 됩니다. 이런 변환은 암시적 변환, 함수형 캐스트, <code>static_cast</code> 등 모든 형태에서 영향을 받습니다. 또한, 정적 분석 도구인 <code>-Wall</code>과 <code>-Wextra</code>는 이 문제에 대한 경고를 제공하지 않으며, <code>-Wconversion</code>도 충분히 경고하지 않습니다.
C++ floating-point to integer conversion can cause undefined behavior.
In C++, when converting a <code>float</code> value with its decimal part discarded, if the resulting integer exceeds the range of the target type, undefined behavior (UB) occurs. This can happen with implicit conversions, functional casts, and <code>static_cast</code> alike. Moreover, static analysis tools like <code>-Wall</code> and <code>-Wextra</code> do not warn about this issue, and <code>-Wconversion</code> also fails to provide adequate warnings.