[Issue 3190] New: enum doesn't work as the increment in a for loop
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 19 02:16:14 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3190
Summary: enum doesn't work as the increment in a for loop
Product: D
Version: 2.031
Platform: x86_64
OS/Version: Linux
Status: NEW
Severity: major
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bugzilla at kyllingen.net
The following should print a list of numbers from 0 to 10:
enum real ONE = 1.0;
real x;
for (x=0.0; x<10.0; x+=ONE) writeln(x);
writeln(x);
Instead it prints:
0
nan
I.e. the loop is only executed once, and x is set to NaN after the first
iteration. The same happens if float is used instead of real. If double is
used, the program goes into a near-infinite loop, spitting out very small
numbers (starting with 6.65345e-316).
The following makes the program behave as expected:
- making ONE a normal variable instead of an enum
- writing "enum { real ONE }" instead
- putting the increment inside the loop body
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list