[
https://issues.apache.org/jira/browse/NUMBERS-127?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Heinrich Bohne updated NUMBERS-127:
-----------------------------------
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.
was: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.
> Fraction(int, int) rejects possibly reducible numerator or denominator 2^-31
> ----------------------------------------------------------------------------
>
> Key: NUMBERS-127
> URL: https://issues.apache.org/jira/browse/NUMBERS-127
> Project: Commons Numbers
> Issue Type: Bug
> Components: fraction
> Affects Versions: 1.0
> Reporter: Heinrich Bohne
> Priority: Minor
>
> 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.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)