[Issue 4111] New: Foreach ranges accept floating-point extrema
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Apr 21 14:01:42 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4111
Summary: Foreach ranges accept floating-point extrema
Product: D
Version: future
Platform: All
OS/Version: All
Status: NEW
Keywords: accepts-invalid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-04-21 14:01:40 PDT ---
This D2 code works with dmd 2.043, it shows that foreach accepts floating point
extrema too.
But I think it's safer/tidier to accept only ranges with integral extrema (in
Python too the range/xrange expects integers). FP approximations can cause
problems here.
import std.stdio;
import std.math: nextUp;
void main() {
foreach(i; 2.1 .. 4.10001) {
writeln(typeid(typeof(i))); // Output: double
break;
}
foreach(i; 2.1 .. nextUp(4.1))
write(i, " "); // Output: 2.1 3.1 4.1
}
--
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