Pointing Float

jimc at ucla-cs.UUCP jimc at ucla-cs.UUCP
Thu Dec 19 03:49:42 AEST 1985

In article <689 at brl-tgr.ARPA> cottrell at nbs-vms.arpa (COTTRELL, JAMES) writes:
>> > >>	float a,b;
>> > >>
>> > >>	a = b + 1.0;	/* Gets done in double because 1.0 is a double.
>> > >>			Gag me with a spoon. */
>One spoon coming up!
>> > > Nah, gets done in single because the compiler realizes that 1.0 has
>> > > the same representation in single and double, and therefore that
>> > > the result of the addition will be the same.
>> (3.5x>) and extensive related discussions for the last few days.
The preliminary draft "C" standard X3J11/85-138 says in sect. B.1.2.3 (program
execution) line 171 that the compiled code has to produce the same (sic)
result as double precision, but needn't actually be double.  Line 163 makes
a similar statement about promoting char to int.
    By the way, it's hard to be sure that 
       (float)x * (float)y == (float) ( (double)x * (double)y)
down to the last bit in every pathological case, but in practice all we
really need is that the answers differ less than an implementation-defined
maximum, typically 1 least significant bit of float.  How do people think
about interpreting "same" in this way?

James F. Carter            (213) 206-1306
UCLA-SEASnet; 2567 Boelter Hall; 405 Hilgard Ave.; Los Angeles, CA 90024
UUCP:...!{ihnp4,ucbvax,{hao!cepu}}!ucla-cs!jimc  ARPA:jimc at locus.UCLA.EDU

More information about the Comp.lang.c mailing list