From c01098d976ecbda9b3ddf1d2dede1723bb4711bf Mon Sep 17 00:00:00 2001 From: halibobo1205 Date: Tue, 3 Dec 2024 17:46:30 +0800 Subject: [PATCH] feat(math): migrate all operations from Math to StrictMath for MarketComparator --- .../java/arm/org/tron/common/utils/MarketComparator.java | 6 +++--- .../java/x86/org/tron/common/utils/MarketComparator.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platform/src/main/java/arm/org/tron/common/utils/MarketComparator.java b/platform/src/main/java/arm/org/tron/common/utils/MarketComparator.java index 2528be8780..c2742d4d10 100644 --- a/platform/src/main/java/arm/org/tron/common/utils/MarketComparator.java +++ b/platform/src/main/java/arm/org/tron/common/utils/MarketComparator.java @@ -69,8 +69,8 @@ public static int comparePriceKey(byte[] o1, byte[] o2) { public static int comparePrice(long price1SellQuantity, long price1BuyQuantity, long price2SellQuantity, long price2BuyQuantity) { try { - return Long.compare(Math.multiplyExact(price1BuyQuantity, price2SellQuantity), - Math.multiplyExact(price2BuyQuantity, price1SellQuantity)); + return Long.compare(StrictMath.multiplyExact(price1BuyQuantity, price2SellQuantity), + StrictMath.multiplyExact(price2BuyQuantity, price1SellQuantity)); } catch (ArithmeticException ex) { // do nothing here, because we will use BigInteger to compute again @@ -98,7 +98,7 @@ private static int compareUnsigned(byte[] a, byte[] b) { if (b == null) { return 1; } - int minLen = Math.min(a.length, b.length); + int minLen = StrictMath.min(a.length, b.length); for (int i = 0; i < minLen; ++i) { int aVal = a[i] & 0xFF; int bVal = b[i] & 0xFF; diff --git a/platform/src/main/java/x86/org/tron/common/utils/MarketComparator.java b/platform/src/main/java/x86/org/tron/common/utils/MarketComparator.java index 2528be8780..c2742d4d10 100644 --- a/platform/src/main/java/x86/org/tron/common/utils/MarketComparator.java +++ b/platform/src/main/java/x86/org/tron/common/utils/MarketComparator.java @@ -69,8 +69,8 @@ public static int comparePriceKey(byte[] o1, byte[] o2) { public static int comparePrice(long price1SellQuantity, long price1BuyQuantity, long price2SellQuantity, long price2BuyQuantity) { try { - return Long.compare(Math.multiplyExact(price1BuyQuantity, price2SellQuantity), - Math.multiplyExact(price2BuyQuantity, price1SellQuantity)); + return Long.compare(StrictMath.multiplyExact(price1BuyQuantity, price2SellQuantity), + StrictMath.multiplyExact(price2BuyQuantity, price1SellQuantity)); } catch (ArithmeticException ex) { // do nothing here, because we will use BigInteger to compute again @@ -98,7 +98,7 @@ private static int compareUnsigned(byte[] a, byte[] b) { if (b == null) { return 1; } - int minLen = Math.min(a.length, b.length); + int minLen = StrictMath.min(a.length, b.length); for (int i = 0; i < minLen; ++i) { int aVal = a[i] & 0xFF; int bVal = b[i] & 0xFF;