ANSI C Standard: Float/Double Handling
Henry Spencer
henry at utzoo.UUCP
Sun Nov 11 10:42:17 AEST 1984
> The standard math library was also modified to include both
> float and double versions of each function, e.g. float sin() and
> double dsin(), float exp() and double dexp() etc. It took about
> a week to do everything.
> ...
> It seems to be a poor idea to make all float constants
> double, because a single constant in an expresion will promote
> all the way through the expression, causing all those unwanted
> conversions.
>
> Anyone considering this type of thing should beware of side
> effects, e.g printf will treat a float argument as double ...
Your approach can be summed up as "if you want double, you must say so".
The problem with this approach is that it breaks a large percentage
of the existing floating-point programs. Avoiding breakage of existing
valid programs is a major item in the ANSI C committee's charter. This
unfortunately means that places where things default to double right
now must generally stay that way. Changing the types accepted by (e.g.)
sin(), changing the type of "1.23e5", and changing the type behavior at
the function-call interface are all changes capable of causing massive
breakage and unportability.
There is also the view that people who use floating point casually should
get the most accurate version, i.e. double. If somebody is seriously
concerned about space or speed, then *he* should pay the price of having
to ask for float explicitly. I concede that some of the techniques one
must use to ask for it are a bit clumsy.
--
Henry Spencer @ U of Toronto Zoology
{allegra,ihnp4,linus,decvax}!utzoo!henry
More information about the Comp.lang.c
mailing list