[Issue 3121] New: recurrence does not generate the correct numbers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 1 08:07:57 PDT 2009


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 at puremagic.com
        ReportedBy: k-foley at 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: -------


More information about the Digitalmars-d-bugs mailing list