Skip to content

Fix #e prefix for decimal numbers to produce exact Rationals#7

Merged
mark-friedman merged 2 commits intomainfrom
fix-issue-6-exact-decimals-1281184460849524705
Feb 20, 2026
Merged

Fix #e prefix for decimal numbers to produce exact Rationals#7
mark-friedman merged 2 commits intomainfrom
fix-issue-6-exact-decimals-1281184460849524705

Conversation

@mark-friedman
Copy link
Copy Markdown
Owner

Fixes Issue #6 by implementing exact decimal parsing for numbers with the #e prefix.

When a number like #e1.223 is encountered, it is now parsed into the exact Rational 1223/1000 (or BigInt if the result is an integer like #e1.2e2 -> 120), instead of an inexact float.

This aligns behavior with R7RS Section 6.2.4. It also enforces that #e cannot be used with infinities or NaNs, raising a SchemeReadError.


PR created automatically by Jules for task 1281184460849524705 started by @mark-friedman

This commit modifies the number parser to correctly handle the `#e` exactness
prefix when applied to decimal numbers (e.g. `#e1.223`) or scientific notation
(e.g. `#e1.2e2`).

Previously, these were parsed as inexact floating point numbers, violating R7RS
which states that `#e` must force exactness.

Changes:
- Added `parseDecimalAsExact` helper in `src/core/interpreter/reader/number_parser.js`
  to parse decimal strings into `Rational` or `BigInt` using BigInt arithmetic.
- Updated `parsePrefixedNumber` to use this new helper when `exactness` is 'exact'.
- Added error handling to throw `SchemeReadError` for `#e+inf.0` / `#e+nan.0`, as these cannot be exact.
- Added comprehensive unit tests in `tests/core/interpreter/reader/number_parser_tests.js`.

Verified with:
- New unit tests passing.
- Chibi compliance tests passing (including numeric syntax).
- Full regression suite passing.

Co-authored-by: mark-friedman <1743690+mark-friedman@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules, parsePrefixedNumber is a pretty long function. Can it be reasonably split up and/or refactored?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored parsePrefixedNumber by splitting it into smaller, more focused helper functions: parsePrefixes, parseRationalWithRadix, parseComplexWithRadix, and parseRealWithRadix. This should improve readability and maintainability significantly.

Copy link
Copy Markdown
Owner Author

@mark-friedman mark-friedman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment about parsePrefixedNumber

- Split `parsePrefixedNumber` into smaller helper functions:
  - `parsePrefixes`
  - `parseRationalWithRadix`
  - `parseComplexWithRadix`
  - `parseRealWithRadix`
- This addresses code review feedback regarding function length and complexity.
- Verified with unit tests.

Co-authored-by: mark-friedman <1743690+mark-friedman@users.noreply.github.com>
@mark-friedman mark-friedman merged commit d6ca680 into main Feb 20, 2026
1 check passed
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