I'm just wondering what guarantees, if any, that either C11 or C99 provide in this regard.
Empirically, it seems that when I convert a floating point value (regardless of its accuracy) to a signed integer, I get a “nice” saturation whenever the floating point value does not appear in this significant integer range, even if a floating point value is the plus or minus of infinity (but I don't know or don't care about the NaN case).
There is a subtle problem here, which is that differences in rounding behavior can cause saturation in some cases, but not in others, especially when we are right at the edge of the saturation border. This does not bother me. My question is whether the floating point machine decided the integer that is required for output (which is platform dependent), but if the specified integer is outside the target integer range with a sign (which is platform independent), regardless of whether the specification is guaranteed saturation.
By default, I understand that what I see is just the convenience of the underlying hardware and that this behavior is not guaranteed, because the signed overflow is undefined. Hope I'm wrong because I hate signed overflow and try to avoid that. So yes, I am also interested in the case of converting to unsigned integers.
While I am, what about a negative 0? Is this guaranteed value a conversion to an integer, even if in a sense you can consider it to be negative epsilon, which is usually rounded to -1?
source
share