Repository navigation
Preserve fractional part when spelling out negative numbers - #13
Merged
synesthesiam merged 2 commits intoNov 16, 2026
Merged
Conversation
The NEGATIVE_NUMBER rule did r = int(-number), truncating the fraction, so '-1.5' spelled out as 'minus one' instead of 'minus one point five'. Positive decimals route through a decimal-aware ruleset; the negative path is the only one that truncated. Pass the full magnitude so the REMAINDER subpart recurses through the same decimal-aware path.
A negative number's remainder is now its full magnitude, which can be a float or Decimal, so mypy rejected assigning it to an int. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix negative decimal spellout in the
NEGATIVE_NUMBERrule (unicode_rbnf/engine.py,RbnfEngine.iter_format_number).For negative numbers the code did
r = int(-number), truncating the fractional part. TheNEGATIVE_NUMBERrule is"minus" + REMAINDER(r), so the remainder was rendered from a truncated int and the decimal was silently dropped. Positive decimals route through a decimal-aware ruleset and work correctly — only the negative path truncates, so the output is asymmetric and lossy.Fix
Preserve the fractional part: when the magnitude is integral keep
int(...), otherwise pass the full magnitude so theREMAINDERsubpart recurses through the same decimal-aware path positive numbers already use.Before / after
-1.5minus oneminus one point five-2.25minus twominus two point two five-0.5minusminus zero point five-10.75minus tenminus ten point seven fiveNon-regression:
1.5→one point five,-3→minus three,-100→minus one hundred(unchanged). Cross-checked de/es/fr produce correct "minus … komma/coma/virgule …" output.Reachability / tests
find_rulereturnsNEGATIVE_NUMBERfor anynumber < 0;format_number→iter_format_number→ the"minus" + REMAINDERrule rendersrvia recursion. Existing suite: 124 passed, unchanged before and after.