Read numbers from their digits, not through float

Open
#409 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start with wiki/audits/ovos-number-parser/design-audit-exact-numbers.md, then inspect the public pronounce_number, extract_number, and numbers_to_digits paths and their language backends. Check consumers of the extract functions before deciding how an opt-in exact return should work; the issue says that API choice needs an owner decision. Done means the listed examples preserve every digit and tests cover the stated cases.

Written by the indexing model from the issue text.

Description

🤖 Auto-generated by Claude Opus 5.5 (claude-opus-5-5) via Claude Code — NOT human-reviewed. Verify before acting. The three examples below were run against the code of #403 and #405 (verified); the design steps are a recommendation (judgment).

What

The parser reads and builds numbers through float. A float holds 15 to 17 significant digits. When a number has more digits than that, the parser speaks or writes digits that are not in the input.

Fixes #401 to #405 remove the float from every path that the public types allow. These cases remain:

Input Result Expected
pronounce_number(Decimal("123456789012345678.25"), "en", places=2) "… six hundred and eighty" "… six hundred and seventy eight point two five"
pronounce_number(Decimal("0.1234567890123456789"), "en", places=19) "… four five six eight" "… four five six seven eight nine"
extract_number("twelve quintillion three hundred forty five point two five", "en") 1.2e+19 Decimal("12000000000000000345.25") from the opt-in exact form (step 4)
numbers_to_digits of the same text "1.2e+19" "12000000000000000345.25"

Whole numbers are not affected. An int or an integral Decimal reads with every digit, and whole-number text extracts as an exact int.

Why

The digits of a number are its meaning. A wrong digit in speech or in a skill's data is a wrong answer, and nothing tells the user. Consumers such as text2spoken and the phoonnx SSML reader read the digits themselves to avoid this. Each such workaround is a second number reader that can disagree with this one.

Every defect found in the float paths came from a float conversion placed where the digits already existed as text. Reading the text directly removes the class of defect, not one case of it.

How

The design audit wiki/audits/ovos-number-parser/design-audit-exact-numbers.md (workspace knowledge base) gives the full argument. The steps:

  1. pronounce_number converts every input once, at entry, to a small frozen value: sign, integer digits, fraction digits. A float enters through repr(), which gives the shortest string that round-trips. A Decimal enters through its own digits. Never use Decimal(float).
  2. The language backends receive that value. One shared reader speaks the fraction digits; each language keeps its own whole-number reader. The per-language public functions keep their signatures, because ovos-date-parser imports them.
  3. The extractors collect digits as text and build the result from the text. numbers_to_digits returns a string, so it is exact always.
  4. extract_number keeps int and float as its return types, because skills do arithmetic on the result and send it in bus messages. An exact result (for example a Decimal) is opt-in, through a new keyword or function.

Step 4 adds public API. That needs an owner decision before the work starts, and an org-wide search for consumers of the extract functions.

Done when

  • Each row of the table above gives the expected result.
  • A Decimal or float with any number of digits reads every digit to places.
  • No path inside the parser converts a value with a fraction to float, except the documented default return of extract_number.
Dominant language
Python
Stars
4
Forks
5
Avg merge
5h 40m
Merged PRs (30d)
97

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenVoiceOS/ovos-number-parser

All issues in OpenVoiceOS/ovos-number-parser

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.