Math: n-th root, logarithm with arbitrary base

# Axel Rauschmayer (14 years ago)

I haven’t seen these two functions among the proposed additions for Math (should these be in a math module?):

function nthRoot(n, x) {
    return Math.pow(x, 1/n);
}

function log_b(b, x) {
    return Math.log(x) / Math.log(b);
}

Have they been considered and rejected?

Axel

# Erik Corry (14 years ago)

Both the proposed implementations do fp rounding twice, and so produce an inaccurate answer. I think we should probably leave it to the user to define incorrect math functions, rather than bake them into the language.

2011/12/19 Axel Rauschmayer <axel at rauschma.de>:

# Axel Rauschmayer (14 years ago)

But wouldn’t that rather be a reason for making these functions part of the core language?

# Erik Corry (14 years ago)

2011/12/19 Axel Rauschmayer <axel at rauschma.de>:

But wouldn’t that rather be a reason for making these functions part of the core language?

MS have proposed log2, log10, log1p. This makes more sense to me. These already exist and are useful in other languages and are not too hard to implement.

If we go beyond that it would be nice to see a sample implementation that is not either trivial or inaccurate or both?