Skip to content

Commit

Permalink
doc: math example
Browse files Browse the repository at this point in the history
  • Loading branch information
hhow09 committed Jan 23, 2025
1 parent bf5e2b0 commit 87408e1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 87408e1

Please sign in to comment.