paul@UUNET.UU.NET (Paul Hudson) (03/22/89)
A small floating point constant in gcc has type double. This can cause unwanted promotions
of other objects to doubles, like
float h()
{
float f;
...
return f * 2.0;
}
as a trivial example. This has an "unnecessary" promotion of f to double, and a shortening to
float again on the return. It would be nice if sufficiently small/imprecise constants could
be of float type at least as an option, if not by default.
Not having an up-to-date ANSI C draft to hand I can't say whether this is allowed by the standard.
but it would be useful!
Paul Hudson
Snail mail: Monotype ADG Email: ...!ukc!acorn!moncam!paul
Science Park, paul@moncam.co.uk
Milton Road, "Sun Microsysytems:
Cambridge, The Company is Arrogant (TM)"
CB4 4FQ
drh@notecnirp.Princeton.EDU (Dave Hanson) (03/24/89)
In article <8903221553.AA04823@marvin.moncam.uucp> mcvax!moncam!paul@UUNET.UU.NET (Paul Hudson) writes:
A small floating point constant in gcc has type double.
This can cause unwanted promotions of other objects to doubles, like
float h() { float f; ... return f * 2.0; }
as a trivial example. This has an "unnecessary" promotion of f to
double, and a shortening to float again on the return. It would be nice
if sufficiently small/imprecise constants could be of float type at
least as an option, if not by default.
this is correct as specified in the ANSI standard;
if you want float constants, use suffix "F", e.g., 2.0F.