Subject: Re: port-alpha/6634: divide by zero gives strange results on alpha
To: Todd Vierling <tv@pobox.com>
From: Kevin Schoedel <schoedel@kw.igs.net>
List: netbsd-bugs
Date: 12/22/1998 17:21:00
>The argument of %f is a double, not a float - what you end up with is a
>double containing the bits of j and a float-sized array of random bits off
>the stack.
>
>The correct last statement should read:
>
>printf("j: %f\n", (double)j);

Actually,

	printf("j: %f\n", j);

is OK.

Assuming this fails for normal floats (i.e. where division by zero
is not involved, *or* if the compiler claims to handle that division by
producing a printable float infinity), and assuming that printf() is
properly declared (as including <stdio.h> in the original PR presumably
did), then there *is* a bug: the compiler should be promoting the float
to double when passing it to printf().

I went through this recently with gcc or egcs (can't remember) with a
different processor (PowerPC) and different type (char), so this might be
a pervasive gcc and/or egcs bug. (It worked on i386 in that case too.)

For reference, the relevant parts of section 6.3.2.2 of the standard:

	.... integral promotions are performed on each argument and
	arguments that have type float are converted to double. These
	are called the *default argument promotions*.... The ellipsis
	notation in a function prototype declarator causes argument
	type conversion to stop after the last declared parameter.
	The default argument promotions are performed on trailing arguments.

-- 
Kevin Schoedel
schoedel@kw.igs.net