[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Re: Zeroes and infinities
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
Because IEEE 754 forbids stopping on serious exceptions, and languages
generally can't support its flags (and that DOES include C99),
Perhaps you should read the C99 standard.
7.6.2 Exceptions
[#1] The following functions provide access to the exception
flags. [...]
Sigh. I was one of the last few numeric experts still attempting to
contribute to WG14 when C99 was standardised. Perhaps you should
read the WHOLE standard, and not just read into the standard what
you think that it should say. Here are a FEW of the points that
you have missed.
The whole of 7.6 <fenv.h> is specified for all C99 implementations,
but actually specifies only the syntax and leaves the semantics
undefined - unless Annex F is in force.
Annex F is optional (at the IMPLEMENTOR'S whim), and is specified
to set __STD_IEC_559__ to 1 if it is in force. But it, in turn,
is specified to set the flags correctly only if the programmer
obeys certain rules, which include:
Always setting #pragma STDC FENV_ACCESS to on
Never setting #pragma STDC FP_CONTRACT to on
Never relying on a flag over any standard library call (except
for <fenv.h> and <math.h>) - yes, that includes abs from <stdlib.h>
Never calling a library function with any mode set to a non-
default value
Never calling any external library - even one guaranteed to be in
conforming C99
Never using complex arithmetic
It is also unclear that, even if an implementation sets __STD_IEC_559__
to 1, it need provide all of the relevant macros. That is generally
assumed, but the standard doesn't require it explicitly.
But, even given all of those restrictions, there was a considerable
and inconclusive debate over whether 6.5 paragraph 5 overrode the
specifications in Annex F or the converse. Here it is:
[#5] 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.
I can witness that the only people who claim to know the answer to
that question are wrong. There was no consensus on the WG14 Email
reflector, though everyone did agree that, IF 6.5 paragraph 5
overrode Annex F, THEN it made Annex F futile.
And there's a LOT more, though it starts to get very arcane beyond
the above simple description.
Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email: nmm1@xxxxxxxxx
Tel.: +44 1223 334761 Fax: +44 1223 334679