You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
new Fraction(-1, 10).Reciprocal().IsEquivalentTo(new Fraction(-10))
false
bool
Normally this should have been true for the Equals as well, but I think this illustrates the issue better.
This problem stems from the fact that the sign of the fraction is not handled here
public static Fraction Reciprocal(Fraction fraction) =>
new Fraction(fraction.Denominator, fraction.Numerator, fraction.State);
According to GetReducedFraction a Normalized fraction should have it's signs normalized:
if (denominator.Sign == -1) {
// Denominator must not be negative after normalization
numerator = BigInteger.Negate(numerator);
denominator = BigInteger.Negate(denominator);
}
I'd be willing to create a PR, but I was hoping that we could merge my "cleanup" of the test project first, if you don't mind..
The text was updated successfully, but these errors were encountered:
- Code cleanup
- use new language features
- use method body (if possible)
- use var statement instead of type declaration (if possible)
- fix#27 [BUG] Reciprocal of a negative fraction has invalid state (#27)
- fix typos
- Code cleanup
- use new language features
- use expression body for methods (if possible)
- use var statement instead of type declaration (if possible)
- fix#27 [BUG] Reciprocal of a negative fraction has invalid state (#27)
- fix typos
Consider the following scenario:
Normally this should have been true for the
Equals
as well, but I think this illustrates the issue better.This problem stems from the fact that the sign of the fraction is not handled here
According to
GetReducedFraction
a Normalized fraction should have it's signs normalized:I'd be willing to create a PR, but I was hoping that we could merge my "cleanup" of the test project first, if you don't mind..
The text was updated successfully, but these errors were encountered: