Skip to content

Add support for scientific notation with 'e' and 'E'#97

Open
kohlerdominik wants to merge 1 commit intobugwheels94:masterfrom
kohlerdominik:master
Open

Add support for scientific notation with 'e' and 'E'#97
kohlerdominik wants to merge 1 commit intobugwheels94:masterfrom
kohlerdominik:master

Conversation

@kohlerdominik
Copy link

@kohlerdominik kohlerdominik commented Feb 25, 2026

This PR fixes issue #96, describing that scientific notation (e.g., 1e-7, 1e+7) is incorrectly parsed as an arithmetic operation involving the Euler constant e.

Changes

1. Lexer Look-ahead Logic

Modified src/lexer.ts to implement a look-ahead check. When the lexer encounters e or E preceded by a number, it now checks for:

  • A trailing number (e.g., 1e7)
  • A sign followed by a number (e.g., 1e-7 or 1e+7)

If these patterns match, they are collapsed into the NUMBER token instead of being treated as constants or operators.

2. Capital E Support

Added E as a valid token in src/token.ts for parity with e, allowing 1E-7 to be parsed correctly.

3. Euler Constant Preservation

Standalone usage of the constant e remains unaffected. The lexer only triggers the scientific notation logic if the e is immediately preceded by a numeric value.

4. New Test Suite

Added test/scientific-notation.js with 11 test cases.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant