Loop optimization

bearophile bearophileHUGS at lycos.com
Sat May 22 05:03:11 PDT 2010


Walter Bright:
> for (int j=0;j<1e6-1;j++)
> 
> The j<1e6-1 is a floating point operation. It should be redone as an int one:
>       j<1_000_000-1

The syntax "1e6" can represent an integer value of one million as perfectly and as precisely as "1_000_000", but traditionally in many languages the exponential syntax is used to represent floating point values only, I don't know why.
If the OP wants a short syntax to represent one million, this syntax can be used in D2:
foreach (j; 0 .. 10^^6)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list