Skip to content

Preserve fractional part when spelling out negative numbers - #13

Merged
synesthesiam merged 2 commits into
rhasspy:mainfrom
selimfedakar:fix-negative-decimal-spellout
Nov 16, 2026
Merged

synesthesiam merged 2 commits into
rhasspy:mainfrom
selimfedakar:fix-negative-decimal-spellout

Conversation

@selimfedakar

Copy link
Copy Markdown
Contributor

What

Fix negative decimal spellout in the NEGATIVE_NUMBER rule (unicode_rbnf/engine.py, RbnfEngine.iter_format_number).

For negative numbers the code did r = int(-number), truncating the fractional part. The NEGATIVE_NUMBER rule 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 the REMAINDER subpart recurses through the same decimal-aware path positive numbers already use.

Before / after

input before after
-1.5 minus one minus one point five
-2.25 minus two minus two point two five
-0.5 minus minus zero point five
-10.75 minus ten minus ten point seven five

Non-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_rule returns NEGATIVE_NUMBER for any number < 0; format_number → iter_format_number → the "minus" + REMAINDER rule renders r via recursion. Existing suite: 124 passed, unchanged before and after.

selimfedakar and others added 2 commits November 13, 2026 10:35
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>
@synesthesiam
synesthesiam merged commit 465ca76 into rhasspy:main Nov 16, 2026
1 check passed
@synesthesiam

Copy link
Copy Markdown
Member

Thanks!

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.

2 participants