Skip to content

math.simplify('1e-10') returns 0 #813

@josdejong

Description

@josdejong

I saw this issue on stackoverflow:

http://stackoverflow.com/questions/42838708/why-math-simplify1e-10-tostring-of-math-js-returns-0

When you simplify a very small constant, zero is returned instead.

I haven't looked deeply into it but I think the issue is caused by this piece of code which turns a number into a fraction:

https://github.com/josdejong/mathjs/blob/master/lib/function/algebra/simplify/simplifyConstant.js#L49-L54

    'number': function(s) {
      if (digits(s) <= 15) {
        return math.fraction(s);
      }
      return s;
    },

Apparently Fraction.js rounds such a small value to zero:

math.fraction(1e-10)  // Fraction {d: 1, n: 0, s: 1}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions