format_number loses both the sign and the magnitude of negative values, returning a positive fraction instead.
Reproduction
| Input |
Returns |
Expected |
-0.5 |
"1/2" |
"-0.5" or "-1/2" |
-1.5 |
"1/2" |
"-1.5" |
-0.25 |
"3/4" |
"-0.25" |
-0.25 returning "3/4" is the clearest case: neither the sign nor the value survives.
Cause
decimal_to_fraction computes the fractional part as value - value.floor(). For -0.25 that is -0.25 - (-1.0) == 0.75, which matches the 3/4 entry in the common-fractions table. The whole > 0.0 guard that would otherwise prepend the integer part never fires, because whole is negative — so the whole part is dropped entirely.
Impact
Low in the CLI today: no seed or test recipe carries a negative quantity, and the function is reached through format_quantity for recipe and web output. It matters more as the function becomes reachable from a library API, where callers are not constrained to the CLI's input range.
Notes
A fix is in flight as part of extracting the formatters into a library crate — guarding decimal_to_fraction so negatives fall through to the decimal path, with tests pinning the corrected values. Verified to change no existing snapshot. Filing separately because it is a pre-existing defect on main.
format_numberloses both the sign and the magnitude of negative values, returning a positive fraction instead.Reproduction
-0.5"1/2""-0.5"or"-1/2"-1.5"1/2""-1.5"-0.25"3/4""-0.25"-0.25returning"3/4"is the clearest case: neither the sign nor the value survives.Cause
decimal_to_fractioncomputes the fractional part asvalue - value.floor(). For-0.25that is-0.25 - (-1.0) == 0.75, which matches the3/4entry in the common-fractions table. Thewhole > 0.0guard that would otherwise prepend the integer part never fires, becausewholeis negative — so the whole part is dropped entirely.Impact
Low in the CLI today: no seed or test recipe carries a negative quantity, and the function is reached through
format_quantityfor recipe and web output. It matters more as the function becomes reachable from a library API, where callers are not constrained to the CLI's input range.Notes
A fix is in flight as part of extracting the formatters into a library crate — guarding
decimal_to_fractionso negatives fall through to the decimal path, with tests pinning the corrected values. Verified to change no existing snapshot. Filing separately because it is a pre-existing defect onmain.