Floating Point Arithmetic

Rob Turner rst at cs.hull.ac.uk
Sat Oct 27 02:38:04 AEST 1990


<henry at zoo.toronto.edu> (Henry Spencer) writes:

 >In general, you should use 'double' for all floating point arithmetic

I agree with this, although 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. 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. I believe that the situation has changed with ANSI C, and
none of these conversions are performed.

         Robert Turner      <rst at cs.hull.ac.uk>

         Department of Computer Science,
         University of Hull, England.



More information about the Comp.lang.c mailing list