Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/main/java/tp/Fraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,30 @@ public void setDenominator(int denominator) {
* the numerator must be positive and the denominator must be negative.
*/
private void reduce() {
int n = numerator;
int d = denominator;
int lePlusGrand;

}
if (numerator < 0) {
n = -numerator;
}
if (n > d) {
lePlusGrand = n;
}
else {
lePlusGrand = d;
}
int diviseur = 0;
for (int i = lePlusGrand; i >= 2; i--) {
if (numerator % i == 0 && denominator % i == 0) {
diviseur = i;
}
}
if (diviseur != 0) {
numerator /= gcd;
denominator /= gcd;
}
}
/** MICHOTTE Martin
* Get a textual representation of the fraction
* Ex : 3, 1/2, 4/3
Expand Down