From 87408e1c6f3e6d21e533089965392954f29cbb05 Mon Sep 17 00:00:00 2001 From: hhow09 Date: Thu, 23 Jan 2025 18:21:45 +0100 Subject: [PATCH] doc: math example --- backend/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/README.md b/backend/README.md index 62efff3..5db2103 100644 --- a/backend/README.md +++ b/backend/README.md @@ -56,6 +56,13 @@ src - [Decimal.js](https://mikemcl.github.io/decimal.js/) is used for the basic arithmetic operations. 4. Evaluate the result by `Fraction.evaluate()`. +### Example +1. Input string: `5 / 3 / 4 * 9 - 2 * 3 / 8` +2. Parse into sub-expressions: `5 / 3 / 4 * 9` and `-2 * 3 / 8` +3. Turn these into fractions: $\frac{5*9}{3*4}$ and -$\frac{2*3}{8}$ +4. find equivalent fractions with same denominator: $\frac{90}{24}$ and -$\frac{18}{24}$ +5. Sum these fractions: $\frac{90}{24} - \frac{18}{24} = \frac{72}{24} = 3$ + ### Limitations - All whitespace is ignored, therefore `1 + 2 3` will consider as `1 + 23` - `negative sign` is only allowed at the beginning of an expression but not after multiplication or division