Method and source check
Last checked:
Automated source and implementation review, including worked examples and documented numerical limits. This review does not provide professional advice or specialist approval.
Method
For decimal input, approximate a fraction by continued fractions within supported range; preserve representable nonzero inputs and keep denominators positive. Fraction input is divided for the decimal display.
approximation target: p/q β entered decimal
fraction-to-decimal: d = numerator/denominator, denominator β 0
Variables and units
- p,q
- approximate integer numerator and positive denominator
- d
- decimal value
Worked example
0.75 maps to 3/4. Entered 0.333 maps to 333/1000, while 0.333333 may be approximated as 1/3; these are not exact equivalents.
Limitations
Displayed decimal is rounded to six places; the rationalized fraction may approximate the entered decimal within the method tolerance.
- Decimal input uses a six-decimal input step and display precision: it accepts zero or a magnitude from 0.000001 through 9007199254740991. Smaller nonzero values are rejected instead of silently displaying 0.
- Approximate rationalization is not exact decimal-place conversion for every input.
- Finite 0.333 is exactly 333/1000, not exactly 1/3.
- Fraction mode requires safe whole-number numerator and denominator; the denominator cannot be zero. Display scaling preserves a finite value when multiplying it by 1,000,000 would overflow.
- 0.000001 remains 1/1000000, not 0/1.
- Magnitude below 0.000001, such as 1e-320, is rejected with a localized range error.
- A negative fraction denominator is normalized to positive.