"for" loops

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jan 28 14:35:49 AEST 1989


In article <8515 at lanl.gov> jlg at lanl.gov (Jim Giles) writes:
>      for (x=0.0; x<=1.0, x+=0.1) {...}
>For a loop from 0.0 to 1000.0 by 0.01 on a 32-bit floating-point machine,
>the round-off of the last 100 adds is comparable to the increment itself!
>This may be another reason for the undesireable feature in C of assuming
>double precision as the default floating-point.

No, I don't think so.  I've never known anyone to recommend a loop
like the above.  The reasons for defaulting floating-point computations
to double precision in original C (no longer required in ANSI C) were
that it was easier to support on the PDP-11 that way and that numerical
applications were so rare in the UNIX C environment that the potential
loss of speed for such applications was not considered significant.



More information about the Comp.lang.c mailing list