Description
Since the sign of a fraction is held by the numerator, it is possible that the values passed as numerator and denominator need to be negated. This is not possible for 2^-31 due to overflow, so the constructor throws an exception in this case. However, the constructor forgets that this value might be reducible if the passed numerator and denominator are not coprime, so it rejects values where the representation in lowest terms would not overflow.
Also, the check whether the denominator is negative and the corresponding negation of the numerator and denominator is coded twice, with the second conditional block being dead code because the sign has already been moved to the numerator by then.
Attachments
Issue Links
- links to