diff options
author | Chris Laplante <chris.laplante@agilent.com> | 2019-11-06 13:41:34 -0500 |
---|---|---|
committer | Richard Leitner <richard.leitner@skidata.com> | 2019-11-11 09:34:59 +0100 |
commit | b5db760e6a6048381301414be387c08a3025dc6e (patch) | |
tree | d39d3810d95e8d906d03adf270bf6ae8a157092d /recipes-core/classpath/classpath-0.99 | |
parent | 72d32b73861edeed08e9463ceb6e3995f1982be6 (diff) | |
download | meta-java-b5db760e6a6048381301414be387c08a3025dc6e.tar.gz |
classpath: add patch to fix BigDecimal.compareTo()
Prior to this patch compareTo couldn't handle operands with negative
scales. It passes the following unit test from JDK8:
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/test/java/math/BigDecimal/CompareToTests.java
Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
Diffstat (limited to 'recipes-core/classpath/classpath-0.99')
-rw-r--r-- | recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch b/recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch new file mode 100644 index 0000000..35fb81e --- /dev/null +++ b/recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch | |||
@@ -0,0 +1,68 @@ | |||
1 | From b561cdb6f3fef251696216775c775f84369278cc Mon Sep 17 00:00:00 2001 | ||
2 | From: Chris Laplante <chris.laplante@agilent.com> | ||
3 | Date: Wed, 2 Oct 2019 21:38:11 -0400 | ||
4 | Subject: [PATCH 1/2] Fix bad implementation of compareTo in BigDecimal | ||
5 | |||
6 | Prior to this patch compareTo couldn't handle operands with negative | ||
7 | scales. It passes the following unit test from JDK8: | ||
8 | http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/test/java/math/BigDecimal/CompareToTests.java | ||
9 | |||
10 | Upstream-Status: Inappropriate [dead project] | ||
11 | |||
12 | Signed-off-by: Chris Laplante <chris.laplante@agilent.com> | ||
13 | --- | ||
14 | java/math/BigDecimal.java | 32 ++++++++++++++++++-------------- | ||
15 | 1 file changed, 18 insertions(+), 14 deletions(-) | ||
16 | |||
17 | diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java | ||
18 | index 7f4546c..e14d894 100644 | ||
19 | --- a/java/math/BigDecimal.java | ||
20 | +++ b/java/math/BigDecimal.java | ||
21 | @@ -861,26 +861,30 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> | ||
22 | if (scale == val.scale) | ||
23 | return intVal.compareTo (val.intVal); | ||
24 | |||
25 | - BigInteger thisParts[] = | ||
26 | - intVal.divideAndRemainder (BigInteger.TEN.pow (scale)); | ||
27 | - BigInteger valParts[] = | ||
28 | - val.intVal.divideAndRemainder (BigInteger.TEN.pow (val.scale)); | ||
29 | + BigInteger[] thisParts = new BigInteger[2]; | ||
30 | + BigInteger[] valParts = new BigInteger[2]; | ||
31 | + | ||
32 | + if (scale > 0) | ||
33 | + thisParts = intVal.divideAndRemainder (BigInteger.TEN.pow (scale)); | ||
34 | + else | ||
35 | + { | ||
36 | + thisParts[0] = intVal.multiply (BigInteger.TEN.pow (-scale)); | ||
37 | + thisParts[1] = BigInteger.ZERO; | ||
38 | + } | ||
39 | + | ||
40 | + if (val.scale > 0) | ||
41 | + valParts = val.intVal.divideAndRemainder (BigInteger.TEN.pow (val.scale)); | ||
42 | + else | ||
43 | + { | ||
44 | + valParts[0] = val.intVal.multiply (BigInteger.TEN.pow (-val.scale)); | ||
45 | + valParts[1] = BigInteger.ZERO; | ||
46 | + } | ||
47 | |||
48 | int compare; | ||
49 | if ((compare = thisParts[0].compareTo (valParts[0])) != 0) | ||
50 | return compare; | ||
51 | |||
52 | // quotients are the same, so compare remainders | ||
53 | - | ||
54 | - // Add some trailing zeros to the remainder with the smallest scale | ||
55 | - if (scale < val.scale) | ||
56 | - thisParts[1] = thisParts[1].multiply | ||
57 | - (BigInteger.valueOf (10).pow (val.scale - scale)); | ||
58 | - else if (scale > val.scale) | ||
59 | - valParts[1] = valParts[1].multiply | ||
60 | - (BigInteger.valueOf (10).pow (scale - val.scale)); | ||
61 | - | ||
62 | - // and compare them | ||
63 | return thisParts[1].compareTo (valParts[1]); | ||
64 | } | ||
65 | |||
66 | -- | ||
67 | 2.7.4 | ||
68 | |||