Skip to content

Commit

Permalink
tests for compare
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Jul 23, 2024
1 parent 8a5d55b commit 998b2f7
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 76 deletions.
134 changes: 70 additions & 64 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
LibDecimalFloatAbsTest:testAbsMinValue(int256) (runs: 5106, μ: 4419, ~: 4419)
LibDecimalFloatAbsTest:testAbsNegative(int256,int256) (runs: 5107, μ: 9914, ~: 10164)
LibDecimalFloatAbsTest:testAbsNonNegative(int256,int256) (runs: 5107, μ: 9040, ~: 8691)
LibDecimalFloatAbsTest:testAbsMinValue(int256) (runs: 5108, μ: 4419, ~: 4419)
LibDecimalFloatAbsTest:testAbsNegative(int256,int256) (runs: 5109, μ: 9914, ~: 10164)
LibDecimalFloatAbsTest:testAbsNonNegative(int256,int256) (runs: 5109, μ: 9040, ~: 8691)
LibDecimalFloatDecimalAddTest:testAdd123456789987654321() (gas: 6203)
LibDecimalFloatDecimalAddTest:testAdd123456789e9987654321() (gas: 6255)
LibDecimalFloatDecimalAddTest:testAddNeverRevert(int256,int256,int256,int256) (runs: 5107, μ: 14149, ~: 14075)
LibDecimalFloatDecimalAddTest:testAddNeverRevert(int256,int256,int256,int256) (runs: 5109, μ: 14149, ~: 14075)
LibDecimalFloatDecimalAddTest:testAddOneOneNotNormalized() (gas: 5818)
LibDecimalFloatDecimalAddTest:testAddOneOnePreNormalized() (gas: 4250)
LibDecimalFloatDecimalAddTest:testAddOneZero() (gas: 3688)
LibDecimalFloatDecimalAddTest:testAddSameExponentSameCoefficient(int256,int256) (runs: 5107, μ: 6416, ~: 6427)
LibDecimalFloatDecimalAddTest:testAddSameExponentSameCoefficient(int256,int256) (runs: 5109, μ: 6415, ~: 6427)
LibDecimalFloatDecimalAddTest:testAddZero() (gas: 3664)
LibDecimalFloatDecimalAddTest:testAddZeroAnyExponent(int128) (runs: 5107, μ: 9310, ~: 9245)
LibDecimalFloatDecimalAddTest:testAddZeroAnyExponent(int128) (runs: 5109, μ: 9310, ~: 9245)
LibDecimalFloatDecimalAddTest:testAddZeroOne() (gas: 3686)
LibDecimalFloatDecimalAddTest:testAddZeroToAnyNonZero(int256,int256,int256) (runs: 5106, μ: 14299, ~: 14243)
LibDecimalFloatDecimalAddTest:testAddZeroToAnyNonZero(int256,int256,int256) (runs: 5108, μ: 14299, ~: 14243)
LibDecimalFloatDecimalAddTest:testAddingSmallToLargeReturnsLargeExamples() (gas: 19289)
LibDecimalFloatDecimalAddTest:testAddingSmallToLargeReturnsLargeFuzz(int256,int256,int256,int256) (runs: 5099, μ: 18700, ~: 18773)
LibDecimalFloatDecimalAddTest:testAddingSmallToLargeReturnsLargeFuzz(int256,int256,int256,int256) (runs: 5100, μ: 18700, ~: 18773)
LibDecimalFloatDecimalAddTest:testGasAddOne() (gas: 944)
LibDecimalFloatDecimalAddTest:testGasAddZero() (gas: 382)
LibDecimalFloatDecimalTest:testFixedDecimalRoundTripLossless(uint256,uint8) (runs: 5107, μ: 10148, ~: 10196)
LibDecimalFloatDecimalTest:testFixedDecimalRoundTripLossless(uint256,uint8) (runs: 5109, μ: 10148, ~: 10196)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyComplicated() (gas: 1022048)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyNormalizedMax() (gas: 760206)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyNormalizedMaxPlusOne() (gas: 866032)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyOne() (gas: 975616)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyOneMillion() (gas: 952412)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyOverflow() (gas: 838681)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyTruncateOne(uint256,uint8) (runs: 5107, μ: 9542, ~: 7195)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyTruncateZero(uint256,uint8) (runs: 5107, μ: 8537, ~: 7207)
LibDecimalFloatDecimalTest:testToFixedDecimalLosslessScaleUp(int256,int256,uint8) (runs: 5101, μ: 15985, ~: 15974)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyExponentOverflow(int256,int256,uint8) (runs: 5107, μ: 14953, ~: 14718)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyIdentity(int256,uint8) (runs: 5107, μ: 10117, ~: 9778)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyNegative(int256,int256,uint8) (runs: 5107, μ: 9905, ~: 10161)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyTruncateOne(uint256,uint8) (runs: 5109, μ: 9541, ~: 7195)
LibDecimalFloatDecimalTest:testFromFixedDecimalLossyTruncateZero(uint256,uint8) (runs: 5109, μ: 8537, ~: 7207)
LibDecimalFloatDecimalTest:testToFixedDecimalLosslessScaleUp(int256,int256,uint8) (runs: 5103, μ: 15985, ~: 15974)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyExponentOverflow(int256,int256,uint8) (runs: 5109, μ: 14953, ~: 14718)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyIdentity(int256,uint8) (runs: 5109, μ: 10117, ~: 9778)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyNegative(int256,int256,uint8) (runs: 5109, μ: 9905, ~: 10161)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyScaleUpOverflow(int256,int256,uint8) (runs: 5102, μ: 13918, ~: 14172)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyTruncate(int256,int256,uint8) (runs: 5107, μ: 14472, ~: 14190)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyTruncate(int256,int256,uint8) (runs: 5109, μ: 14472, ~: 14190)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyTruncateLossless() (gas: 14500)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyUnderflow(int256,int256,uint8) (runs: 5107, μ: 13713, ~: 13580)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyZero(int256,uint8) (runs: 5107, μ: 4575, ~: 4575)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyUnderflow(int256,int256,uint8) (runs: 5109, μ: 13713, ~: 13580)
LibDecimalFloatDecimalTest:testToFixedDecimalLossyZero(int256,uint8) (runs: 5109, μ: 4575, ~: 4575)
LibDecimalFloatDivideTest:testDivide1Over3() (gas: 6420)
LibDecimalFloatDivideTest:testDivide1Over3Gas0() (gas: 761)
LibDecimalFloatDivideTest:testDivide1Over3Gas10() (gas: 7068)
Expand All @@ -43,64 +43,70 @@ LibDecimalFloatDivideTest:testDivideNegative1Over3() (gas: 6490)
LibDecimalFloatDivideTest:testDivideOOMs5and2() (gas: 4827)
LibDecimalFloatDivideTest:testDivideOOMsOverTen() (gas: 5873)
LibDecimalFloatDivideTest:testDivideTenOverOOMs() (gas: 5738)
LibDecimalFloatDivideTest:testUnnormalizedThreesDivision0(int256,int256) (runs: 111, μ: 23628110, ~: 23628366)
LibDecimalFloatEqTest:testEqGasAZero() (gas: 410)
LibDecimalFloatEqTest:testEqGasBZero() (gas: 409)
LibDecimalFloatEqTest:testEqGasBothZero() (gas: 430)
LibDecimalFloatEqTest:testEqGasDifferentSigns() (gas: 440)
LibDecimalFloatEqTest:testEqGasExponentDiffOverflow() (gas: 558)
LibDecimalFloatEqTest:testEqOneEAny(int256,int256) (runs: 5107, μ: 3396, ~: 3396)
LibDecimalFloatEqTest:testEqX(int256) (runs: 5107, μ: 3372, ~: 3372)
LibDecimalFloatEqTest:testEqXEAnyVsXEAny(int256,int256,int256) (runs: 5105, μ: 4698, ~: 4696)
LibDecimalFloatEqTest:testEqXEqY(int256,int256,int256,int256) (runs: 5107, μ: 714, ~: 733)
LibDecimalFloatEqTest:testEqXNotY(int256,int256,int256,int256) (runs: 5106, μ: 3863, ~: 3888)
LibDecimalFloatEqTest:testEqXNotYExponents(int256,int256,int256,int256) (runs: 5107, μ: 4222, ~: 4301)
LibDecimalFloatEqTest:testEqZero(int256,int256) (runs: 5107, μ: 3442, ~: 3442)
LibDecimalFloatGtTest:testGtGasAZero() (gas: 431)
LibDecimalFloatGtTest:testGtGasBZero() (gas: 430)
LibDecimalFloatGtTest:testGtGasBothZero() (gas: 432)
LibDecimalFloatGtTest:testGtGasDifferentSigns() (gas: 410)
LibDecimalFloatGtTest:testGtGasExponentDiffOverflow() (gas: 513)
LibDecimalFloatGtTest:testGtOneEAny(int256,int256) (runs: 5107, μ: 3445, ~: 3445)
LibDecimalFloatGtTest:testGtX(int256) (runs: 5107, μ: 3419, ~: 3419)
LibDecimalFloatGtTest:testGtXEAnyVsXEAny(int256,int256,int256) (runs: 5107, μ: 9681, ~: 9468)
LibDecimalFloatGtTest:testGtXEAnyVsXEAnyNegative(int256,int256,int256) (runs: 5107, μ: 10305, ~: 10552)
LibDecimalFloatGtTest:testGtXNotY(int256,int256,int256,int256) (runs: 5107, μ: 4209, ~: 4288)
LibDecimalFloatGtTest:testGtZero(int256,int256) (runs: 5107, μ: 3422, ~: 3422)
LibDecimalFloatDivideTest:testUnnormalizedThreesDivision0(int256,int256) (runs: 113, μ: 23628114, ~: 23628366)
LibDecimalFloatEqTest:testEqGasAZero() (gas: 430)
LibDecimalFloatEqTest:testEqGasBZero() (gas: 473)
LibDecimalFloatEqTest:testEqGasBothZero() (gas: 450)
LibDecimalFloatEqTest:testEqGasDifferentSigns() (gas: 482)
LibDecimalFloatEqTest:testEqGasExponentDiffOverflow() (gas: 578)
LibDecimalFloatEqTest:testEqNotReverts(int256,int256,int256,int256) (runs: 5109, μ: 653, ~: 679)
LibDecimalFloatEqTest:testEqOneEAny(int256,int256) (runs: 5109, μ: 3416, ~: 3416)
LibDecimalFloatEqTest:testEqReference(int256,int256,int256,int256) (runs: 5109, μ: 9883, ~: 11437)
LibDecimalFloatEqTest:testEqX(int256) (runs: 5109, μ: 3392, ~: 3392)
LibDecimalFloatEqTest:testEqXEAnyVsXEAny(int256,int256,int256) (runs: 5107, μ: 4716, ~: 4714)
LibDecimalFloatEqTest:testEqXEqY(int256,int256,int256,int256) (runs: 5109, μ: 732, ~: 753)
LibDecimalFloatEqTest:testEqXNotY(int256,int256,int256,int256) (runs: 5107, μ: 3927, ~: 3953)
LibDecimalFloatEqTest:testEqXNotYExponents(int256,int256,int256,int256) (runs: 5109, μ: 4241, ~: 4321)
LibDecimalFloatEqTest:testEqZero(int256,int256) (runs: 5109, μ: 3440, ~: 3440)
LibDecimalFloatGtTest:testGtGasAZero() (gas: 429)
LibDecimalFloatGtTest:testGtGasBZero() (gas: 428)
LibDecimalFloatGtTest:testGtGasBothZero() (gas: 452)
LibDecimalFloatGtTest:testGtGasDifferentSigns() (gas: 430)
LibDecimalFloatGtTest:testGtGasExponentDiffOverflow() (gas: 578)
LibDecimalFloatGtTest:testGtOneEAny(int256,int256) (runs: 5109, μ: 3443, ~: 3443)
LibDecimalFloatGtTest:testGtReference(int256,int256,int256,int256) (runs: 5109, μ: 9876, ~: 11407)
LibDecimalFloatGtTest:testGtX(int256) (runs: 5109, μ: 3417, ~: 3417)
LibDecimalFloatGtTest:testGtXEAnyVsXEAny(int256,int256,int256) (runs: 5109, μ: 9742, ~: 9530)
LibDecimalFloatGtTest:testGtXEAnyVsXEAnyNegative(int256,int256,int256) (runs: 5109, μ: 10324, ~: 10570)
LibDecimalFloatGtTest:testGtXNotY(int256,int256,int256,int256) (runs: 5109, μ: 4207, ~: 4286)
LibDecimalFloatGtTest:testGtXPositiveYNegative(int256,int256,int256,int256) (runs: 5109, μ: 12894, ~: 12801)
LibDecimalFloatGtTest:testGtXPositiveYZero(int256,int256,int256) (runs: 5109, μ: 9465, ~: 9255)
LibDecimalFloatGtTest:testGtZero(int256,int256) (runs: 5109, μ: 3465, ~: 3465)
LibDecimalFloatInvTest:testInvGas0() (gas: 734)
LibDecimalFloatInvTest:testInvReference(int256,int256) (runs: 5105, μ: 13017, ~: 13131)
LibDecimalFloatInvTest:testInvReference(int256,int256) (runs: 5107, μ: 13016, ~: 13131)
LibDecimalFloatInvTest:testInvSlowGas0() (gas: 755)
LibDecimalFloatLog10Test:testExactLogs() (gas: 19667)
LibDecimalFloatLtTest:testLtGasAZero() (gas: 430)
LibDecimalFloatLtTest:testLtGasBZero() (gas: 452)
LibDecimalFloatLtTest:testLtGasBothZero() (gas: 431)
LibDecimalFloatLtTest:testLtGasDifferentSigns() (gas: 453)
LibDecimalFloatLtTest:testLtGasExponentDiffOverflow() (gas: 515)
LibDecimalFloatLtTest:testLtNegativeVsPositive(int256,int256,int256,int256) (runs: 5107, μ: 12842, ~: 12740)
LibDecimalFloatLtTest:testLtNegativeVsZero(int256,int256,int256) (runs: 5107, μ: 9987, ~: 10236)
LibDecimalFloatLtTest:testLtOneEAny(int256,int256) (runs: 5107, μ: 3445, ~: 3445)
LibDecimalFloatLtTest:testLtVsEqualVsGt(int256,int256,int256,int256) (runs: 5107, μ: 4238, ~: 4312)
LibDecimalFloatLtTest:testLtX(int256) (runs: 5107, μ: 3396, ~: 3396)
LibDecimalFloatLtTest:testLtXEAnyVsXEAny(int256,int256,int256) (runs: 5107, μ: 9725, ~: 9512)
LibDecimalFloatLtTest:testLtXEAnyVsXEAnyNegative(int256,int256,int256) (runs: 5107, μ: 10261, ~: 10508)
LibDecimalFloatLtTest:testLtZero(int256,int256) (runs: 5107, μ: 3422, ~: 3422)
LibDecimalFloatLtTest:testLtGasAZero() (gas: 450)
LibDecimalFloatLtTest:testLtGasBZero() (gas: 472)
LibDecimalFloatLtTest:testLtGasBothZero() (gas: 451)
LibDecimalFloatLtTest:testLtGasDifferentSigns() (gas: 473)
LibDecimalFloatLtTest:testLtGasExponentDiffOverflow() (gas: 535)
LibDecimalFloatLtTest:testLtNegativeVsPositive(int256,int256,int256,int256) (runs: 5109, μ: 12879, ~: 12780)
LibDecimalFloatLtTest:testLtNegativeVsZero(int256,int256,int256) (runs: 5109, μ: 10028, ~: 10276)
LibDecimalFloatLtTest:testLtOneEAny(int256,int256) (runs: 5109, μ: 3465, ~: 3465)
LibDecimalFloatLtTest:testLtReference(int256,int256,int256,int256) (runs: 5109, μ: 9901, ~: 11454)
LibDecimalFloatLtTest:testLtVsEqualVsGt(int256,int256,int256,int256) (runs: 5109, μ: 4258, ~: 4332)
LibDecimalFloatLtTest:testLtX(int256) (runs: 5109, μ: 3438, ~: 3438)
LibDecimalFloatLtTest:testLtXEAnyVsXEAny(int256,int256,int256) (runs: 5109, μ: 9764, ~: 9552)
LibDecimalFloatLtTest:testLtXEAnyVsXEAnyNegative(int256,int256,int256) (runs: 5109, μ: 10303, ~: 10548)
LibDecimalFloatLtTest:testLtZero(int256,int256) (runs: 5109, μ: 3442, ~: 3442)
LibDecimalFloatMixedTest:testDivide1Over3() (gas: 7213)
LibDecimalFloatMultiplyTest:testMultiply123456789987654321() (gas: 3720)
LibDecimalFloatMultiplyTest:testMultiply123456789987654321WithExponents(int128,int128) (runs: 5107, μ: 13185, ~: 13269)
LibDecimalFloatMultiplyTest:testMultiply123456789987654321WithExponents(int128,int128) (runs: 5109, μ: 13184, ~: 13269)
LibDecimalFloatMultiplyTest:testMultiply1e181e19() (gas: 3721)
LibDecimalFloatMultiplyTest:testMultiplyGasOne() (gas: 382)
LibDecimalFloatMultiplyTest:testMultiplyGasZero() (gas: 348)
LibDecimalFloatMultiplyTest:testMultiplyNotRevertAnyExpectation(int256,int256,int256,int256) (runs: 5107, μ: 13911, ~: 13097)
LibDecimalFloatMultiplyTest:testMultiplyNotRevertAnyExpectation(int256,int256,int256,int256) (runs: 5109, μ: 13910, ~: 13097)
LibDecimalFloatMultiplyTest:testMultiplyOneOne() (gas: 3697)
LibDecimalFloatMultiplyTest:testMultiplyOneZero() (gas: 3663)
LibDecimalFloatMultiplyTest:testMultiplyZero0Exponent() (gas: 3619)
LibDecimalFloatMultiplyTest:testMultiplyZeroAnyExponent(int64,int64) (runs: 5107, μ: 3907, ~: 3907)
LibDecimalFloatMultiplyTest:testMultiplyZeroAnyExponent(int64,int64) (runs: 5109, μ: 3907, ~: 3907)
LibDecimalFloatMultiplyTest:testMultiplyZeroOne() (gas: 3620)
LibDecimalFloatPackTest:testNormalizedRoundTrip(int256,int256) (runs: 5107, μ: 11154, ~: 11057)
LibDecimalFloatPackTest:testPartsRoundTrip(int128,int128) (runs: 5107, μ: 4718, ~: 4718)
LibDecimalFloatSubTest:testMinusIsSubZero(int256,int256,int256) (runs: 5107, μ: 13217, ~: 13268)
LibDecimalFloatSubTest:testSubIsAdd(int256,int256,int256,int256) (runs: 5107, μ: 17589, ~: 17843)
LibDecimalFloatSubTest:testSubMinSignedValue(int256,int256,int256) (runs: 5107, μ: 17350, ~: 17236)
LibDecimalFloatPackTest:testNormalizedRoundTrip(int256,int256) (runs: 5109, μ: 11154, ~: 11057)
LibDecimalFloatPackTest:testPartsRoundTrip(int128,int128) (runs: 5109, μ: 4718, ~: 4718)
LibDecimalFloatSubTest:testMinusIsSubZero(int256,int256,int256) (runs: 5109, μ: 13217, ~: 13268)
LibDecimalFloatSubTest:testSubIsAdd(int256,int256,int256,int256) (runs: 5108, μ: 17589, ~: 17843)
LibDecimalFloatSubTest:testSubMinSignedValue(int256,int256,int256) (runs: 5109, μ: 17350, ~: 17236)
LibLogTableBytesTest:testToBytesAntiLogTableDec() (gas: 158027)
LibLogTableBytesTest:testToBytesAntiLogTableDecSmall() (gas: 160620)
LibLogTableBytesTest:testToBytesLogTableDec() (gas: 141631)
Expand Down
127 changes: 127 additions & 0 deletions test/lib/LibDecimalFloatSlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity ^0.8.25;
import {LibDecimalFloatImplementation} from "src/lib/implementation/LibDecimalFloatImplementation.sol";
import {LibDecimalFloat} from "src/lib/LibDecimalFloat.sol";

