Repository navigation
Conversation
…t-parser-bracket-exponent # Conflicts: # HISTORY.md
|
Thanks so much for your interest in and contribution to mathjs. I'm not in a position to judge what's the best line to draw on what to implement in the Unit parser, given the architecture issues Jos discussed in #3620. For example, mathjs would accept nested parentheses in the exponent ( So, to set realistic expectations: there won't be any action on this PR until Jos is able to review it. Given the things that are occupying him at the moment, it's difficult to predict when that might be. Thanks for your understanding. |
Summary
Allow parentheses around the exponent in the unit parser (unit("m ^ (1)")).
Why this matters
unit("m ^ (1)")throwsSyntaxError: In "km ^ (1)", "^" must be followed by a floating-point number. The internalUnit.parseparser (src/type/unit/Unit.js) already supports parentheses for grouping units (e.g.(m/s)^2), but it does not accept parentheses wrapping the exponent that follows a^. When it encounters^ (,parseNumber()returnsnull(a(is not a digit/dot/sign) and the parser throws. Owner josdejong explicitly blessed a short-term fix on 2026-01-07: "if adding bracket support to the unit parser is simple to do I think we can do that, otherwise ... improve the error message." This is the simple bracket-support path.Testing
Changes are scoped to the files named in the fix; added or updated tests where the project has a suite, and matched existing conventions.
Fixes #3620