diff --git a/common/src/main/java/org/tron/common/math/MathWrapper.java b/common/src/main/java/org/tron/common/math/MathWrapper.java index 4a1acf6c0f3..f643dea05b0 100644 --- a/common/src/main/java/org/tron/common/math/MathWrapper.java +++ b/common/src/main/java/org/tron/common/math/MathWrapper.java @@ -140,6 +140,12 @@ public static double pow(double a, double b) { public static double powForExchange(double a, double b) { Preconditions.checkArgument(b > -1 && b < 1, "b must be -1 1 && a < 2, "a must be 1 data = Collections.synchronizedMap(new HashMap<>()); /** @@ -371,6 +369,17 @@ private static void addData(String a, String x87Ret) { data.put(hexToDouble(a), hexToDouble(x87Ret)); } + public static Double get(double key) { + return data.get(key); + } + + static String doubleToHex(double input) { + // Convert the double to a long + long inputAsLong = Double.doubleToLongBits(input); + // and then convert the long to a hex string + return Long.toHexString(inputAsLong); + } + static double hexToDouble(String input) { // Convert the hex string to a long long hexAsLong = Long.parseLong(input, 16); diff --git a/common/src/test/java/org/tron/common/math/MathTest.java b/common/src/test/java/org/tron/common/math/MathTest.java index 0ca55a07c3c..ba49d8024bd 100644 --- a/common/src/test/java/org/tron/common/math/MathTest.java +++ b/common/src/test/java/org/tron/common/math/MathTest.java @@ -15,8 +15,7 @@ public void testPow() { double ret3 = StrictMathWrapper.pow(a, 0.0005); Assert.assertNotEquals(0, Double.compare(ret, ret2)); Assert.assertNotEquals(0, Double.compare(ret2, ret3)); - Assert.assertEquals(0, Double.compare( - PowDataForJdk8.getData().get(a), ret2)); + Assert.assertEquals(0, Double.compare(PowDataForJdk8.get(a), ret2)); Assert.assertEquals(0, Double.compare(ret, ret3)); } }