import {console2} from "forge-std/Test.sol";

library LibDecimalFloatSlow {
function multiplySlow(int256 signedCoefficientA, int256 exponentA, int256 signedCoefficientB, int256 exponentB)
internal
Expand Down Expand Up @@ -40,4 +42,129 @@ library LibDecimalFloatSlow {
function invSlow(int256 signedCoefficient, int256 exponent) internal pure returns (int256, int256) {
return LibDecimalFloat.divide(1e37, -37, signedCoefficient, exponent);
}

function eqSlow(int256 signedCoefficientA, int256 exponentA, int256 signedCoefficientB, int256 exponentB)
internal
pure
returns (bool)
{
// If the exponents are the same we compare the coefficients.
if (exponentA == exponentB) {
return signedCoefficientA == signedCoefficientB;
}

// Comparisons with zero ignore exponents.
if (signedCoefficientA == 0 || signedCoefficientB == 0) {
return signedCoefficientA == signedCoefficientB;
}

unchecked {
int256 tmp = 0;
while (exponentA > exponentB) {
tmp = signedCoefficientA * 10;
if (tmp / 10 != signedCoefficientA) {
return false;
}
signedCoefficientA = tmp;
exponentA--;
}

while (exponentB > exponentA) {
tmp = signedCoefficientB * 10;
if (tmp / 10 != signedCoefficientB) {
return false;
}
signedCoefficientB = tmp;
exponentB--;
}
}

return eqSlow(signedCoefficientA, exponentA, signedCoefficientB, exponentB);
}

function gtSlow(int256 signedCoefficientA, int256 exponentA, int256 signedCoefficientB, int256 exponentB)
internal
pure
returns (bool)
{
// If the exponents are the same we compare the coefficients.
if (exponentA == exponentB) {
return signedCoefficientA > signedCoefficientB;
}

// Comparisons with zero ignore exponents.
if (signedCoefficientA == 0 || signedCoefficientB == 0) {
return signedCoefficientA > signedCoefficientB;
}

unchecked {
int256 tmp = 0;
while (exponentA > exponentB) {
tmp = signedCoefficientA * 10;
if (tmp / 10 != signedCoefficientA) {
// A overflowed so is huge in magnitude, it's gt everything
// if positive and lt everything if it's negative.
return signedCoefficientA > 0;
}
signedCoefficientA = tmp;
exponentA--;
}

while (exponentB > exponentA) {
tmp = signedCoefficientB * 10;
if (tmp / 10 != signedCoefficientB) {
// B overflowed so is huge in magnitude, it's gt everything
// if positive and lt everything if it's negative.
return signedCoefficientB < 0;
}
signedCoefficientB = tmp;
exponentB--;
}
}

return gtSlow(signedCoefficientA, exponentA, signedCoefficientB, exponentB);
}

function ltSlow(int256 signedCoefficientA, int256 exponentA, int256 signedCoefficientB, int256 exponentB)
internal
pure
returns (bool)
{
// If the exponents are the same we compare the coefficients.
if (exponentA == exponentB) {
return signedCoefficientA < signedCoefficientB;
}

// Comparisons with zero ignore exponents.
if (signedCoefficientA == 0 || signedCoefficientB == 0) {
return signedCoefficientA < signedCoefficientB;
}

unchecked {
int256 tmp = 0;
while (exponentA > exponentB) {
tmp = signedCoefficientA * 10;
if (tmp / 10 != signedCoefficientA) {
// A overflowed so is huge in magnitude, it's gt everything
// if positive and lt everything if it's negative.
return signedCoefficientA < 0;
}
signedCoefficientA = tmp;
exponentA--;
}

while (exponentB > exponentA) {
tmp = signedCoefficientB * 10;
if (tmp / 10 != signedCoefficientB) {
// B overflowed so is huge in magnitude, it's gt everything
// if positive and lt everything if it's negative.
return signedCoefficientB > 0;
}
signedCoefficientB = tmp;
exponentB--;
}
}

return ltSlow(signedCoefficientA, exponentA, signedCoefficientB, exponentB);
}
}
Loading

0 comments on commit 998b2f7

Please sign in to comment.