[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Re: Meeting the Scope and Purpose of P754
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
On 2007-07-14 09:51:55 +0200, Florent de Dinechin wrote:
I believe it could be done in a way that would not go against the C99
standard. C99 allows the compiler to use any precision larger than the
declared one, but does not mandate to do so AFAIK (Guillaume or Vincent
will correct me on this one).
First, the double type does not necessarily correspond to the IEEE-754
double precision (unless __STDC_IEC_559__ is 1). Then the compiler may
use any precision larger than the one corresponding to the FP type
(FLT_EVAL_METHOD gives information about that). But if you use a cast
or an assignment (see 5.1.2.3#12, 6.3.1.5#2 and 6.3.1.8#2[52]), then
the value must be converted to be exactly representable in its semantic
type.
This is what the C99 standard mandates, but in practice, compilers
often generate buggy code on x86 processors (in particular under
Linux, but I recall that MS-Windows can be affected too).
Yes, but it manages to make even that seriously ambiguous. 6.3.1.5
says:
If the value
being converted is in the range of values that can be
represented but cannot be represented exactly, the result is
either the nearest higher or nearest lower representable
value, chosen in an implementation-defined manner. If the
value being converted is outside the range of values that
can be represented, the behavior is undefined.
As usual with the C standard, there is no hint anywhere of which
section takes precedence over which, and so it is perfectly reasonable
to interpret this as overriding Annex F.
There is an even more horrible problem, which is that C99 does
not define what it means by type in the specification of casts and
assignments. Again, it is reasonable to interpret it as meaning
syntactic type, so the value need not be converted provided that
it is treated as if it were a value of another type. The C90
standard implied that was the case; the C99 one implies that it is
not, but the only semi-definite statement is in a merely informative
example.
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