J
jacob navia
Keith said:Isn't support for that optional? In other words, I think a conforming
implementation can do anything it likes on floating-point overflow, as
long as it doesn't claim IEC 60599 conformance.
Obviously there will be implementations of C where the machine has no
floating point unit. In those machines, maybe this thing can
be skipped.
But it's good that the standard provides a description of how FP
overflow is to be handled for implementations that choose to do so.
The standard explicitly states that conversion to a floating-point
type invokes undefined behavior if the value cannot be represented in
the target type. And C99 6.5p5 says:
If an _exceptional condition_ occurs during the evaluation of an
expression (that is, if the result is not mathematically defined
or not in the range of representable values for its type), the
behavior is undefined.
(This doesn't apply to unsigned types, since reduction modulo 2**N is
part of the operation, so formally speaking the overflow doesn't
happen in the first place.)
[...]It is a pity that the standard did NOT specify what happens with integer
overflow, even if indirectly acknowledges that the operation results
in undefined behavior.
Did you mean "directly" rather than "indirectly"?
Well it is missing the specifications of WHAT HAPPENS in case of integer
overflow.
There is a significant difference, in that the standard provides an
*optional* framework for dealing with floating-point overflow; an
implementer who wants to do something similar for signed integer
overflow pretty much has to define the interfaces.
It's possible I'm misreading the standard; if so, please point out
where I'm mistaken.
Floating point is optional. I have seen many implementations of C
(and done several with the embedded versions of my compiler system)
where there wasn't any floating point at all!
But IF there is floating point, it must be implemented along the lines
of the standard.
Now, why they didn't do the same for the integer exceptions (division by
zero, overflow) it is a mystery.
In general C99 advanced the language in floating point with very good
specifications, (environment, complex numbers) but left essential stuff
like integer overflow unspecified.