[Issue 10466] Optional "[]" syntax for std.range.iota too

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 31 00:35:03 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10466


Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |joseph.wakeling at webdrake.ne
                   |                            |t


--- Comment #6 from Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> 2013-08-31 00:34:59 PDT ---
(In reply to comment #4)
> Hmm, iota with FP gets tricky, because, for example, 0.1 does not have an exact
> representation in floating-point. So if you write iota(0.0, 1.0, 0.1), it's
> unclear whether 1.0 will be included or not (for example, you may end up with
> 0.999999998 and it gets included, or it may end up with 1.0000001 and get
> excluded).

Surely that should be a case of, "use with FP at own risk".  There are cases
where it might be useful, but as with all things, you need to understand the
possibility of rounding error.

I got bitten rather amusingly by such an example where I was doing a for ()
loop across [0, 1] in 0.1 increments.  GDC and LDC can handle that, DMD
couldn't, and I had to switch to increments that were negative powers of 2.  If
you can trust the user to implement a for () loop correctly, you can trust them
to do the same with iota().

Bottom line -- iota() currently does allow FP numbers and excluding them would
be a breaking change.

-- 
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