Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions test/src/lib/LibDecimalFloat.pow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,23 @@ 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 {
Float inv = b.inv();
try this.powExternal(c, inv) returns (Float roundTrip) {
if (roundTrip.isZero()) {} 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)) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
if (b.isZero()) {
Comment thread
thedavidmeister marked this conversation as resolved.
assertTrue(c.eq(LibDecimalFloat.FLOAT_ONE), "b is 0 so c should be 1");
} 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);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (!roundTrip.isZero()) {
Float diff = a.div(roundTrip).sub(LibDecimalFloat.packLossless(1, 0)).abs();
assertTrue(!diff.gt(diffLimit()), "diff");
}
Comment thread
thedavidmeister marked this conversation as resolved.
} catch (bytes memory err) {}
}
}
} catch (bytes memory err) {}
} catch (bytes memory) {
// Can't round trip something that errors.
}
}
}
Loading