One big issue I have with your code is that all of of your comparisons are based off of the fraction's double value. This can lead to many bugs down the line that result in questions like thisthis.
To fix this: you can do one of two things: define or pass an epsilon (such as .00001) to be used for comparison.
Or even better, use the denominator and numerator to compare fractions.
To do so, I would utilize memoization (to make this performant for repeated calls on the same fraction), and to to store the fraction in reduced form. Then you do a simple comparison on the reduced form like so:
- Fraction 1: \$\dfrac{x}{y}\$
- Fraction 2: \$\dfrac{a}{b}\$
Compare \$x*b\$ to \$a*y\$:
- if \$x*b > a*y\$, Fraction 1 is bigger.
- if \$x*b < a*y\$, Fraction 2 is bigger.
- if \$x*b = a*y\$, Fraction 1 is equal to Fraction 2.