www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3121] New: recurrence does not generate the correct numbers

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3121

           Summary: recurrence does not generate the correct numbers
           Product: D
           Version: 2.030
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: patch, wrong-code
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: k-foley onu.edu


Original:
1943    struct Recurrence(alias fun, StateType, size_t stateSize)
1944    {
1945        StateType[stateSize] _state;
1946        size_t _n;
1947    
1948        this(StateType[stateSize] initial) { _state = initial; }
1949    
1950        void popFront()
1951        {
1952            _state[_n % stateSize] = binaryFun!(fun, "a", "n")(
1953                cycle(_state, _n), _n);
1954            ++_n;
1955        }
1956    
1957        StateType front()
1958        {
1959            return _state[_n % stateSize];
1960        }
1961    
1962        enum bool empty = false;
1963    }

Line 1953 should be "cycle(_state, _n), _n + stateSize);"

Otherwise, the factorial example will print an initial 1, followed infinitely
by 0.  Maybe the unittest should perform an assert rather than a print:

auto fact = recurrence!("n * a[n-1]")(1);
assert( equal(take(10, fact), [1, 1, 2, 2*3, 2*3*4, 2*3*4*5, 2*3*4*5*6,
2*3*4*5*6*7, 2*3*4*5*6*7*8, 2*3*4*5*6*7*8*9][]) );

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 01 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3121


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




--- Comment #1 from Andrei Alexandrescu <andrei metalanguage.com>  2009-07-03
23:34:04 PDT ---
Fixed as advised, thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 03 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3121


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com




--- Comment #2 from Walter Bright <bugzilla digitalmars.com>  2009-07-09
02:58:04 PDT ---
Fixed dmd 2.031

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