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
Use a least common denominator to add or subtract fractions; multiply numerator by numerator and denominator by denominator for products; multiply by the reciprocal for division. Reduce by the greatest common divisor and keep the denominator positive. Division by a zero-valued second fraction is rejected.
a/b + c/d = (ad + bc)/bd
(a/b) ÷ (c/d) = ad/bc, c ≠0
a/b − c/d = (ad−bc)/bd
(a/b)(c/d) = ac/bd
Variables and units
- a,b
- first numerator and nonzero denominator
- c,d
- second numerator and nonzero denominator
Worked example
1/4 + 1/6 = 3/12 + 2/12 = 5/12; the displayed decimal is 0.4167.
Limitations
Fraction result is reduced; the optional decimal display is rounded to four places.
- Inputs represent fractions with integer numerators and nonzero integer denominators.
- Displayed decimal approximations may not represent recurring decimals exactly.
- Inputs and intermediate integer products, sums and common-denominator conversions must stay within the safe integer range (absolute value at most 9,007,199,254,740,991). Unsupported operations are rejected rather than shown as exact fractions.
- Zero input denominator is invalid.
- The second fraction cannot be zero in division.
- 9007199254740991/1 + 2/1 is rejected because the exact sum exceeds the supported integer range.