[Issue 4111] New: Foreach ranges accept floating-point extrema

bearophile bearophileHUGS at lycos.com
Thu Apr 22 02:05:37 PDT 2010


Aelxx:
> >    foreach(i; 2.1 .. 4.10001) {
> >        writeln(typeid(typeof(i))); // Output: double
> >        break;
> >    }
> 
> I'd like MATLAB style more:
> foreach (f; linspace (0.0, 1.0, 100))
> {...}
> here f gets values 0, 0.0101.., 0.0202..., ..., 0.98989..., 1.0
> 
> foreach (f; logspace (1.0, 1e6, 7))
> {...}
> here f gets values 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6. 

If you have comments on a bug report, it's quite better if you write them in Bugzilla, because here they will probably be lost/ignored.
Phobos has iota() that's similar to what you ask, a FP version is easy to create.

Bye,
bearophile


More information about the Digitalmars-d-bugs mailing list