HUGE

David B.Anderson davea at quasar.wpd.sgi.com
Sat Jan 19 08:38:47 AEST 1991


In article <61848 at brunix.UUCP>, sgf at cs.brown.edu (Sam Fulcomer) writes:
> In article <1991Jan17.201925.2264 at odin.corp.sgi.com> bruceh at sgi.com (Bruce R. Holloway) writes:
> >In article <72495 at bu.edu.bu.edu> tjh at bu-pub.bu.edu (Tim Hall) writes:
> >>
> >The problem isn't that HUGE needs to be attenuated.  It's that the MIPS
> >C compiler didn't respect the cast to float in your constant definition.
> 
> ok, but why doesn't
> 	if( a == (float)NOVALUE)
> work?

bruceh is correct.

Since this has become a hot issue I'll elaborate:
	((float) NOVALUE)
should narrow the constant (when NOVALUE is a double constant) to a float.

However, in 3.3, the constant did not get narrowed. 

Fortunately, this is rarely a problem.  Unfortunately, when it bites
someone it is confusing to look at the code because it is the _constant_
which was not narrowed (the generated code is ok, the constant is bad).  
The .s output of Mr. Hall's compile would be in part (cc -g):

compiled with 3.3 cc:
        li.s    $f4, 3.4028234699999997e+35
        s.s     $f4, 28($sp)
        cvt.d.s $f6, $f4
        li.d    $f8, 3.4028234699999997e+35
        c.eq.d  $f6, $f8
        bc1f    $32

One gets the un-narrowed NOVALUE $6 rather than the double-precision
version of the narrowed one.

Now look at the same compiled under 4.0 cc:

        li.s    $f4, 3.4028234346940236e+35
        s.s     $f4, 28($sp)
        cvt.d.s $f6, $f4
        li.d    $f8, 3.4028234346940236e+35
        c.eq.d  $f6, $f8
        bc1f    $32

Same code, but the constant is  now correct.

In general, narrowing *does* happen correctly in 3.3 C. However in
the above case (constant double narrowed to float) it does not.

This is fixed in the next major release (4.0).

Hope this elaboration helps a little.
[ David B. Anderson  Silicon Graphics  (415)335-1548  davea at sgi.com ]
[``What can go wrong?''                           --Calvin to Hobbes]



More information about the Comp.sys.sgi mailing list