From 683be23b2e28888025f4f59d3e57aa3aa057fea1 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 10 Sep 2025 12:16:08 +0200 Subject: [PATCH 1/7] lint tests --- test/src/lib/LibDecimalFloat.pow.t.sol | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/src/lib/LibDecimalFloat.pow.t.sol b/test/src/lib/LibDecimalFloat.pow.t.sol index bfebdfe6..c7b50d15 100644 --- a/test/src/lib/LibDecimalFloat.pow.t.sol +++ b/test/src/lib/LibDecimalFloat.pow.t.sol @@ -150,18 +150,19 @@ contract LibDecimalFloatPowTest is LogTest { function testRoundTripFuzzPow(Float a, Float b) external { try this.powExternal(a, b) returns (Float c) { - // If b is zero we'll divide by zero on the inv. - // If c is 1 then it's not round trippable because 1^x = 1 for all x. - // C will be 1 when a is 1 or b is 0 (or very close to either). - if (b.isZero() || c.eq(LibDecimalFloat.FLOAT_ONE)) {} else { + // If C is 1 then either a is 1 or b is 0 or so close that we round to 0. + // The case where a is 1 should round trip, but all other cases won't. + if (a.eq(LibDecimalFloat.FLOAT_ONE) || !c.eq(LibDecimalFloat.FLOAT_ONE)) { Float inv = b.inv(); - try this.powExternal(c, inv) returns (Float roundTrip) { - if (roundTrip.isZero()) {} else { - Float diff = a.div(roundTrip).sub(LibDecimalFloat.packLossless(1, 0)).abs(); - assertTrue(!diff.gt(diffLimit()), "diff"); - } - } catch (bytes memory err) {} + // The round trip should not error so we do not try. + Float roundTrip = this.powExternal(c, inv); + if (roundTrip.isZero()) {} else { + Float diff = a.div(roundTrip).sub(LibDecimalFloat.packLossless(1, 0)).abs(); + assertTrue(!diff.gt(diffLimit()), "diff"); + } } - } catch (bytes memory err) {} + } catch (bytes memory) { + // Can't round trip something that errors. + } } } From 3b538a1aab0a00c861a42fb5de62c31b7c1fcc1d Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 10 Sep 2025 20:33:14 +0200 Subject: [PATCH 2/7] edge case in fuzz --- test/src/lib/LibDecimalFloat.pow.t.sol | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/src/lib/LibDecimalFloat.pow.t.sol b/test/src/lib/LibDecimalFloat.pow.t.sol index c7b50d15..4e810022 100644 --- a/test/src/lib/LibDecimalFloat.pow.t.sol +++ b/test/src/lib/LibDecimalFloat.pow.t.sol @@ -153,12 +153,16 @@ contract LibDecimalFloatPowTest is LogTest { // If C is 1 then either a is 1 or b is 0 or so close that we round to 0. // The case where a is 1 should round trip, but all other cases won't. if (a.eq(LibDecimalFloat.FLOAT_ONE) || !c.eq(LibDecimalFloat.FLOAT_ONE)) { - Float inv = b.inv(); - // The round trip should not error so we do not try. - Float roundTrip = this.powExternal(c, inv); - if (roundTrip.isZero()) {} else { - Float diff = a.div(roundTrip).sub(LibDecimalFloat.packLossless(1, 0)).abs(); - assertTrue(!diff.gt(diffLimit()), "diff"); + if (b.isZero()) { + assertTrue(c.eq(LibDecimalFloat.FLOAT_ONE), "b is 0 so c should be 1"); + } else { + Float inv = b.inv(); + // The round trip should not error so we do not try. + Float roundTrip = this.powExternal(c, inv); + if (roundTrip.isZero()) {} else { + Float diff = a.div(roundTrip).sub(LibDecimalFloat.packLossless(1, 0)).abs(); + assertTrue(!diff.gt(diffLimit()), "diff"); + } } } } catch (bytes memory) { From d3646a770a4a252051a4f2512146278657f1196b Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 10 Sep 2025 20:52:57 +0200 Subject: [PATCH 3/7] guard on fuzz --- test/src/lib/LibDecimalFloat.pow.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/lib/LibDecimalFloat.pow.t.sol b/test/src/lib/LibDecimalFloat.pow.t.sol index 4e810022..6bb3906d 100644 --- a/test/src/lib/LibDecimalFloat.pow.t.sol +++ b/test/src/lib/LibDecimalFloat.pow.t.sol @@ -155,7 +155,7 @@ contract LibDecimalFloatPowTest is LogTest { if (a.eq(LibDecimalFloat.FLOAT_ONE) || !c.eq(LibDecimalFloat.FLOAT_ONE)) { if (b.isZero()) { assertTrue(c.eq(LibDecimalFloat.FLOAT_ONE), "b is 0 so c should be 1"); - } else { + } else if (!c.isZero() || !b.lt(LibDecimalFloat.FLOAT_ZERO)) { Float inv = b.inv(); // The round trip should not error so we do not try. Float roundTrip = this.powExternal(c, inv); From 40eb907c00317d5e17cbd1e353a2d2619f6ffc8b Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 10 Sep 2025 21:11:32 +0200 Subject: [PATCH 4/7] lint --- test/src/lib/LibDecimalFloat.pow.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/lib/LibDecimalFloat.pow.t.sol b/test/src/lib/LibDecimalFloat.pow.t.sol index 6bb3906d..2f30e291 100644 --- a/test/src/lib/LibDecimalFloat.pow.t.sol +++ b/test/src/lib/LibDecimalFloat.pow.t.sol @@ -159,7 +159,7 @@ contract LibDecimalFloatPowTest is LogTest { Float inv = b.inv(); // The round trip should not error so we do not try. Float roundTrip = this.powExternal(c, inv); - if (roundTrip.isZero()) {} else { + if (!roundTrip.isZero()) { Float diff = a.div(roundTrip).sub(LibDecimalFloat.packLossless(1, 0)).abs(); assertTrue(!diff.gt(diffLimit()), "diff"); } From 3f91f5cfb0023f0cb1b0d01ba80ee5ff38d67e60 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 10 Sep 2025 21:13:56 +0200 Subject: [PATCH 5/7] lint --- test/src/lib/LibDecimalFloat.pow.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/lib/LibDecimalFloat.pow.t.sol b/test/src/lib/LibDecimalFloat.pow.t.sol index 2f30e291..34361833 100644 --- a/test/src/lib/LibDecimalFloat.pow.t.sol +++ b/test/src/lib/LibDecimalFloat.pow.t.sol @@ -155,7 +155,7 @@ contract LibDecimalFloatPowTest is LogTest { if (a.eq(LibDecimalFloat.FLOAT_ONE) || !c.eq(LibDecimalFloat.FLOAT_ONE)) { if (b.isZero()) { assertTrue(c.eq(LibDecimalFloat.FLOAT_ONE), "b is 0 so c should be 1"); - } else if (!c.isZero() || !b.lt(LibDecimalFloat.FLOAT_ZERO)) { + } else if (!(c.isZero() && b.lt(LibDecimalFloat.FLOAT_ZERO))) { Float inv = b.inv(); // The round trip should not error so we do not try. Float roundTrip = this.powExternal(c, inv); From 3cfbcb26df807c313822e0d1cf2aca6f2cf97e49 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 10 Sep 2025 21:14:52 +0200 Subject: [PATCH 6/7] lint --- test/src/lib/LibDecimalFloat.pow.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/lib/LibDecimalFloat.pow.t.sol b/test/src/lib/LibDecimalFloat.pow.t.sol index 34361833..f70f635b 100644 --- a/test/src/lib/LibDecimalFloat.pow.t.sol +++ b/test/src/lib/LibDecimalFloat.pow.t.sol @@ -160,7 +160,7 @@ contract LibDecimalFloatPowTest is LogTest { // The round trip should not error so we do not try. Float roundTrip = this.powExternal(c, inv); if (!roundTrip.isZero()) { - Float diff = a.div(roundTrip).sub(LibDecimalFloat.packLossless(1, 0)).abs(); + Float diff = a.div(roundTrip).sub(LibDecimalFloat.FLOAT_ONE).abs(); assertTrue(!diff.gt(diffLimit()), "diff"); } } From af1f3bdd10304c87dee1a495e403a248f7a696d9 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Wed, 10 Sep 2025 21:19:42 +0200 Subject: [PATCH 7/7] lint --- test/src/lib/LibDecimalFloat.pow.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/lib/LibDecimalFloat.pow.t.sol b/test/src/lib/LibDecimalFloat.pow.t.sol index f70f635b..8c5cbea1 100644 --- a/test/src/lib/LibDecimalFloat.pow.t.sol +++ b/test/src/lib/LibDecimalFloat.pow.t.sol @@ -150,7 +150,7 @@ contract LibDecimalFloatPowTest is LogTest { function testRoundTripFuzzPow(Float a, Float b) external { try this.powExternal(a, b) returns (Float c) { - // If C is 1 then either a is 1 or b is 0 or so close that we round to 0. + // If C is 1 then either a == 1 or b == 0 (or b rounds to 0). // The case where a is 1 should round trip, but all other cases won't. if (a.eq(LibDecimalFloat.FLOAT_ONE) || !c.eq(LibDecimalFloat.FLOAT_ONE)) { if (b.isZero()) {