Skip to content

Commit

Permalink
feat(math): migrate all operations from Math to StrictMath for Market…
Browse files Browse the repository at this point in the history
…Comparator
  • Loading branch information
halibobo1205 committed Dec 3, 2024
1 parent a1afbd2 commit c01098d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c01098d

Please sign in to comment.