Background
`edecimal::parse` currently accepts only an integer-format input (regex `[+-]*[0123456789]+`). It rejects:
- Decimal point: `"3.14"` -> fails
- Scientific notation: `"1.5e10"` -> fails
This is a serious limitation for a decimal number system whose entire purpose is exact decimal arithmetic.
`operator>>` also doesn't `setstate(std::ios::failbit)` on parse failure.
Discovered during Phase E of #835.
Scope
- Extend `parse()` to accept:
- Integer literals (existing behavior): `"42"`, `"-1000"`
- Decimal literals: `"3.14"`, `"-2.5"`, `"0.001"`
- Scientific notation: `"1e10"`, `"1.5e-100"`, `"3.14e+200"`
- The edecimal type stores decimal digits in base-10; the parse should preserve those digits exactly (no intermediate floating-point conversion).
- Operator>> hygiene:
- Add `if (!(istr >> txt)) return istr;` guard
- `setstate(failbit)` on parse failure
Implementation notes
- Reuse `sw::universal::string_parse::scan_decimal_float` (the Phase A foundation) for tokenization: it returns int_part, frac_part, exp10 as string_views and validates the input.
- The decimal point position + exponent collapse to an effective digit-shift in the base-10 representation, which edecimal can handle natively.
Acceptance criteria
- New regression test `static/elastic/decimal/conversion/string_parse.cpp` (or appropriate path)
- Coverage: integers, decimal literals, scientific notation, negative values, malformed input rejection, operator>> failbit
- Verified on gcc + clang
Related
Background
`edecimal::parse` currently accepts only an integer-format input (regex `[+-]*[0123456789]+`). It rejects:
This is a serious limitation for a decimal number system whose entire purpose is exact decimal arithmetic.
`operator>>` also doesn't `setstate(std::ios::failbit)` on parse failure.
Discovered during Phase E of #835.
Scope
Implementation notes
Acceptance criteria
Related