Article View: comp.std.c
Article #3800Re: double to long double arithmetic promotion - is it allowed by the standard?
From: Peter Holzer
Date: Sun, 20 Aug 1995 18:21
Date: Sun, 20 Aug 1995 18:21
40 lines
2405 bytes
2405 bytes
Irv Lustig <irv@dizzy.cplex.com> writes: >I'm having a disagreement with a compiler vendor (who shall remain nameless) >for the Intel 386/486/Pentium as to whether the following is allowed by the C >standard. >The issue is as follows: >The vendor does a double precision calculation and stores the result in a >floating point register, which is 80 bits long. This result is then used in a >second calculation, so the arithmetic is done in extended precision. Then the >result is stored in a variable of type "double" by doing truncation. >You end up with the following odd situation, which I claim is illegal: >a = b (64-bit binary representations are the same) >c = d (64-bit binary representations are the same) >but (a + c) != (b + d) I thought this is illegal, but actually the standard isn't quite clear in this matter (although I think the intent to make this illegal is clear). The standard allows expressions to be evaluated with higher precicision, but states that the type of the expression is not changed by this. It specifies that at a conversion to a narrower FP type the value must be either rounded up or down (implementation defined). A footnote claims that casts must work as expected. What is not clear, is whether assignment of a double value which is actually a long double value to a double variable constitutes a `conversion'. I think it does since it must obviously be converted to fit in the variable. But your compiler vendor might claim that both the expression and the variable have type `double' so this is not a conversion. The same could be said about casts, too, however, and the footnote gives a hint that the comittee indended casts to strip off the extra precision. You could try adding extra casts to see if they strip off the extra precision. If they do, your vendor is inconsistent, if they don't he is violating a footnote. Both isn't really forbidden, but it gives you extra ammunition :-). hp
Technical Details
Message-ID:
<hjp.808942896@wsrcom.wsr.ac.at>Path:
arc1-ca.pugleaf.net!wsrcom.wsr.ac.at!hjpReferences:
<40lfps$5in@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!wsrcom.wsr.ac.at!hjp From: hjp@wsr.ac.at (Peter Holzer) Newsgroups: comp.std.c Subject: Re: double to long double arithmetic promotion - is it allowed by the standard? Date: 20 Aug 95 18:21:36 GMT Organization: WSR, Vienna, Austria Message-ID: <hjp.808942896@wsrcom.wsr.ac.at> References: <40lfps$5in@solutions.solon.com> NNTP-Posting-Host: wsrtest.wsr.ac.at X-Newsreader: NN version 6.5.0 #4 (NOV)