[
https://issues.apache.org/jira/browse/LANG-1603?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17582215#comment-17582215
]
Alex Herbert commented on LANG-1603:
------------------------------------
Note that the two classes are not a drop-in replacement. LANG-1601 highlights
these methods in lang that do not exist in numbers:
{code:java}
public int getProperNumerator()
public int getProperWhole()
public String toProperString() {code}
The methods are to represent fraction A/B as a whole number and fraction part X
Y/Z. However this functionality is not part of numbers. The first two methods
are trivial 1 liners:
{code:java}
int x = numerator / denominator;
int y = Math.abs(numerator % denominator);{code}
However the sign can be in the numerator or the denominator in the numbers
implementation, it is always in the numerator in the lang implementation, and
I've not checked all edge cases. Since there are equivalent methods in Numbers
for the whole part (namely intValue and longValue) the functionality is
achieved using:
{code:java}
int a, b;
Fraction f = Fraction.of(a, b);
// == (int) (a / b)
int x = f.intValue();
// == (int) (a % b)
int y = f.getNumerator() - f.signum() * x * f.getDenominator();
{code}
The string formatting logic to write out fraction X Y/Z is more involved. The
above ticket mentions that this could be achieved in numbers using a formatter
class.
Other methods have name changes:
{noformat}
invert == reciprocal
divideBy == divide
multiplyBy == multiply
{noformat}
> Deprecate the "Fraction" class
> ------------------------------
>
> Key: LANG-1603
> URL: https://issues.apache.org/jira/browse/LANG-1603
> Project: Commons Lang
> Issue Type: Sub-task
> Reporter: Gilles Sadowski
> Priority: Major
> Fix For: 4.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> [Fraction|https://gitbox.apache.org/repos/asf?p=commons-lang.git;a=blob;f=src/main/java/org/apache/commons/lang3/math/Fraction.java;h=e90e340ac5578126492471841f4a97548dbb49f7;hb=HEAD]
> in [Lang] vs
> [Fraction|https://gitbox.apache.org/repos/asf?p=commons-numbers.git;a=blob;f=commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java;h=f1bc54278a9a65538638ddbe9d17a28452a60ca4;hb=HEAD]
> in [Numbers].
--
This message was sent by Atlassian Jira
(v8.20.10#820010)