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


kenn...@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kenn...@gmail.com


--- Comment #8 from kenn...@gmail.com 2011-06-03 12:55:56 PDT ---
(In reply to comment #7)
> (In reply to comment #4)
> > Actually I can just dup manually instead of using the heap:
> > 
> > return cycle(result.dup);
> 
> .dup creates a copy on the heap.
> 
> 
> This is a safer implementation:
> 
> import std.stdio, std.math, std.algorithm, std.range;
> 
> auto makeSine() {
>     return cycle(map!q{ sin(a * PI) }(iota(0, 2, 0.2)));
> }
> 
> void main() {
>     auto sineTable = makeSine();
>     writeln(take(sineTable, 10));
> }
> 
> 
> Regarding the unsafety of the version that uses a fixed sized array, I'd like
> the compiler to warn better against such bugs.

This will evaluate 'sin(a * PI)' N times, which totally goes against the reason
of making a sine table. You should 'array' the 'map' before 'cycle'-ing.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to