diff --git a/.gas-snapshot b/.gas-snapshot index 0625b6aa..e3270c2a 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,147 +1,158 @@ -DecimalFloatAbsTest:testAbsDeployed(bytes32) (runs: 5109, μ: 2594522, ~: 2594465) -DecimalFloatAddTest:testAddDeployed(bytes32,bytes32) (runs: 5109, μ: 2598288, ~: 2598369) -DecimalFloatCeilTest:testCeilDeployed(bytes32) (runs: 5109, μ: 2594530, ~: 2594178) -DecimalFloatConstantsTest:testEDeployed() (gas: 2593708) -DecimalFloatConstantsTest:testMaxNegativeValueDeployed() (gas: 2593740) -DecimalFloatConstantsTest:testMaxPositiveValueDeployed() (gas: 2593698) -DecimalFloatConstantsTest:testMinNegativeValueDeployed() (gas: 2593673) -DecimalFloatConstantsTest:testMinPositiveValueDeployed() (gas: 2593652) -DecimalFloatDivTest:testDivDeployed(bytes32,bytes32) (runs: 5109, μ: 2596998, ~: 2596856) -DecimalFloatEqTest:testEqDeployed(bytes32,bytes32) (runs: 5109, μ: 2594908, ~: 2594833) -DecimalFloatFloorTest:testFloorDeployed(bytes32) (runs: 5109, μ: 2594361, ~: 2594176) -DecimalFloatFormatTest:testFormatDeployed(bytes32) (runs: 5109, μ: 2598514, ~: 2598341) -DecimalFloatFracTest:testFracDeployed(bytes32) (runs: 5109, μ: 2594752, ~: 2594736) -DecimalFloatFromFixedDecimalLosslessTest:testFromFixedDecimalLosslessDeployed(uint256,uint8) (runs: 5109, μ: 2595308, ~: 2595240) -DecimalFloatFromFixedDecimalLossyTest:testFromFixedDecimalLossyDeployed(uint256,uint8) (runs: 5109, μ: 2595793, ~: 2595710) -DecimalFloatGtTest:testGtDeployed(bytes32,bytes32) (runs: 5109, μ: 2594850, ~: 2594775) -DecimalFloatGteTest:testGteDeployed(bytes32,bytes32) (runs: 5109, μ: 2594836, ~: 2594761) -DecimalFloatInvTest:testInvDeployed(bytes32) (runs: 5109, μ: 2596086, ~: 2596016) -DecimalFloatIsZeroTest:testIsZeroDeployed(bytes32) (runs: 5109, μ: 2594018, ~: 2594018) -DecimalFloatLtTest:testLtDeployed(bytes32,bytes32) (runs: 5109, μ: 2594827, ~: 2594752) -DecimalFloatLteTest:testLteDeployed(bytes32,bytes32) (runs: 5109, μ: 2594880, ~: 2594805) -DecimalFloatMaxTest:testMaxDeployed(bytes32,bytes32) (runs: 5109, μ: 2594889, ~: 2594827) -DecimalFloatMinTest:testMinDeployed(bytes32,bytes32) (runs: 5109, μ: 2594909, ~: 2594847) -DecimalFloatMinusTest:testMinusDeployed(bytes32) (runs: 5109, μ: 2594623, ~: 2594623) -DecimalFloatMulTest:testMulDeployed(bytes32,bytes32) (runs: 5109, μ: 2596724, ~: 2597783) -DecimalFloatPackLosslessTest:testPackDeployed(int224,int32) (runs: 5109, μ: 158769, ~: 158769) -DecimalFloatParseTest:testParseDeployed(string) (runs: 5109, μ: 2597255, ~: 2597124) -DecimalFloatPowTest:testPowDeployed(bytes32,bytes32) (runs: 5109, μ: 2605572, ~: 2602856) -DecimalFloatSqrtTest:testSqrtDeployed(bytes32) (runs: 5109, μ: 2604890, ~: 2603570) -DecimalFloatSubTest:testSubDeployed(bytes32,bytes32) (runs: 5109, μ: 2598631, ~: 2598717) -DecimalFloatToFixedDecimalLosslessTest:testToFixedDecimalLosslessDeployed(bytes32,uint8) (runs: 5109, μ: 2595944, ~: 2595823) -DecimalFloatToFixedDecimalLossyTest:testToFixedDecimalLossyDeployed(bytes32,uint8) (runs: 5109, μ: 2596079, ~: 2596352) -LibDecimalFloatAbsTest:testAbsMinValue(int32) (runs: 5108, μ: 5121, ~: 5121) -LibDecimalFloatAbsTest:testAbsNegative(int256,int32) (runs: 5109, μ: 10475, ~: 10702) -LibDecimalFloatAbsTest:testAbsNonNegative(int256,int32) (runs: 5109, μ: 9641, ~: 9392) -LibDecimalFloatCeilTest:testCeilExamples() (gas: 28322) -LibDecimalFloatCeilTest:testCeilInRange(int224,int256) (runs: 5109, μ: 10988, ~: 10706) -LibDecimalFloatCeilTest:testCeilLessThanMin(int224,int256) (runs: 5109, μ: 10029, ~: 9813) -LibDecimalFloatCeilTest:testCeilNonNegative(int224,int256) (runs: 5109, μ: 8953, ~: 9205) -LibDecimalFloatCeilTest:testCeilNotReverts(bytes32) (runs: 5109, μ: 589, ~: 411) -LibDecimalFloatCeilTest:testCeilZero(int32) (runs: 5109, μ: 5438, ~: 5438) +DecimalFloatAbsTest:testAbsDeployed(bytes32) (runs: 5118, μ: 2585908, ~: 2585851) +DecimalFloatAddTest:testAddDeployed(bytes32,bytes32) (runs: 5118, μ: 2589963, ~: 2590047) +DecimalFloatCeilTest:testCeilDeployed(bytes32) (runs: 5118, μ: 2585935, ~: 2585564) +DecimalFloatConstantsTest:testEDeployed() (gas: 2585094) +DecimalFloatConstantsTest:testMaxNegativeValueDeployed() (gas: 2585126) +DecimalFloatConstantsTest:testMaxPositiveValueDeployed() (gas: 2585084) +DecimalFloatConstantsTest:testMinNegativeValueDeployed() (gas: 2585059) +DecimalFloatConstantsTest:testMinPositiveValueDeployed() (gas: 2585038) +DecimalFloatDivTest:testDivDeployed(bytes32,bytes32) (runs: 5118, μ: 2588385, ~: 2588242) +DecimalFloatEqTest:testEqDeployed(bytes32,bytes32) (runs: 5118, μ: 2586294, ~: 2586219) +DecimalFloatFloorTest:testFloorDeployed(bytes32) (runs: 5118, μ: 2585748, ~: 2585562) +DecimalFloatFormatTest:testFormatDeployed(bytes32) (runs: 5118, μ: 2589916, ~: 2589727) +DecimalFloatFracTest:testFracDeployed(bytes32) (runs: 5118, μ: 2586139, ~: 2586122) +DecimalFloatFromFixedDecimalLosslessTest:testFromFixedDecimalLosslessDeployed(uint256,uint8) (runs: 5118, μ: 2586692, ~: 2586626) +DecimalFloatFromFixedDecimalLossyTest:testFromFixedDecimalLossyDeployed(uint256,uint8) (runs: 5118, μ: 2587178, ~: 2587096) +DecimalFloatGtTest:testGtDeployed(bytes32,bytes32) (runs: 5118, μ: 2586236, ~: 2586161) +DecimalFloatGteTest:testGteDeployed(bytes32,bytes32) (runs: 5118, μ: 2586222, ~: 2586147) +DecimalFloatInvTest:testInvDeployed(bytes32) (runs: 5118, μ: 2587476, ~: 2587402) +DecimalFloatIsZeroTest:testIsZeroDeployed(bytes32) (runs: 5118, μ: 2585404, ~: 2585404) +DecimalFloatLtTest:testLtDeployed(bytes32,bytes32) (runs: 5118, μ: 2586213, ~: 2586138) +DecimalFloatLteTest:testLteDeployed(bytes32,bytes32) (runs: 5118, μ: 2586266, ~: 2586191) +DecimalFloatMaxTest:testMaxDeployed(bytes32,bytes32) (runs: 5118, μ: 2586274, ~: 2586213) +DecimalFloatMinTest:testMinDeployed(bytes32,bytes32) (runs: 5118, μ: 2586295, ~: 2586233) +DecimalFloatMinusTest:testMinusDeployed(bytes32) (runs: 5118, μ: 2586009, ~: 2586009) +DecimalFloatMulTest:testMulDeployed(bytes32,bytes32) (runs: 5118, μ: 2588107, ~: 2589169) +DecimalFloatPackLosslessTest:testPackDeployed(int224,int32) (runs: 5118, μ: 158769, ~: 158769) +DecimalFloatParseTest:testParseDeployed(string) (runs: 5118, μ: 2588641, ~: 2588510) +DecimalFloatPowTest:testPowDeployed(bytes32,bytes32) (runs: 5118, μ: 2597234, ~: 2594242) +DecimalFloatSqrtTest:testSqrtDeployed(bytes32) (runs: 5118, μ: 2596502, ~: 2594956) +DecimalFloatSubTest:testSubDeployed(bytes32,bytes32) (runs: 5118, μ: 2590308, ~: 2590347) +DecimalFloatToFixedDecimalLosslessTest:testToFixedDecimalLosslessDeployed(bytes32,uint8) (runs: 5118, μ: 2587325, ~: 2587209) +DecimalFloatToFixedDecimalLossyTest:testToFixedDecimalLossyDeployed(bytes32,uint8) (runs: 5118, μ: 2587473, ~: 2587738) +LibDecimalFloatAbsTest:testAbsMinValue(int32) (runs: 5117, μ: 5121, ~: 5121) +LibDecimalFloatAbsTest:testAbsNegative(int256,int32) (runs: 5118, μ: 10475, ~: 10702) +LibDecimalFloatAbsTest:testAbsNonNegative(int256,int32) (runs: 5118, μ: 9640, ~: 9392) +LibDecimalFloatCeilTest:testCeilExamples() (gas: 30794) +LibDecimalFloatCeilTest:testCeilInRange(int224,int256) (runs: 5118, μ: 11042, ~: 10713) +LibDecimalFloatCeilTest:testCeilLessThanMin(int224,int256) (runs: 5118, μ: 10060, ~: 9820) +LibDecimalFloatCeilTest:testCeilNonNegative(int224,int256) (runs: 5118, μ: 8961, ~: 9212) +LibDecimalFloatCeilTest:testCeilNotReverts(bytes32) (runs: 5118, μ: 598, ~: 411) +LibDecimalFloatCeilTest:testCeilZero(int32) (runs: 5118, μ: 5438, ~: 5438) LibDecimalFloatConstantsTest:testFloatE() (gas: 3357) LibDecimalFloatConstantsTest:testFloatHalf() (gas: 3336) LibDecimalFloatConstantsTest:testFloatMaxNegativeValue() (gas: 3379) -LibDecimalFloatConstantsTest:testFloatMaxNegativeValueIsMax(bytes32) (runs: 5109, μ: 4488, ~: 4594) +LibDecimalFloatConstantsTest:testFloatMaxNegativeValueIsMax(bytes32) (runs: 5118, μ: 4488, ~: 4594) LibDecimalFloatConstantsTest:testFloatMaxPositiveValue() (gas: 3335) -LibDecimalFloatConstantsTest:testFloatMaxPositiveValueIsMax(bytes32) (runs: 5109, μ: 3545, ~: 3586) +LibDecimalFloatConstantsTest:testFloatMaxPositiveValueIsMax(bytes32) (runs: 5118, μ: 3545, ~: 3586) LibDecimalFloatConstantsTest:testFloatMinNegativeValue() (gas: 3335) -LibDecimalFloatConstantsTest:testFloatMinNegativeValueIsMin(bytes32) (runs: 5109, μ: 3496, ~: 3457) +LibDecimalFloatConstantsTest:testFloatMinNegativeValueIsMin(bytes32) (runs: 5118, μ: 3496, ~: 3457) LibDecimalFloatConstantsTest:testFloatMinPositiveValue() (gas: 3357) -LibDecimalFloatConstantsTest:testFloatMinPositiveValueIsMin(bytes32) (runs: 5109, μ: 4938, ~: 4870) +LibDecimalFloatConstantsTest:testFloatMinPositiveValueIsMin(bytes32) (runs: 5118, μ: 4938, ~: 4870) LibDecimalFloatConstantsTest:testFloatOne() (gas: 3358) LibDecimalFloatConstantsTest:testFloatTwo() (gas: 3380) LibDecimalFloatConstantsTest:testFloatZero() (gas: 3337) -LibDecimalFloatDecimalAddTest:testAddPacked(bytes32,bytes32) (runs: 5109, μ: 9467, ~: 9568) -LibDecimalFloatDecimalLosslessTest:testFromFixedDecimalLosslessFail(uint256,uint8) (runs: 5104, μ: 9615, ~: 9663) -LibDecimalFloatDecimalLosslessTest:testFromFixedDecimalLosslessMem(uint256,uint8) (runs: 5109, μ: 8130, ~: 8048) -LibDecimalFloatDecimalLosslessTest:testFromFixedDecimalLosslessPass(uint256,uint8) (runs: 5109, μ: 7452, ~: 7424) +LibDecimalFloatDecimalAddTest:testAddPacked(bytes32,bytes32) (runs: 5118, μ: 9761, ~: 9832) +LibDecimalFloatDecimalLosslessTest:testFromFixedDecimalLosslessFail(uint256,uint8) (runs: 5113, μ: 9615, ~: 9663) +LibDecimalFloatDecimalLosslessTest:testFromFixedDecimalLosslessMem(uint256,uint8) (runs: 5118, μ: 8130, ~: 8048) +LibDecimalFloatDecimalLosslessTest:testFromFixedDecimalLosslessPass(uint256,uint8) (runs: 5118, μ: 7452, ~: 7424) LibDecimalFloatDecimalLosslessTest:testToFixedDecimalLosslessFail() (gas: 4894) -LibDecimalFloatDecimalLosslessTest:testToFixedDecimalLosslessPacked(bytes32,uint8) (runs: 5109, μ: 6719, ~: 6161) -LibDecimalFloatDecimalLosslessTest:testToFixedDecimalLosslessPass(int256,int256,uint8) (runs: 5109, μ: 15805, ~: 15768) -LibDecimalFloatDecimalTest:testFixedDecimalRoundTripLossless(uint256,uint8) (runs: 5109, μ: 9274, ~: 9053) +LibDecimalFloatDecimalLosslessTest:testToFixedDecimalLosslessPacked(bytes32,uint8) (runs: 5118, μ: 6719, ~: 6161) +LibDecimalFloatDecimalLosslessTest:testToFixedDecimalLosslessPass(int256,int256,uint8) (runs: 5118, μ: 15805, ~: 15768) +LibDecimalFloatDecimalTest:testFixedDecimalRoundTripLossless(uint256,uint8) (runs: 5118, μ: 9274, ~: 9053) LibDecimalFloatDecimalTest:testFromFixedDecimalLossyComplicated() (gas: 685958) LibDecimalFloatDecimalTest:testFromFixedDecimalLossyNormalizedMax() (gas: 673506) LibDecimalFloatDecimalTest:testFromFixedDecimalLossyNormalizedMaxPlusOne() (gas: 704362) LibDecimalFloatDecimalTest:testFromFixedDecimalLossyOne() (gas: 685936) LibDecimalFloatDecimalTest:testFromFixedDecimalLossyOneMillion() (gas: 685937) LibDecimalFloatDecimalTest:testFromFixedDecimalLossyOverflow() (gas: 715261) -LibDecimalFloatDecimalTest:testFromFixedDecimalLossyPacked(uint256,uint8) (runs: 5109, μ: 9460, ~: 9374) -LibDecimalFloatDecimalTest:testFromFixedDecimalLossyTruncateOne(uint256,uint8) (runs: 5109, μ: 5978, ~: 5937) -LibDecimalFloatDecimalTest:testFromFixedDecimalLossyTruncateZero(uint256,uint8) (runs: 5109, μ: 7306, ~: 5860) -LibDecimalFloatDecimalTest:testToFixedDecimalLosslessScaleUp(int256,int256,uint8) (runs: 5101, μ: 16005, ~: 15996) -LibDecimalFloatDecimalTest:testToFixedDecimalLossyExponentOverflow(int256,int256,uint8) (runs: 5109, μ: 14964, ~: 14729) -LibDecimalFloatDecimalTest:testToFixedDecimalLossyIdentity(int256,uint8) (runs: 5109, μ: 10151, ~: 9811) -LibDecimalFloatDecimalTest:testToFixedDecimalLossyNegative(int256,int256,uint8) (runs: 5109, μ: 10825, ~: 11076) -LibDecimalFloatDecimalTest:testToFixedDecimalLossyPacked(bytes32,uint8) (runs: 5109, μ: 6805, ~: 6905) -LibDecimalFloatDecimalTest:testToFixedDecimalLossyScaleUpOverflow(int256,int256,uint8) (runs: 5104, μ: 15348, ~: 15612) -LibDecimalFloatDecimalTest:testToFixedDecimalLossyTruncate(int256,int256,uint8) (runs: 5109, μ: 14493, ~: 14212) +LibDecimalFloatDecimalTest:testFromFixedDecimalLossyPacked(uint256,uint8) (runs: 5118, μ: 9460, ~: 9374) +LibDecimalFloatDecimalTest:testFromFixedDecimalLossyTruncateOne(uint256,uint8) (runs: 5118, μ: 5978, ~: 5937) +LibDecimalFloatDecimalTest:testFromFixedDecimalLossyTruncateZero(uint256,uint8) (runs: 5118, μ: 7307, ~: 5860) +LibDecimalFloatDecimalTest:testToFixedDecimalLosslessScaleUp(int256,int256,uint8) (runs: 5108, μ: 16005, ~: 15996) +LibDecimalFloatDecimalTest:testToFixedDecimalLossyExponentOverflow(int256,int256,uint8) (runs: 5118, μ: 14963, ~: 14729) +LibDecimalFloatDecimalTest:testToFixedDecimalLossyIdentity(int256,uint8) (runs: 5118, μ: 10151, ~: 9811) +LibDecimalFloatDecimalTest:testToFixedDecimalLossyNegative(int256,int256,uint8) (runs: 5118, μ: 10825, ~: 11076) +LibDecimalFloatDecimalTest:testToFixedDecimalLossyPacked(bytes32,uint8) (runs: 5118, μ: 6805, ~: 6905) +LibDecimalFloatDecimalTest:testToFixedDecimalLossyScaleUpOverflow(int256,int256,uint8) (runs: 5106, μ: 15348, ~: 15612) +LibDecimalFloatDecimalTest:testToFixedDecimalLossyTruncate(int256,int256,uint8) (runs: 5118, μ: 14493, ~: 14212) LibDecimalFloatDecimalTest:testToFixedDecimalLossyTruncateLossless() (gas: 14523) -LibDecimalFloatDecimalTest:testToFixedDecimalLossyUnderflow(int256,int256,uint8) (runs: 5109, μ: 13739, ~: 13602) -LibDecimalFloatDecimalTest:testToFixedDecimalLossyZero(int256,uint8) (runs: 5109, μ: 4598, ~: 4598) -LibDecimalFloatDivTest:testDivPacked(bytes32,bytes32) (runs: 5109, μ: 8052, ~: 7855) -LibDecimalFloatEqTest:testEqPacked(bytes32,bytes32) (runs: 5109, μ: 5524, ~: 5450) -LibDecimalFloatEqTest:testEqXNotYExponents(bytes32,bytes32) (runs: 5109, μ: 4341, ~: 4234) -LibDecimalFloatEqTest:testEqZero(int32) (runs: 5109, μ: 5133, ~: 5133) +LibDecimalFloatDecimalTest:testToFixedDecimalLossyUnderflow(int256,int256,uint8) (runs: 5118, μ: 13739, ~: 13602) +LibDecimalFloatDecimalTest:testToFixedDecimalLossyZero(int256,uint8) (runs: 5118, μ: 4598, ~: 4598) +LibDecimalFloatDivTest:testDivPacked(bytes32,bytes32) (runs: 5118, μ: 8053, ~: 7855) +LibDecimalFloatEqTest:testEqPacked(bytes32,bytes32) (runs: 5118, μ: 5524, ~: 5450) +LibDecimalFloatEqTest:testEqXNotYExponents(bytes32,bytes32) (runs: 5118, μ: 4341, ~: 4234) +LibDecimalFloatEqTest:testEqZero(int32) (runs: 5118, μ: 5133, ~: 5133) LibDecimalFloatFloorTest:testFloorExamples() (gas: 38387) LibDecimalFloatFloorTest:testFloorGas0() (gas: 960) LibDecimalFloatFloorTest:testFloorGasTiny() (gas: 881) LibDecimalFloatFloorTest:testFloorGasZero() (gas: 553) -LibDecimalFloatFloorTest:testFloorInRange(int224,int256) (runs: 5109, μ: 11032, ~: 11044) -LibDecimalFloatFloorTest:testFloorLessThanMin(int224,int256) (runs: 5109, μ: 10284, ~: 10293) -LibDecimalFloatFloorTest:testFloorNonNegative(int224,int256) (runs: 5109, μ: 9547, ~: 9806) -LibDecimalFloatFloorTest:testFloorNotReverts(bytes32) (runs: 5109, μ: 461, ~: 365) +LibDecimalFloatFloorTest:testFloorInRange(int224,int256) (runs: 5118, μ: 11032, ~: 11044) +LibDecimalFloatFloorTest:testFloorLessThanMin(int224,int256) (runs: 5118, μ: 10284, ~: 10293) +LibDecimalFloatFloorTest:testFloorNonNegative(int224,int256) (runs: 5118, μ: 9546, ~: 9806) +LibDecimalFloatFloorTest:testFloorNotReverts(bytes32) (runs: 5118, μ: 461, ~: 365) LibDecimalFloatFracTest:testFracExamples() (gas: 39135) LibDecimalFloatFracTest:testFracGas0() (gas: 960) LibDecimalFloatFracTest:testFracGasTiny() (gas: 836) LibDecimalFloatFracTest:testFracGasZero() (gas: 820) -LibDecimalFloatFracTest:testFracInRange(int224,int256) (runs: 5109, μ: 10847, ~: 10859) -LibDecimalFloatFracTest:testFracLessThanMin(int224,int256) (runs: 5109, μ: 10273, ~: 10280) -LibDecimalFloatFracTest:testFracNonNegative(int224,int256) (runs: 5109, μ: 9806, ~: 10066) -LibDecimalFloatFracTest:testFracNotReverts(bytes32) (runs: 5109, μ: 630, ~: 621) +LibDecimalFloatFracTest:testFracInRange(int224,int256) (runs: 5118, μ: 10847, ~: 10859) +LibDecimalFloatFracTest:testFracLessThanMin(int224,int256) (runs: 5118, μ: 10272, ~: 10280) +LibDecimalFloatFracTest:testFracNonNegative(int224,int256) (runs: 5118, μ: 9805, ~: 10066) +LibDecimalFloatFracTest:testFracNotReverts(bytes32) (runs: 5118, μ: 630, ~: 621) LibDecimalFloatGtTest:testGtGasAZero() (gas: 973) LibDecimalFloatGtTest:testGtGasBZero() (gas: 973) LibDecimalFloatGtTest:testGtGasBothZero() (gas: 751) LibDecimalFloatGtTest:testGtGasDifferentSigns() (gas: 974) LibDecimalFloatGtTest:testGtGasExponentDiffOverflow() (gas: 1143) -LibDecimalFloatGtTest:testGtOneEAny(bytes32) (runs: 5109, μ: 3494, ~: 3494) -LibDecimalFloatGtTest:testGtReference(int224,int32,int224,int32) (runs: 5109, μ: 8064, ~: 6272) -LibDecimalFloatGtTest:testGtX(int224,int32) (runs: 5109, μ: 3882, ~: 3882) -LibDecimalFloatGtTest:testGtXEAnyVsXEAny(int256,int32,int32) (runs: 5109, μ: 10593, ~: 10332) -LibDecimalFloatGtTest:testGtXEAnyVsXEAnyNegative(int256,int32,int32) (runs: 5109, μ: 11144, ~: 11349) -LibDecimalFloatGtTest:testGtXNotY(bytes32,bytes32) (runs: 5109, μ: 4341, ~: 4232) -LibDecimalFloatGtTest:testGtXPositiveYNegative(int256,int32,int256,int32) (runs: 5109, μ: 13764, ~: 13595) -LibDecimalFloatGtTest:testGtXPositiveYZero(int256,int32,int32) (runs: 5109, μ: 10274, ~: 10026) -LibDecimalFloatGtTest:testGtZero(int32,int32) (runs: 5109, μ: 4793, ~: 4793) +LibDecimalFloatGtTest:testGtOneEAny(bytes32) (runs: 5118, μ: 3494, ~: 3494) +LibDecimalFloatGtTest:testGtReference(int224,int32,int224,int32) (runs: 5118, μ: 8062, ~: 6272) +LibDecimalFloatGtTest:testGtX(int224,int32) (runs: 5118, μ: 3882, ~: 3882) +LibDecimalFloatGtTest:testGtXEAnyVsXEAny(int256,int32,int32) (runs: 5118, μ: 10592, ~: 10332) +LibDecimalFloatGtTest:testGtXEAnyVsXEAnyNegative(int256,int32,int32) (runs: 5118, μ: 11144, ~: 11349) +LibDecimalFloatGtTest:testGtXNotY(bytes32,bytes32) (runs: 5118, μ: 4341, ~: 4232) +LibDecimalFloatGtTest:testGtXPositiveYNegative(int256,int32,int256,int32) (runs: 5118, μ: 13764, ~: 13595) +LibDecimalFloatGtTest:testGtXPositiveYZero(int256,int32,int32) (runs: 5118, μ: 10273, ~: 10026) +LibDecimalFloatGtTest:testGtZero(int32,int32) (runs: 5118, μ: 4793, ~: 4793) LibDecimalFloatGteTest:testGteGasAZero() (gas: 976) LibDecimalFloatGteTest:testGteGasBZero() (gas: 1020) LibDecimalFloatGteTest:testGteGasBothZero() (gas: 753) LibDecimalFloatGteTest:testGteGasDifferentSigns() (gas: 996) LibDecimalFloatGteTest:testGteGasExponentDiffOverflow() (gas: 1102) -LibDecimalFloatGteTest:testGteOneEAny(bytes32) (runs: 5109, μ: 3494, ~: 3494) -LibDecimalFloatGteTest:testGteReference(int224,int32,int224,int32) (runs: 5109, μ: 8114, ~: 6344) -LibDecimalFloatGteTest:testGteX(int224,int32) (runs: 5109, μ: 3925, ~: 3925) -LibDecimalFloatGteTest:testGteXEAnyVsXEAny(int256,int32,int32) (runs: 5109, μ: 10622, ~: 10364) -LibDecimalFloatGteTest:testGteXEAnyVsXEAnyNegative(int256,int32,int32) (runs: 5109, μ: 11156, ~: 11361) -LibDecimalFloatGteTest:testGteXNotLtY(bytes32,bytes32) (runs: 5109, μ: 3947, ~: 3873) -LibDecimalFloatGteTest:testGteXPositiveYNegative(int256,int32,int256,int32) (runs: 5109, μ: 13794, ~: 13623) -LibDecimalFloatGteTest:testGteXPositiveYZero(int256,int32,int32) (runs: 5109, μ: 9551, ~: 9170) -LibDecimalFloatGteTest:testGteZero(int32,int32) (runs: 5109, μ: 4838, ~: 4838) -LibDecimalFloatImplementationAddTest:testAdd123456789987654321() (gas: 4602) -LibDecimalFloatImplementationAddTest:testAdd123456789e9987654321() (gas: 4654) -LibDecimalFloatImplementationAddTest:testAddNeverRevert(int256,int256,int256,int256) (runs: 5109, μ: 13048, ~: 12978) -LibDecimalFloatImplementationAddTest:testAddOneOneNotMaximized() (gas: 5985) -LibDecimalFloatImplementationAddTest:testAddOneOnePreMaximized() (gas: 4129) -LibDecimalFloatImplementationAddTest:testAddOneZero() (gas: 3666) -LibDecimalFloatImplementationAddTest:testAddSameExponentSameCoefficient(int256,int256) (runs: 5109, μ: 6265, ~: 6334) +LibDecimalFloatGteTest:testGteOneEAny(bytes32) (runs: 5118, μ: 3494, ~: 3494) +LibDecimalFloatGteTest:testGteReference(int224,int32,int224,int32) (runs: 5118, μ: 8112, ~: 6318) +LibDecimalFloatGteTest:testGteX(int224,int32) (runs: 5118, μ: 3925, ~: 3925) +LibDecimalFloatGteTest:testGteXEAnyVsXEAny(int256,int32,int32) (runs: 5118, μ: 10621, ~: 10364) +LibDecimalFloatGteTest:testGteXEAnyVsXEAnyNegative(int256,int32,int32) (runs: 5118, μ: 11157, ~: 11361) +LibDecimalFloatGteTest:testGteXNotLtY(bytes32,bytes32) (runs: 5118, μ: 3947, ~: 3873) +LibDecimalFloatGteTest:testGteXPositiveYNegative(int256,int32,int256,int32) (runs: 5118, μ: 13794, ~: 13623) +LibDecimalFloatGteTest:testGteXPositiveYZero(int256,int32,int32) (runs: 5118, μ: 9550, ~: 9170) +LibDecimalFloatGteTest:testGteZero(int32,int32) (runs: 5118, μ: 4838, ~: 4838) +LibDecimalFloatImplementationAddTest:testAdd123456789987654321() (gas: 4811) +LibDecimalFloatImplementationAddTest:testAdd123456789e9987654321() (gas: 4795) +LibDecimalFloatImplementationAddTest:testAddNeverRevert(int256,int256,int256,int256) (runs: 5118, μ: 13126, ~: 13053) +LibDecimalFloatImplementationAddTest:testAddOneOneNotMaximized() (gas: 6148) +LibDecimalFloatImplementationAddTest:testAddOneOnePreMaximized() (gas: 4235) +LibDecimalFloatImplementationAddTest:testAddOneZero() (gas: 3688) +LibDecimalFloatImplementationAddTest:testAddSameExponent(int256,int256) (runs: 5112, μ: 6890, ~: 6957) LibDecimalFloatImplementationAddTest:testAddZero() (gas: 3687) -LibDecimalFloatImplementationAddTest:testAddZeroAnyExponent(int128) (runs: 5109, μ: 9294, ~: 9271) -LibDecimalFloatImplementationAddTest:testAddZeroOne() (gas: 3664) -LibDecimalFloatImplementationAddTest:testAddZeroToAnyNonZero(int256,int256,int256) (runs: 5108, μ: 13985, ~: 13961) -LibDecimalFloatImplementationAddTest:testAddingSmallToLargeReturnsLargeExamples() (gas: 71367) -LibDecimalFloatImplementationAddTest:testAddingSmallToLargeReturnsLargeFuzz(int256,int256,int256,int256) (runs: 5099, μ: 16839, ~: 16821) -LibDecimalFloatImplementationAddTest:testGasAddOne() (gas: 1179) -LibDecimalFloatImplementationAddTest:testGasAddZero() (gas: 360) +LibDecimalFloatImplementationAddTest:testAddZeroAnyExponent(int128) (runs: 5118, μ: 9292, ~: 9271) +LibDecimalFloatImplementationAddTest:testAddZeroOne() (gas: 3686) +LibDecimalFloatImplementationAddTest:testAddZeroToAnyNonZero(int256,int256,int256) (runs: 5117, μ: 13996, ~: 13970) +LibDecimalFloatImplementationAddTest:testAddingSmallToLargeReturnsLargeExamples() (gas: 92108) +LibDecimalFloatImplementationAddTest:testAddingSmallToLargeReturnsLargeFuzz(int256,int256,int256,int256) (runs: 5101, μ: 17007, ~: 16985) +LibDecimalFloatImplementationAddTest:testGasAddOne() (gas: 1364) +LibDecimalFloatImplementationAddTest:testGasAddZero() (gas: 382) +--- a/test/src/lib/implementation/LibDecimalFloatImplementation.add.t.sol +@@ -31,10 +31,10 @@ + } + +- function testOverflowCheks(int256 a, int256 b) external pure { ++ function testOverflowChecks(int256 a, int256 b) external pure { + bool expected = willOverflow(a, b); + bool actual = willOverflow2(a, b); + assertEq(expected, actual); + } +LibDecimalFloatImplementationCharacteristicMantissaTest:testCharacteristicMantissaExamples() (gas: 7754) LibDecimalFloatImplementationDivTest:testDiv1Over3() (gas: 6014) LibDecimalFloatImplementationDivTest:testDiv1Over3Gas0() (gas: 716) LibDecimalFloatImplementationDivTest:testDiv1Over3Gas10() (gas: 6907) @@ -151,125 +162,125 @@ LibDecimalFloatImplementationDivTest:testDivNegative1Over3() (gas: 6074) LibDecimalFloatImplementationDivTest:testDivOOMs5and2() (gas: 4848) LibDecimalFloatImplementationDivTest:testDivOOMsOverTen() (gas: 5665) LibDecimalFloatImplementationDivTest:testDivTenOverOOMs() (gas: 5590) -LibDecimalFloatImplementationDivTest:testUnnormalizedThreesDiv0(int256,int256) (runs: 113, μ: 21050750, ~: 21050370) +LibDecimalFloatImplementationDivTest:testUnnormalizedThreesDiv0(int256,int256) (runs: 122, μ: 21050720, ~: 21050370) LibDecimalFloatImplementationEqTest:testEqGasAZero() (gas: 430) LibDecimalFloatImplementationEqTest:testEqGasBZero() (gas: 473) LibDecimalFloatImplementationEqTest:testEqGasBothZero() (gas: 450) LibDecimalFloatImplementationEqTest:testEqGasDifferentSigns() (gas: 482) LibDecimalFloatImplementationEqTest:testEqGasExponentDiffOverflow() (gas: 533) -LibDecimalFloatImplementationEqTest:testEqNotReverts(int256,int256,int256,int256) (runs: 5109, μ: 654, ~: 679) -LibDecimalFloatImplementationEqTest:testEqOneEAny(int256,int256) (runs: 5109, μ: 3416, ~: 3416) -LibDecimalFloatImplementationEqTest:testEqReference(int256,int256,int256,int256) (runs: 5109, μ: 9901, ~: 11437) -LibDecimalFloatImplementationEqTest:testEqX(int256) (runs: 5109, μ: 3392, ~: 3392) -LibDecimalFloatImplementationEqTest:testEqXEAnyVsXEAny(int256,int256,int256) (runs: 5107, μ: 4718, ~: 4714) -LibDecimalFloatImplementationEqTest:testEqXEqY(int256,int256,int256,int256) (runs: 5109, μ: 732, ~: 753) -LibDecimalFloatImplementationEqTest:testEqXNotY(int256,int256,int256,int256) (runs: 5109, μ: 3928, ~: 3953) -LibDecimalFloatImplementationEqTest:testEqZero(int256,int256) (runs: 5109, μ: 3440, ~: 3440) +LibDecimalFloatImplementationEqTest:testEqNotReverts(int256,int256,int256,int256) (runs: 5118, μ: 654, ~: 679) +LibDecimalFloatImplementationEqTest:testEqOneEAny(int256,int256) (runs: 5118, μ: 3416, ~: 3416) +LibDecimalFloatImplementationEqTest:testEqReference(int256,int256,int256,int256) (runs: 5118, μ: 9903, ~: 11446) +LibDecimalFloatImplementationEqTest:testEqX(int256) (runs: 5118, μ: 3392, ~: 3392) +LibDecimalFloatImplementationEqTest:testEqXEAnyVsXEAny(int256,int256,int256) (runs: 5116, μ: 4718, ~: 4714) +LibDecimalFloatImplementationEqTest:testEqXEqY(int256,int256,int256,int256) (runs: 5118, μ: 732, ~: 753) +LibDecimalFloatImplementationEqTest:testEqXNotY(int256,int256,int256,int256) (runs: 5118, μ: 3928, ~: 3953) +LibDecimalFloatImplementationEqTest:testEqZero(int256,int256) (runs: 5118, μ: 3440, ~: 3440) LibDecimalFloatImplementationInvTest:testInvGas0() (gas: 734) -LibDecimalFloatImplementationInvTest:testInvReference(int256,int256) (runs: 5107, μ: 12225, ~: 12163) +LibDecimalFloatImplementationInvTest:testInvReference(int256,int256) (runs: 5116, μ: 12225, ~: 12163) LibDecimalFloatImplementationInvTest:testInvSlowGas0() (gas: 755) LibDecimalFloatImplementationLog10Test:testExactLogs() (gas: 1263178) -LibDecimalFloatImplementationLog10Test:testExactLookupsLog10() (gas: 1279384) -LibDecimalFloatImplementationLog10Test:testInterpolatedLookups() (gas: 1259927) -LibDecimalFloatImplementationLog10Test:testSub1() (gas: 1256123) -LibDecimalFloatImplementationMaximizeTest:testMaximized(int256,int256) (runs: 5109, μ: 9488, ~: 9443) -LibDecimalFloatImplementationMaximizeTest:testMaximizedExamples() (gas: 157696) -LibDecimalFloatImplementationMaximizeTest:testMaximizedIdempotent(int256,int256) (runs: 5109, μ: 9794, ~: 9748) -LibDecimalFloatImplementationMinusTest:testMinusIsSubZero(int256,int256,int256) (runs: 5109, μ: 12951, ~: 12929) +LibDecimalFloatImplementationLog10Test:testExactLookupsLog10() (gas: 1280250) +LibDecimalFloatImplementationLog10Test:testInterpolatedLookups() (gas: 1260903) +LibDecimalFloatImplementationLog10Test:testSub1() (gas: 1256480) +LibDecimalFloatImplementationMaximizeTest:testMaximizedEverything(int256,int256) (runs: 5118, μ: 9478, ~: 9455) +LibDecimalFloatImplementationMaximizeTest:testMaximizedExamples() (gas: 165819) +LibDecimalFloatImplementationMaximizeTest:testMaximizedIdempotent(int256,int256) (runs: 5118, μ: 9903, ~: 9868) +LibDecimalFloatImplementationMinusTest:testMinusIsSubZero(int256,int256,int256) (runs: 5118, μ: 12950, ~: 12929) LibDecimalFloatImplementationMulTest:testMul123456789987654321() (gas: 3676) -LibDecimalFloatImplementationMulTest:testMul123456789987654321WithExponents(int128,int128) (runs: 5109, μ: 13185, ~: 13270) +LibDecimalFloatImplementationMulTest:testMul123456789987654321WithExponents(int128,int128) (runs: 5118, μ: 13186, ~: 13270) LibDecimalFloatImplementationMulTest:testMul1e181e19() (gas: 3720) LibDecimalFloatImplementationMulTest:testMulGasOne() (gas: 382) LibDecimalFloatImplementationMulTest:testMulGasZero() (gas: 324) -LibDecimalFloatImplementationMulTest:testMulNotRevertAnyExpectation(int256,int256,int256,int256) (runs: 5109, μ: 13394, ~: 12563) +LibDecimalFloatImplementationMulTest:testMulNotRevertAnyExpectation(int256,int256,int256,int256) (runs: 5118, μ: 13394, ~: 12563) LibDecimalFloatImplementationMulTest:testMulOneOne() (gas: 3721) LibDecimalFloatImplementationMulTest:testMulOneZero() (gas: 3663) LibDecimalFloatImplementationMulTest:testMulZero0Exponent() (gas: 3620) -LibDecimalFloatImplementationMulTest:testMulZeroAnyExponent(int64,int64) (runs: 5109, μ: 3908, ~: 3908) +LibDecimalFloatImplementationMulTest:testMulZeroAnyExponent(int64,int64) (runs: 5118, μ: 3908, ~: 3908) LibDecimalFloatImplementationMulTest:testMulZeroOne() (gas: 3642) LibDecimalFloatImplementationNormalizeTest:testExamples() (gas: 160899) -LibDecimalFloatImplementationNormalizeTest:testIdempotent(int256,int256) (runs: 5109, μ: 9875, ~: 9808) -LibDecimalFloatImplementationNormalizeTest:testIsNormalizedReference(int256,int256) (runs: 5109, μ: 3533, ~: 3539) -LibDecimalFloatImplementationNormalizeTest:testNormalized(int256,int256) (runs: 5109, μ: 9415, ~: 9348) +LibDecimalFloatImplementationNormalizeTest:testIdempotent(int256,int256) (runs: 5118, μ: 9875, ~: 9808) +LibDecimalFloatImplementationNormalizeTest:testIsNormalizedReference(int256,int256) (runs: 5118, μ: 3533, ~: 3539) +LibDecimalFloatImplementationNormalizeTest:testNormalized(int256,int256) (runs: 5118, μ: 9415, ~: 9348) LibDecimalFloatImplementationPow10Test:testExactLookups() (gas: 1281984) LibDecimalFloatImplementationPow10Test:testExactPows() (gas: 1260129) -LibDecimalFloatImplementationPow10Test:testInterpolatedLookupsPower() (gas: 1282922) -LibDecimalFloatImplementationPow10Test:testNoRevert(int224,int32) (runs: 5103, μ: 1258761, ~: 1259054) -LibDecimalFloatImplementationSubTest:testSubIsAdd(int256,int256,int256,int256) (runs: 5109, μ: 15665, ~: 15684) -LibDecimalFloatImplementationSubTest:testSubMinSignedValue(int256,int256,int256) (runs: 5109, μ: 14792, ~: 14735) -LibDecimalFloatImplementationSubTest:testSubOneFromMax() (gas: 6435) -LibDecimalFloatImplementationSubTest:testSubSelf(int224,int32) (runs: 5109, μ: 5346, ~: 5449) +LibDecimalFloatImplementationPow10Test:testInterpolatedLookupsPower() (gas: 1285018) +LibDecimalFloatImplementationPow10Test:testNoRevert(int224,int32) (runs: 5108, μ: 1259163, ~: 1259241) +LibDecimalFloatImplementationSubTest:testSubIsAdd(int256,int256,int256,int256) (runs: 5118, μ: 15800, ~: 15832) +LibDecimalFloatImplementationSubTest:testSubMinSignedValue(int256,int256,int256) (runs: 5118, μ: 14990, ~: 14932) +LibDecimalFloatImplementationSubTest:testSubOneFromMax() (gas: 6517) +LibDecimalFloatImplementationSubTest:testSubSelf(int224,int32) (runs: 5118, μ: 5509, ~: 5620) LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentExamples() (gas: 13429) -LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentLargerExponentOverflowRescaleRevert(int256,int256,int256) (runs: 5101, μ: 14426, ~: 14395) -LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentLargerExponentVeryLargeDiffRevert(int256,int256,int256) (runs: 5109, μ: 13307, ~: 13527) -LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentLargerTargetExponentNoRevert(int256,int256,int256) (runs: 5109, μ: 11668, ~: 11718) -LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentSameExponentNoop(int256,int256) (runs: 5109, μ: 3676, ~: 3676) -LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentSmallerExponentNoRevert(int256,int256,int256) (runs: 5104, μ: 13874, ~: 13665) -LibDecimalFloatInvTest:testInvMem(bytes32) (runs: 5109, μ: 7321, ~: 7246) -LibDecimalFloatIsZeroTest:testIsZeroDeployed(bytes32) (runs: 5109, μ: 3899, ~: 3899) -LibDecimalFloatIsZeroTest:testIsZeroEqZero(bytes32) (runs: 5109, μ: 3527, ~: 3527) -LibDecimalFloatIsZeroTest:testIsZeroExamples(int32) (runs: 5109, μ: 4477, ~: 4477) -LibDecimalFloatIsZeroTest:testNotIsZero(int224,int32) (runs: 5107, μ: 3896, ~: 3896) -LibDecimalFloatLog10Test:testLog10Packed(bytes32) (runs: 5109, μ: 1650376, ~: 1269941) +LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentLargerExponentOverflowRescaleRevert(int256,int256,int256) (runs: 5104, μ: 14426, ~: 14395) +LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentLargerExponentVeryLargeDiffRevert(int256,int256,int256) (runs: 5118, μ: 13307, ~: 13527) +LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentLargerTargetExponentNoRevert(int256,int256,int256) (runs: 5118, μ: 11668, ~: 11718) +LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentSameExponentNoop(int256,int256) (runs: 5118, μ: 3676, ~: 3676) +LibDecimalFloatImplementationWithTargetExponentTest:testWithTargetExponentSmallerExponentNoRevert(int256,int256,int256) (runs: 5110, μ: 13874, ~: 13665) +LibDecimalFloatInvTest:testInvMem(bytes32) (runs: 5118, μ: 7321, ~: 7246) +LibDecimalFloatIsZeroTest:testIsZeroDeployed(bytes32) (runs: 5118, μ: 3899, ~: 3899) +LibDecimalFloatIsZeroTest:testIsZeroEqZero(bytes32) (runs: 5118, μ: 3527, ~: 3527) +LibDecimalFloatIsZeroTest:testIsZeroExamples(int32) (runs: 5118, μ: 4477, ~: 4477) +LibDecimalFloatIsZeroTest:testNotIsZero(int224,int32) (runs: 5116, μ: 3896, ~: 3896) +LibDecimalFloatLog10Test:testLog10Packed(bytes32) (runs: 5118, μ: 1651432, ~: 1271847) LibDecimalFloatLtTest:testLtExamples() (gas: 3994) LibDecimalFloatLtTest:testLtGasAZero() (gas: 946) LibDecimalFloatLtTest:testLtGasBZero() (gas: 1012) LibDecimalFloatLtTest:testLtGasBothZero() (gas: 969) LibDecimalFloatLtTest:testLtGasDifferentSigns() (gas: 969) LibDecimalFloatLtTest:testLtGasExponentDiffOverflow() (gas: 1053) -LibDecimalFloatLtTest:testLtNegativeVsPositive(int256,int32,int256,int32) (runs: 5109, μ: 13749, ~: 13593) -LibDecimalFloatLtTest:testLtNegativeVsZero(int256,int32,int32) (runs: 5109, μ: 10790, ~: 11008) -LibDecimalFloatLtTest:testLtOneEAny(int224,int32) (runs: 5109, μ: 3905, ~: 3905) -LibDecimalFloatLtTest:testLtReference(bytes32,bytes32) (runs: 5109, μ: 4697, ~: 4998) -LibDecimalFloatLtTest:testLtVsEqualVsGt(bytes32,bytes32) (runs: 5109, μ: 4323, ~: 4210) -LibDecimalFloatLtTest:testLtX(int224) (runs: 5109, μ: 3798, ~: 3798) -LibDecimalFloatLtTest:testLtXEAnyVsXEAny(int256,int32,int32) (runs: 5109, μ: 10558, ~: 10297) -LibDecimalFloatLtTest:testLtXEAnyVsXEAnyNegative(int256,int32,int32) (runs: 5109, μ: 11153, ~: 11359) -LibDecimalFloatLtTest:testLtZero(int32,int32) (runs: 5109, μ: 4171, ~: 4171) +LibDecimalFloatLtTest:testLtNegativeVsPositive(int256,int32,int256,int32) (runs: 5118, μ: 13749, ~: 13593) +LibDecimalFloatLtTest:testLtNegativeVsZero(int256,int32,int32) (runs: 5118, μ: 10790, ~: 11008) +LibDecimalFloatLtTest:testLtOneEAny(int224,int32) (runs: 5118, μ: 3905, ~: 3905) +LibDecimalFloatLtTest:testLtReference(bytes32,bytes32) (runs: 5118, μ: 4696, ~: 4998) +LibDecimalFloatLtTest:testLtVsEqualVsGt(bytes32,bytes32) (runs: 5118, μ: 4323, ~: 4210) +LibDecimalFloatLtTest:testLtX(int224) (runs: 5118, μ: 3798, ~: 3798) +LibDecimalFloatLtTest:testLtXEAnyVsXEAny(int256,int32,int32) (runs: 5118, μ: 10557, ~: 10297) +LibDecimalFloatLtTest:testLtXEAnyVsXEAnyNegative(int256,int32,int32) (runs: 5118, μ: 11154, ~: 11359) +LibDecimalFloatLtTest:testLtZero(int32,int32) (runs: 5118, μ: 4171, ~: 4171) LibDecimalFloatLteTest:testLteGasAZero() (gas: 997) LibDecimalFloatLteTest:testLteGasBZero() (gas: 999) LibDecimalFloatLteTest:testLteGasBothZero() (gas: 753) LibDecimalFloatLteTest:testLteGasDifferentSigns() (gas: 976) LibDecimalFloatLteTest:testLteGasExponentDiffOverflow() (gas: 1082) -LibDecimalFloatLteTest:testLteOneEAny(bytes32) (runs: 5109, μ: 3493, ~: 3493) -LibDecimalFloatLteTest:testLteReference(int224,int32,int224,int32) (runs: 5109, μ: 8109, ~: 6315) -LibDecimalFloatLteTest:testLteX(int224,int32) (runs: 5109, μ: 3904, ~: 3904) -LibDecimalFloatLteTest:testLteXEAnyVsXEAny(int256,int32,int32) (runs: 5109, μ: 10583, ~: 10321) -LibDecimalFloatLteTest:testLteXEAnyVsXEAnyNegative(int256,int32,int32) (runs: 5109, μ: 11177, ~: 11383) -LibDecimalFloatLteTest:testLteXNotLtY(bytes32,bytes32) (runs: 5109, μ: 3882, ~: 3807) -LibDecimalFloatLteTest:testLteXPositiveYNegative(int256,int32,int256,int32) (runs: 5109, μ: 13103, ~: 12931) -LibDecimalFloatLteTest:testLteXPositiveYZero(int256,int32,int32) (runs: 5109, μ: 9575, ~: 9191) -LibDecimalFloatLteTest:testLteZero(int32,int32) (runs: 5109, μ: 4816, ~: 4816) -LibDecimalFloatMaxTest:testMaxX(bytes32) (runs: 5109, μ: 4246, ~: 4246) -LibDecimalFloatMaxTest:testMaxXY(bytes32,bytes32) (runs: 5109, μ: 4689, ~: 4613) -LibDecimalFloatMaxTest:testMaxXYEqual(bytes32) (runs: 5109, μ: 5272, ~: 5272) -LibDecimalFloatMaxTest:testMaxXYGreater(bytes32,bytes32) (runs: 5104, μ: 6129, ~: 6016) -LibDecimalFloatMaxTest:testMaxXYLess(bytes32,bytes32) (runs: 5101, μ: 6141, ~: 6027) -LibDecimalFloatMinTest:testMinX(bytes32) (runs: 5109, μ: 4268, ~: 4268) -LibDecimalFloatMinTest:testMinXY(bytes32,bytes32) (runs: 5109, μ: 4689, ~: 4613) -LibDecimalFloatMinTest:testMinXYEqual(bytes32) (runs: 5109, μ: 5292, ~: 5292) -LibDecimalFloatMinTest:testMinXYGreater(bytes32,bytes32) (runs: 5105, μ: 6074, ~: 5961) -LibDecimalFloatMinTest:testMinXYLess(bytes32,bytes32) (runs: 5100, μ: 6087, ~: 5972) -LibDecimalFloatMinusTest:testMinusPacked(bytes32) (runs: 5109, μ: 5550, ~: 5550) +LibDecimalFloatLteTest:testLteOneEAny(bytes32) (runs: 5118, μ: 3493, ~: 3493) +LibDecimalFloatLteTest:testLteReference(int224,int32,int224,int32) (runs: 5118, μ: 8107, ~: 6315) +LibDecimalFloatLteTest:testLteX(int224,int32) (runs: 5118, μ: 3904, ~: 3904) +LibDecimalFloatLteTest:testLteXEAnyVsXEAny(int256,int32,int32) (runs: 5118, μ: 10582, ~: 10321) +LibDecimalFloatLteTest:testLteXEAnyVsXEAnyNegative(int256,int32,int32) (runs: 5118, μ: 11177, ~: 11383) +LibDecimalFloatLteTest:testLteXNotLtY(bytes32,bytes32) (runs: 5118, μ: 3882, ~: 3807) +LibDecimalFloatLteTest:testLteXPositiveYNegative(int256,int32,int256,int32) (runs: 5118, μ: 13102, ~: 12931) +LibDecimalFloatLteTest:testLteXPositiveYZero(int256,int32,int32) (runs: 5118, μ: 9574, ~: 9191) +LibDecimalFloatLteTest:testLteZero(int32,int32) (runs: 5118, μ: 4816, ~: 4816) +LibDecimalFloatMaxTest:testMaxX(bytes32) (runs: 5118, μ: 4246, ~: 4246) +LibDecimalFloatMaxTest:testMaxXY(bytes32,bytes32) (runs: 5118, μ: 4689, ~: 4613) +LibDecimalFloatMaxTest:testMaxXYEqual(bytes32) (runs: 5118, μ: 5272, ~: 5272) +LibDecimalFloatMaxTest:testMaxXYGreater(bytes32,bytes32) (runs: 5109, μ: 6129, ~: 6016) +LibDecimalFloatMaxTest:testMaxXYLess(bytes32,bytes32) (runs: 5105, μ: 6141, ~: 6027) +LibDecimalFloatMinTest:testMinX(bytes32) (runs: 5118, μ: 4268, ~: 4268) +LibDecimalFloatMinTest:testMinXY(bytes32,bytes32) (runs: 5118, μ: 4689, ~: 4613) +LibDecimalFloatMinTest:testMinXYEqual(bytes32) (runs: 5118, μ: 5292, ~: 5292) +LibDecimalFloatMinTest:testMinXYGreater(bytes32,bytes32) (runs: 5110, μ: 6074, ~: 5961) +LibDecimalFloatMinTest:testMinXYLess(bytes32,bytes32) (runs: 5104, μ: 6087, ~: 5972) +LibDecimalFloatMinusTest:testMinusPacked(bytes32) (runs: 5118, μ: 5550, ~: 5550) LibDecimalFloatMixedTest:testDiv1Over3() (gas: 8161) -LibDecimalFloatMulTest:testMulPacked(bytes32,bytes32) (runs: 5109, μ: 7891, ~: 8837) -LibDecimalFloatPackTest:testPartsRoundTrip(int224,int32) (runs: 5109, μ: 5352, ~: 5352) -LibDecimalFloatPow10Test:testPow10Packed(bytes32) (runs: 5109, μ: 1644878, ~: 1257626) -LibDecimalFloatPowTest:testNegativePowError(bytes32,bytes32) (runs: 5109, μ: 1248478, ~: 1248447) -LibDecimalFloatPowTest:testPowAZero(int32,bytes32) (runs: 5103, μ: 1246471, ~: 1246471) +LibDecimalFloatMulTest:testMulPacked(bytes32,bytes32) (runs: 5118, μ: 7889, ~: 8837) +LibDecimalFloatPackTest:testPartsRoundTrip(int224,int32) (runs: 5118, μ: 5352, ~: 5352) +LibDecimalFloatPow10Test:testPow10Packed(bytes32) (runs: 5118, μ: 1643075, ~: 1257968) +LibDecimalFloatPowTest:testNegativePowError(bytes32,bytes32) (runs: 5118, μ: 1248478, ~: 1248447) +LibDecimalFloatPowTest:testPowAZero(int32,bytes32) (runs: 5110, μ: 1246471, ~: 1246471) LibDecimalFloatPowTest:testPowAZeroNegative(bytes32) (runs: 5098, μ: 1246870, ~: 1246870) -LibDecimalFloatPowTest:testPowBZero(bytes32,int32) (runs: 5109, μ: 1246058, ~: 1246058) -LibDecimalFloatPowTest:testPows() (gas: 1305439) -LibDecimalFloatPowTest:testRoundTripFuzzPow(bytes32,bytes32) (runs: 5109, μ: 1260110, ~: 1256782) -LibDecimalFloatPowTest:testRoundTripSimple() (gas: 1455217) -LibDecimalFloatSqrtTest:testRoundTripFuzzSqrt(int224,int32) (runs: 5109, μ: 1288362, ~: 1285857) -LibDecimalFloatSqrtTest:testSqrt() (gas: 1289575) -LibDecimalFloatSqrtTest:testSqrtNegative(bytes32) (runs: 5109, μ: 1248100, ~: 1248059) -LibDecimalFloatSqrtTest:testSqrtRoundTrip() (gas: 1384444) -LibDecimalFloatSubTest:testSubPacked(bytes32,bytes32) (runs: 5109, μ: 9673, ~: 9793) +LibDecimalFloatPowTest:testPowBZero(bytes32,int32) (runs: 5118, μ: 1246058, ~: 1246058) +LibDecimalFloatPowTest:testPows() (gas: 1307542) +LibDecimalFloatPowTest:testRoundTripFuzzPow(bytes32,bytes32) (runs: 5118, μ: 1260914, ~: 1257677) +LibDecimalFloatPowTest:testRoundTripSimple() (gas: 1462197) +LibDecimalFloatSqrtTest:testRoundTripFuzzSqrt(int224,int32) (runs: 5118, μ: 1292077, ~: 1289038) +LibDecimalFloatSqrtTest:testSqrt() (gas: 1293543) +LibDecimalFloatSqrtTest:testSqrtNegative(bytes32) (runs: 5117, μ: 1248101, ~: 1248059) +LibDecimalFloatSqrtTest:testSqrtRoundTrip() (gas: 1393964) +LibDecimalFloatSubTest:testSubPacked(bytes32,bytes32) (runs: 5118, μ: 9973, ~: 9995) LibFormatDecimalFloatTest:testFormatDecimalExamples() (gas: 133439) -LibFormatDecimalFloatTest:testFormatDecimalRoundTrip(uint256) (runs: 5109, μ: 25218, ~: 20105) -LibFormatDecimalFloatTest:testFormatDecimalRoundTripNegative(int256) (runs: 5109, μ: 19679, ~: 21006) +LibFormatDecimalFloatTest:testFormatDecimalRoundTrip(uint256) (runs: 5118, μ: 25209, ~: 20105) +LibFormatDecimalFloatTest:testFormatDecimalRoundTripNegative(int256) (runs: 5118, μ: 19675, ~: 21006) LibLogTableBytesTest:testToBytesAntiLogTableDec() (gas: 159794) LibLogTableBytesTest:testToBytesAntiLogTableDecSmall() (gas: 162322) LibLogTableBytesTest:testToBytesLogTableDec() (gas: 143165) @@ -291,7 +302,7 @@ LibParseDecimalFloatTest:testParseLiteralDecimalFloatEDot() (gas: 4190) LibParseDecimalFloatTest:testParseLiteralDecimalFloatExponentRevert5() (gas: 4176) LibParseDecimalFloatTest:testParseLiteralDecimalFloatExponentRevert6() (gas: 4188) LibParseDecimalFloatTest:testParseLiteralDecimalFloatExponents() (gas: 402635) -LibParseDecimalFloatTest:testParseLiteralDecimalFloatFuzz(uint256,uint8,bool) (runs: 5109, μ: 45902, ~: 37394) +LibParseDecimalFloatTest:testParseLiteralDecimalFloatFuzz(uint256,uint8,bool) (runs: 5118, μ: 45938, ~: 37394) LibParseDecimalFloatTest:testParseLiteralDecimalFloatLeadingZeros() (gas: 59779) LibParseDecimalFloatTest:testParseLiteralDecimalFloatNegativeE() (gas: 6100) LibParseDecimalFloatTest:testParseLiteralDecimalFloatNegativeFrac() (gas: 5137) @@ -299,5 +310,5 @@ LibParseDecimalFloatTest:testParseLiteralDecimalFloatPrecisionRevert0() (gas: 27 LibParseDecimalFloatTest:testParseLiteralDecimalFloatPrecisionRevert1() (gas: 24801) LibParseDecimalFloatTest:testParseLiteralDecimalFloatSpecific() (gas: 22959) LibParseDecimalFloatTest:testParseLiteralDecimalFloatUnrelated() (gas: 50856) -LibParseDecimalFloatTest:testParsePacked(string) (runs: 5109, μ: 9786, ~: 9668) -TestDecimalFloatUnpackTest:testUnpackDeployed(bytes32) (runs: 5109, μ: 158422, ~: 158422) \ No newline at end of file +LibParseDecimalFloatTest:testParsePacked(string) (runs: 5118, μ: 9787, ~: 9668) +TestDecimalFloatUnpackTest:testUnpackDeployed(bytes32) (runs: 5118, μ: 158422, ~: 158422) \ No newline at end of file diff --git a/src/lib/LibDecimalFloat.sol b/src/lib/LibDecimalFloat.sol index f822fbf7..fbfe1893 100644 --- a/src/lib/LibDecimalFloat.sol +++ b/src/lib/LibDecimalFloat.sol @@ -644,7 +644,7 @@ library LibDecimalFloat { // mantissa == 0 → value is already an integer. // mantissa > 0 (input > 0) → truncation decreases the value, so add 1 to round up. else if (mantissa > 0) { - (characteristic, exponent) = LibDecimalFloatImplementation.add(characteristic, exponent, 1e75, -75); + (characteristic, exponent) = LibDecimalFloatImplementation.add(characteristic, exponent, 1e76, -76); } (Float result, bool lossless) = packLossy(characteristic, exponent); diff --git a/src/lib/implementation/LibDecimalFloatImplementation.sol b/src/lib/implementation/LibDecimalFloatImplementation.sol index 816f73b2..f2457621 100644 --- a/src/lib/implementation/LibDecimalFloatImplementation.sol +++ b/src/lib/implementation/LibDecimalFloatImplementation.sol @@ -306,7 +306,22 @@ library LibDecimalFloatImplementation { // The actual addition step. unchecked { - signedCoefficientA += signedCoefficientB; + int256 c = signedCoefficientA + signedCoefficientB; + bool didOverflow; + assembly ("memory-safe") { + let sameSignAB := iszero(shr(0xff, xor(signedCoefficientA, signedCoefficientB))) + let sameSignAC := iszero(shr(0xff, xor(signedCoefficientA, c))) + didOverflow := and(sameSignAB, iszero(sameSignAC)) + } + // Be careful to handle overflow. + if (didOverflow) { + signedCoefficientA /= 10; + signedCoefficientB /= 10; + exponentA += 1; + signedCoefficientA += signedCoefficientB; + } else { + signedCoefficientA = c; + } } return (signedCoefficientA, exponentA); } @@ -527,17 +542,9 @@ library LibDecimalFloatImplementation { } int256 initialExponent = exponent; - if (signedCoefficient / 1e76 != 0) { - signedCoefficient /= 10; - exponent += 1; - - if (exponent < initialExponent) { - revert ExponentOverflow(signedCoefficient, exponent); - } - } // Check if already maximized before dropping into a block full of // jumps. - else if (signedCoefficient / 1e75 == 0) { + if (signedCoefficient / 1e75 == 0) { if (signedCoefficient / 1e38 == 0) { signedCoefficient *= 1e38; exponent -= 38; @@ -562,10 +569,19 @@ library LibDecimalFloatImplementation { signedCoefficient *= 10; exponent -= 1; } + } - if (initialExponent < exponent) { - revert ExponentOverflow(signedCoefficient, exponent); - } + // Maybe we can fit in one more OOM without overflow, but we won't + // know until we try. This pushes us into [1e76,type(int256).max] and + // [-type(int256).max,-1e76] ranges, if that's possible. + int256 trySignedCoefficient = signedCoefficient * 10; + if (signedCoefficient == trySignedCoefficient / 10) { + signedCoefficient = trySignedCoefficient; + exponent -= 1; + } + + if (initialExponent < exponent) { + revert ExponentOverflow(signedCoefficient, exponent); } return (signedCoefficient, exponent); @@ -799,7 +815,7 @@ library LibDecimalFloatImplementation { } // If the exponent is less than -76, the characteristic is 0. - // and the mantissa is the number itself. + // and the mantissa is the whole coefficient. if (exponent < -76) { return (0, signedCoefficient); } diff --git a/test/src/lib/LibDecimalFloat.ceil.t.sol b/test/src/lib/LibDecimalFloat.ceil.t.sol index 7295a8c3..49742ce5 100644 --- a/test/src/lib/LibDecimalFloat.ceil.t.sol +++ b/test/src/lib/LibDecimalFloat.ceil.t.sol @@ -19,15 +19,20 @@ contract LibDecimalFloatCeilTest is Test { int256 expectedSignedCoefficient, int256 expectedExponent ) internal pure { - (signedCoefficient, exponent) = + (int256 actualSignedCoefficient, int256 actualExponent) = LibDecimalFloat.ceil(LibDecimalFloat.packLossless(signedCoefficient, exponent)).unpack(); - if (!LibDecimalFloatImplementation.eq(signedCoefficient, exponent, expectedSignedCoefficient, expectedExponent)) - { + if ( + !LibDecimalFloatImplementation.eq( + actualSignedCoefficient, actualExponent, expectedSignedCoefficient, expectedExponent + ) + ) { console2.log("signedCoefficient", signedCoefficient); console2.log("exponent", exponent); console2.log("expectedSignedCoefficient", expectedSignedCoefficient); console2.log("expectedExponent", expectedExponent); + console2.log("actualSignedCoefficient", actualSignedCoefficient); + console2.log("actualExponent", actualExponent); revert("Ceil check failed"); } } diff --git a/test/src/lib/implementation/LibDecimalFloatImplementation.add.t.sol b/test/src/lib/implementation/LibDecimalFloatImplementation.add.t.sol index 7ee7f0a3..f93ac251 100644 --- a/test/src/lib/implementation/LibDecimalFloatImplementation.add.t.sol +++ b/test/src/lib/implementation/LibDecimalFloatImplementation.add.t.sol @@ -10,6 +10,36 @@ import { import {Test} from "forge-std/Test.sol"; contract LibDecimalFloatImplementationAddTest is Test { + function willOverflow(int256 a, int256 b) internal pure returns (bool) { + unchecked { + if (a > 0 && b > 0) { + return a > type(int256).max - b; + } else if (a < 0 && b < 0) { + return a < type(int256).min - b; + } else { + return false; // No overflow if signs are different. + } + } + } + + /// This is copypasta from the internals of add. + function willOverflow2(int256 a, int256 b) internal pure returns (bool didOverflow) { + unchecked { + int256 c = a + b; + assembly ("memory-safe") { + let sameSignAB := iszero(shr(0xff, xor(a, b))) + let sameSignAC := iszero(shr(0xff, xor(a, c))) + didOverflow := and(sameSignAB, iszero(sameSignAC)) + } + } + } + + function testOverflowChecks(int256 a, int256 b) external pure { + bool expected = willOverflow(a, b); + bool actual = willOverflow2(a, b); + assertEq(actual, expected, "Overflow check mismatch"); + } + function checkAdd( int256 signedCoefficientA, int256 exponentA, @@ -61,14 +91,14 @@ contract LibDecimalFloatImplementationAddTest is Test { /// 1 + 1 = 2 function testAddOneOneNotMaximized() external pure { (int256 signedCoefficient, int256 exponent) = LibDecimalFloatImplementation.add(1, 0, 1, 0); - assertEq(signedCoefficient, 2e75, "Signed coefficient mismatch"); - assertEq(exponent, -75, "Exponent mismatch"); + assertEq(signedCoefficient, 2e76, "Signed coefficient mismatch"); + assertEq(exponent, -76, "Exponent mismatch"); } function testAddOneOnePreMaximized() external pure { - (int256 signedCoefficient, int256 exponent) = LibDecimalFloatImplementation.add(1e75, -75, 1e75, -75); - assertEq(signedCoefficient, 2e75); - assertEq(exponent, -75); + (int256 signedCoefficient, int256 exponent) = LibDecimalFloatImplementation.add(1e76, -76, 1e76, -76); + assertEq(signedCoefficient, 2e76); + assertEq(exponent, -76); } /// 123456789 add 987654321 @@ -83,8 +113,8 @@ contract LibDecimalFloatImplementationAddTest is Test { /// 123456789e9 + 987654321 = 123456789987654321 function testAdd123456789e9987654321() external pure { (int256 signedCoefficient, int256 exponent) = LibDecimalFloatImplementation.add(123456789, 9, 987654321, 0); - assertEq(signedCoefficient, 1.23456789987654321e75); - assertEq(exponent, -75 + 17); + assertEq(signedCoefficient, 1.23456789987654321e76); + assertEq(exponent, -76 + 17); } function testGasAddZero() external pure { @@ -139,63 +169,83 @@ contract LibDecimalFloatImplementationAddTest is Test { function testAddingSmallToLargeReturnsLargeExamples() external pure { // Establish a baseline. - checkAdd(1e37, 0, 1e37, -37, 10000000000000000000000000000000000001e38, -38); + checkAdd(1e37, 0, 1e37, -37, 10000000000000000000000000000000000001e39, -39); // Show baseline with reversed order. - checkAdd(1e37, -37, 1e37, 0, 10000000000000000000000000000000000001e38, -38); + checkAdd(1e37, -37, 1e37, 0, 10000000000000000000000000000000000001e39, -39); // Show full precision loss. - checkAdd(1e37, 0, 1e37, -38, 100000000000000000000000000000000000001e37, -38); - checkAdd(1e37, 0, 1e37, -75, 1000000000000000000000000000000000000000000000000000000000000000000000000001, -38); - checkAdd(1e37, 0, 1e37, -76, 1e75, -38); + checkAdd(1e37, 0, 1e37, -38, 100000000000000000000000000000000000001e38, -39); + checkAdd(1e37, 0, 1e37, -75, 10000000000000000000000000000000000000000000000000000000000000000000000000010, -39); + checkAdd(1e38, 0, 1e37, -76, 1e76, -38); + checkAdd(1e37, 0, 1e37, -76, 10000000000000000000000000000000000000000000000000000000000000000000000000001, -39); // Show same thing again with reversed order. - checkAdd(1e37, -38, 1e37, 0, 100000000000000000000000000000000000001e37, -38); - checkAdd(1e37, -75, 1e37, 0, 1000000000000000000000000000000000000000000000000000000000000000000000000001, -38); - checkAdd(1e37, -76, 1e37, 0, 1e75, -38); + checkAdd(1e37, -38, 1e37, 0, 100000000000000000000000000000000000001e38, -39); + checkAdd(1e37, -75, 1e37, 0, 10000000000000000000000000000000000000000000000000000000000000000000000000010, -39); + checkAdd(1e37, -76, 1e37, 0, 10000000000000000000000000000000000000000000000000000000000000000000000000001, -39); // Same precision loss happens for negative numbers. - checkAdd(-1e37, 0, -1e37, -38, -100000000000000000000000000000000000001e37, -38); + checkAdd(-1e37, 0, -1e37, -38, -100000000000000000000000000000000000001e38, -39); checkAdd( - -1e37, 0, -1e37, -75, -1000000000000000000000000000000000000000000000000000000000000000000000000001, -38 + -1e37, 0, -1e37, -75, -10000000000000000000000000000000000000000000000000000000000000000000000000010, -39 + ); + checkAdd( + -1e37, 0, -1e37, -76, -10000000000000000000000000000000000000000000000000000000000000000000000000001, -39 ); - checkAdd(-1e37, 0, -1e37, -76, -1e75, -38); // Reverse order. - checkAdd(-1e37, -38, -1e37, 0, -100000000000000000000000000000000000001e37, -38); + checkAdd(-1e37, -38, -1e37, 0, -100000000000000000000000000000000000001e38, -39); + checkAdd( + -1e37, -75, -1e37, 0, -10000000000000000000000000000000000000000000000000000000000000000000000000010, -39 + ); checkAdd( - -1e37, -75, -1e37, 0, -1000000000000000000000000000000000000000000000000000000000000000000000000001, -38 + -1e37, -76, -1e37, 0, -10000000000000000000000000000000000000000000000000000000000000000000000000001, -39 ); - checkAdd(-1e37, -76, -1e37, 0, -1e75, -38); // Only the difference in exponents matters. Show the baseline. - checkAdd(1e37, -20, 1e37, -57, 10000000000000000000000000000000000001e38, -58); + checkAdd(1e37, -20, 1e37, -57, 10000000000000000000000000000000000001e39, -59); + checkAdd( + 1e37, -20, 1e37, -95, 10000000000000000000000000000000000000000000000000000000000000000000000000010, -59 + ); checkAdd( - 1e37, -20, 1e37, -95, 1000000000000000000000000000000000000000000000000000000000000000000000000001, -58 + 1e37, -20, 1e37, -96, 10000000000000000000000000000000000000000000000000000000000000000000000000001, -59 ); - checkAdd(1e37, -20, 1e37, -96, 1e75, -58); + checkAdd(1e37, -20, 1e37, -97, 1e76, -59); // Reverse order. - checkAdd(1e37, -57, 1e37, -20, 10000000000000000000000000000000000001e38, -58); + checkAdd(1e37, -57, 1e37, -20, 10000000000000000000000000000000000001e39, -59); checkAdd( - 1e37, -95, 1e37, -20, 1000000000000000000000000000000000000000000000000000000000000000000000000001, -58 + 1e37, -95, 1e37, -20, 10000000000000000000000000000000000000000000000000000000000000000000000000010, -59 ); - checkAdd(1e37, -96, 1e37, -20, 1e75, -58); + checkAdd( + 1e37, -96, 1e37, -20, 10000000000000000000000000000000000000000000000000000000000000000000000000001, -59 + ); + checkAdd(1e37, -97, 1e37, -20, 1e76, -59); // Show the same thing with negative numbers. - checkAdd(-1e37, -20, -1e37, -57, -10000000000000000000000000000000000001e38, -58); + checkAdd(-1e37, -20, -1e37, -57, -10000000000000000000000000000000000001e39, -59); checkAdd( - -1e37, -20, -1e37, -95, -1000000000000000000000000000000000000000000000000000000000000000000000000001, -58 + -1e37, -20, -1e37, -95, -10000000000000000000000000000000000000000000000000000000000000000000000000010, -59 ); - checkAdd(-1e37, -20, -1e37, -96, -1e75, -58); + checkAdd( + -1e37, -20, -1e37, -96, -10000000000000000000000000000000000000000000000000000000000000000000000000001, -59 + ); + checkAdd(-1e37, -20, -1e37, -97, -1e76, -59); // Reverse order. - checkAdd(-1e37, -57, -1e37, -20, -10000000000000000000000000000000000001e38, -58); + checkAdd(-1e37, -57, -1e37, -20, -10000000000000000000000000000000000001e39, -59); + checkAdd( + -1e37, -95, -1e37, -20, -10000000000000000000000000000000000000000000000000000000000000000000000000010, -59 + ); checkAdd( - -1e37, -95, -1e37, -20, -1000000000000000000000000000000000000000000000000000000000000000000000000001, -58 + -1e37, -96, -1e37, -20, -10000000000000000000000000000000000000000000000000000000000000000000000000001, -59 ); - checkAdd(-1e37, -96, -1e37, -20, -1e75, -58); + checkAdd(-1e37, -97, -1e37, -20, -1e76, -59); + + // Suspicious values flagged in fuzzing elsewhere. + checkAdd(54304950862250382, -16, 1e76, -76, 6.4304950862250382e75, -75); } - /// If the exponents are the same and the coefficients are the same, then - /// addition is simply adding the coefficients. - function testAddSameExponentSameCoefficient(int256 signedCoefficientA, int256 signedCoefficientB) external pure { + /// If the exponents are the same then addition is simply adding the + /// coefficients. + function testAddSameExponent(int256 signedCoefficientA, int256 signedCoefficientB) external pure { int256 exponentA; int256 exponentB; int256 signedCoefficientAMaximized; @@ -208,7 +258,12 @@ contract LibDecimalFloatImplementationAddTest is Test { } exponentB = exponentA; - int256 expectedSignedCoefficient = signedCoefficientAMaximized + signedCoefficientBMaximized; + int256 expectedSignedCoefficient; + unchecked { + expectedSignedCoefficient = signedCoefficientAMaximized + signedCoefficientBMaximized; + // We aren't testing the overflow case in this test. + vm.assume(!willOverflow(signedCoefficientAMaximized, signedCoefficientBMaximized)); + } int256 expectedExponent = exponentA; (int256 signedCoefficient, int256 exponent) = LibDecimalFloatImplementation.add( diff --git a/test/src/lib/implementation/LibDecimalFloatImplementation.characteristicMantissa.t.sol b/test/src/lib/implementation/LibDecimalFloatImplementation.characteristicMantissa.t.sol new file mode 100644 index 00000000..00362118 --- /dev/null +++ b/test/src/lib/implementation/LibDecimalFloatImplementation.characteristicMantissa.t.sol @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: CAL +pragma solidity =0.8.25; + +import {Test} from "forge-std/Test.sol"; + +import {LibDecimalFloatImplementation} from "src/lib/implementation/LibDecimalFloatImplementation.sol"; + +contract LibDecimalFloatImplementationCharacteristicMantissaTest is Test { + function checkCharacteristicMantissa( + int256 signedCoefficient, + int256 exponent, + int256 expectedCharacteristic, + int256 expectedMantissa + ) internal pure { + (int256 actualCharacteristic, int256 actualMantissa) = + LibDecimalFloatImplementation.characteristicMantissa(signedCoefficient, exponent); + + assertEq(actualCharacteristic, expectedCharacteristic, "Characteristic mismatch"); + assertEq(actualMantissa, expectedMantissa, "Mantissa mismatch"); + } + + function testCharacteristicMantissaExamples() public pure { + checkCharacteristicMantissa(0, 0, 0, 0); + checkCharacteristicMantissa(0, 1, 0, 0); + + checkCharacteristicMantissa(5.4304950862250382e16, -16, 5e16, 4304950862250382); + checkCharacteristicMantissa(-5.4304950862250382e16, -16, -5e16, -0.4304950862250382e16); + + checkCharacteristicMantissa(5.4304950862250382e16, -76, 0, 5.4304950862250382e16); + checkCharacteristicMantissa(-5.4304950862250382e16, -76, 0, -5.4304950862250382e16); + + // Exact multiple => zero mantissa + checkCharacteristicMantissa(5e16, -16, 5e16, 0); + checkCharacteristicMantissa(-5e16, -16, -5e16, 0); + // Off-by-one around the multiple + checkCharacteristicMantissa(5e16 + 1, -16, 5e16, 1); + checkCharacteristicMantissa(-5e16 - 1, -16, -5e16, -1); + + // Boundary at exponent -76 (scale = 1e76) + checkCharacteristicMantissa(1e76, -76, 1e76, 0); + checkCharacteristicMantissa(1e76 + 1, -76, 1e76, 1); + checkCharacteristicMantissa(-1e76, -76, -1e76, 0); + checkCharacteristicMantissa(-1e76 - 1, -76, -1e76, -1); + + // Beyond boundary at exponent -77 (scale > int256.max): characteristic must be 0 + checkCharacteristicMantissa(1, -77, 0, 1); + checkCharacteristicMantissa(-1, -77, 0, -1); + } +} diff --git a/test/src/lib/implementation/LibDecimalFloatImplementation.log10.t.sol b/test/src/lib/implementation/LibDecimalFloatImplementation.log10.t.sol index 570c57da..3cb68556 100644 --- a/test/src/lib/implementation/LibDecimalFloatImplementation.log10.t.sol +++ b/test/src/lib/implementation/LibDecimalFloatImplementation.log10.t.sol @@ -31,19 +31,19 @@ contract LibDecimalFloatImplementationLog10Test is LogTest { } function testExactLookupsLog10() external { - checkLog10(1001, 0, 3.0004e75, -75); - checkLog10(100.1e1, -1, 2.0004e75, -75); - checkLog10(10.01e2, -2, 1.0004e75, -75); + checkLog10(1001, 0, 3.0004e76, -76); + checkLog10(100.1e1, -1, 2.0004e76, -76); + checkLog10(10.01e2, -2, 1.0004e76, -76); checkLog10(1.001e3, -3, 0.0004e38, -38); - checkLog10(10.02e2, -2, 1.0009e75, -75); - checkLog10(10.99e2, -2, 1.0411e75, -75); + checkLog10(10.02e2, -2, 1.0009e76, -76); + checkLog10(10.99e2, -2, 1.0411e76, -76); - checkLog10(6566, 0, 3.8173e75, -75); + checkLog10(6566, 0, 3.8173e76, -76); } function testInterpolatedLookups() external { - checkLog10(10.015e3, -3, 1.00065e75, -75); + checkLog10(10.015e3, -3, 1.00065e76, -76); } function testSub1() external { diff --git a/test/src/lib/implementation/LibDecimalFloatImplementation.maximize.t.sol b/test/src/lib/implementation/LibDecimalFloatImplementation.maximize.t.sol index 3ce7fcdc..624d3a7f 100644 --- a/test/src/lib/implementation/LibDecimalFloatImplementation.maximize.t.sol +++ b/test/src/lib/implementation/LibDecimalFloatImplementation.maximize.t.sol @@ -18,7 +18,7 @@ contract LibDecimalFloatImplementationMaximizeTest is Test { } if (signedCoefficient / 1e76 != 0) { - return false; + return true; } if (signedCoefficient / 1e75 == 0) { @@ -29,7 +29,7 @@ contract LibDecimalFloatImplementationMaximizeTest is Test { } /// Every normalized number is maximized. - function testMaximized(int256 signedCoefficient, int256 exponent) external pure { + function testMaximizedEverything(int256 signedCoefficient, int256 exponent) external pure { exponent = bound(exponent, EXPONENT_MIN, EXPONENT_MAX); (int256 actualSignedCoefficient, int256 actualExponent) = LibDecimalFloatImplementation.maximize(signedCoefficient, exponent); @@ -51,16 +51,22 @@ contract LibDecimalFloatImplementationMaximizeTest is Test { function testMaximizedExamples() external pure { checkMaximized(0, 0, 0, 0); checkMaximized(0, 1, 0, 0); - checkMaximized(1e37, 0, 1e75, -38); - checkMaximized(1e75, 0, 1e75, 0); - checkMaximized(type(int256).max, 0, type(int256).max / 10, 1); - checkMaximized(type(int256).min, 0, type(int256).min / 10, 1); - checkMaximized(42, 0, 42e74, -74); - checkMaximized(42e74, -74, 42e74, -74); + checkMaximized(1e37, 0, 1e76, -39); + checkMaximized(1e76, 0, 1e76, 0); + checkMaximized(type(int256).max, 0, type(int256).max, 0); + checkMaximized(type(int256).min, 0, type(int256).min, 0); + checkMaximized(42, 0, 4.2e76, -75); + checkMaximized(42e74, -74, 4.2e76, -75); + checkMaximized(4.2e76, -75, 4.2e76, -75); + checkMaximized(88, 0, 8.8e75, -74); + checkMaximized(88e74, -74, 8.8e75, -74); for (int256 i = 76; i >= 0; i--) { - checkMaximized(int256(10 ** uint256(i)), 0, 1e75, i - 75); + checkMaximized(int256(10 ** uint256(i)), 0, 1e76, i - 76); } + + // Suspicious values flagged in fuzzing elsewhere. + checkMaximized(54304950862250382, -16, 5.4304950862250382e76, -76); } /// Maximization should be idempotent. diff --git a/test/src/lib/implementation/LibDecimalFloatImplementation.pow10.t.sol b/test/src/lib/implementation/LibDecimalFloatImplementation.pow10.t.sol index ae11d4b5..91cab239 100644 --- a/test/src/lib/implementation/LibDecimalFloatImplementation.pow10.t.sol +++ b/test/src/lib/implementation/LibDecimalFloatImplementation.pow10.t.sol @@ -61,9 +61,9 @@ contract LibDecimalFloatImplementationPow10Test is LogTest { function testInterpolatedLookupsPower() external { // 10^1.55555 = 35.9376769153 - checkPow10(1.55555e37, -37, 35935e71, -74); + checkPow10(1.55555e37, -37, 35.935e75, -75); // 10^1234.56789 - checkPow10(123456789, -5, 36979e71, 1159); + checkPow10(123456789, -5, 3.6979e76, 1158); // ~= 10 (fuzzing found this edge case). checkPow10( 99999999999999999999999999999999999997448, diff --git a/test/src/lib/implementation/LibDecimalFloatImplementation.sub.t.sol b/test/src/lib/implementation/LibDecimalFloatImplementation.sub.t.sol index cc4bc1f8..4ae1638a 100644 --- a/test/src/lib/implementation/LibDecimalFloatImplementation.sub.t.sol +++ b/test/src/lib/implementation/LibDecimalFloatImplementation.sub.t.sol @@ -62,7 +62,7 @@ contract LibDecimalFloatImplementationSubTest is Test { } function testSubOneFromMax() external pure { - checkSub(type(int224).max, type(int32).max, 1, 0, int256(type(int224).max) * 1e8, type(int32).max - 8); + checkSub(type(int224).max, type(int32).max, 1, 0, int256(type(int224).max) * 1e9, type(int32).max - 9); } function testSubSelf(int224 signedCoefficientA, int32 exponentA) external pure {