Skip to content

math.js can't handle multiple recursive calls #313

@Zecc

Description

@Zecc

Multiple recursive calls inside a function return wrong results (always the same value, it seems).

An example:

fib(n) = (n <= 2) ? 1 : fib(n-2)+fib(n-1);
[fib(1), fib(2), fib(3), fib(4), fib(5), fib(6), fib(7), fib(8), fib(9)]

Expected result:

[[1, 1, 2, 3, 5, 8, 13, 21, 34]]

Actual result:

[[1, 1, 2, 2, 3, 3, 4, 4, 5]]

Another example:

tohex(n) = (n < 10) ? string(n) :
           (n == 15) ? "f"  :  (n == 14) ? "e"  :  (n == 13) ? "d" :
           (n == 12) ? "c"  :  (n == 11) ? "b"  :  (n == 10) ? "a" :
           tohex(floor(n/16)) + tohex(mod(n,16));
[tohex(16), tohex(255), tohex(51966)]

Expected result:

[["10", "ff", "cafe"]]

Actual result:

[["11", "ff", "cccc"]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions