From 91e3b81b14e3fcde14a590e26b442cc6a4f1a809 Mon Sep 17 00:00:00 2001 From: hhow09 Date: Thu, 23 Jan 2025 18:29:49 +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..7312b35 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