summaryrefslogtreecommitdiffstats
path: root/recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch')
-rw-r--r--recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch68
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 @@
1From b561cdb6f3fef251696216775c775f84369278cc Mon Sep 17 00:00:00 2001
2From: Chris Laplante <chris.laplante@agilent.com>
3Date: Wed, 2 Oct 2019 21:38:11 -0400
4Subject: [PATCH 1/2] Fix bad implementation of compareTo in BigDecimal
5
6Prior to this patch compareTo couldn't handle operands with negative
7scales. It passes the following unit test from JDK8:
8http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/test/java/math/BigDecimal/CompareToTests.java
9
10Upstream-Status: Inappropriate [dead project]
11
12Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
13---
14 java/math/BigDecimal.java | 32 ++++++++++++++++++--------------
15 1 file changed, 18 insertions(+), 14 deletions(-)
16
17diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java
18index 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--
672.7.4
68