Floating Point Arithmetic

Stephen Clamage steve at taumet.com
Sun Oct 28 03:48:20 AEST 1990


rst at cs.hull.ac.uk (Rob Turner) writes:
>[ ... ] it took me a fair while to get over the
>natural hurdle of always prefering to use float because float
>arithmetic 'must be faster' than double.

If FP arithmetic is done in software and the software does both float
and double arithmetic, float is generally faster.  With hardware
floating-point, there is usually no difference, since the hardware
converts to its internal form and back.

>I am under the impression
>that in K&R C (which I have used to do most of my C programming), all
>floating point computation is performed in double precision mode
>anyway, so the compiler ends up having to convert floats to doubles
>before you do the sums, then translate back into floats afterwards.
>Depending on the floating point format, these conversions take up
>varying amounts of time. Similarly, float parameters are passed as
>doubles.

True; and you cannot predict whether conversion to/from float is faster
or slower than conversion to/from double on an unkonwn system, nor
whether the conversion time is compensated for by the difference, if any,
in float vs double arithmetic speed.

>I believe that the situation has changed with ANSI C, and
>none of these conversions are performed.

Not quite.  ANSI C allows but does not require arithmetic on float types
to be performed without conversion to double.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list