Skip to content

Commit

Permalink
Reduced rational nr. should be in standard form. (#1958)
Browse files Browse the repository at this point in the history
* Reduced rational should be in standard form.

The current instructors fail to mention that a reduced rational number should always be rendered in standard form (without any negative value at the denominator).

* remove superflous blank lines; fix wording
  • Loading branch information
dmolin authored Feb 9, 2022
1 parent 01d14e1 commit 2eaec0c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions exercises/rational-numbers/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ Implement the following operations:
- absolute value, exponentiation of a given rational number to an integer power, exponentiation of a given rational number to a real (floating-point) power, exponentiation of a real number to a rational number.

Your implementation of rational numbers should always be reduced to lowest terms. For example, `4/4` should reduce to `1/1`, `30/60` should reduce to `1/2`, `12/8` should reduce to `3/2`, etc. To reduce a rational number `r = a/b`, divide `a` and `b` by the greatest common divisor (gcd) of `a` and `b`. So, for example, `gcd(12, 8) = 4`, so `r = 12/8` can be reduced to `(12/4)/(8/4) = 3/2`.
The reduced form of a rational number should be in "standard form" (the denominator should always be a positive integer). If a denominator with a negative integer is present, multiply both numerator and denominator by `-1` to ensure standard form is reached. For example, `{3, -4}` should be reduced to `{-3, 4}`

Assume that the programming language you are using does not have an implementation of rational numbers.

0 comments on commit 2eaec0c

Please sign in to comment.