New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Scientific notation -3E0.5 is returning value #629

Closed
karenpb opened this Issue Mar 28, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@karenpb

karenpb commented Mar 28, 2016

In scientific notation, it should throw error if the exponent is decimal number.
eg. 3E0.5 is throwing Syntax Error
But -3E0.5 returns -1.5 as the result.
Is this a bug?

@karenpb

This comment has been minimized.

karenpb commented Mar 28, 2016

Just tried 3E.5 and it returns 4.0774227426886. Does mathjs interpret it as 3_e_0.5 in this case? Thanks.

@josdejong josdejong added the bug label Mar 28, 2016

@josdejong

This comment has been minimized.

Owner

josdejong commented Mar 28, 2016

That's interesting. Some of your expressions are parsed as an implicit multiplication:

math.parse('3E0.5');  // SyntaxError: Unexpected part ".5" (char 4)
math.parse('-3E0.5').toString({implicit: 'show'});   // "-3E0 * .5"
math.parse('3E.5').toString({implicit: 'show'});     // "3 * E * .5"
math.parse('-3E.5').toString({implicit: 'show'});    // "-3 * E * .5"

We will fix it, the parser should parse all of these cases as an invalid exponential notation and throw an error.

@karenpb

This comment has been minimized.

karenpb commented Mar 29, 2016

Thank you!

@josdejong

This comment has been minimized.

Owner

josdejong commented Apr 3, 2016

This has been fixed now in the develop branch

@infusion

This comment has been minimized.

Collaborator

infusion commented Apr 3, 2016

I would call it undefined behavior. Also JS itself doesn't have the feature of passing decimal exponents. If you've implemented it now, it should be declared a new feature of math.js.

@josdejong

This comment has been minimized.

Owner

josdejong commented Apr 3, 2016

?

The fix is that an error is thrown when you enter a decimal exponent, instead of having it parsed as an implicit multiplication. Decimal exponents are still not supported.

@infusion

This comment has been minimized.

Collaborator

infusion commented Apr 3, 2016

Ahh! Okay, sorry, haven't looked into your fix.

@josdejong

This comment has been minimized.

Owner

josdejong commented Apr 3, 2016

oki

@josdejong josdejong closed this in 8b39e1b Apr 3, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment