Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions test/src/lib/LibDecimalFloat.eq.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,15 @@ contract LibDecimalFloatEqTest is Test {

assertEq(eq, !lt && !gt);
}

/// Test some zeros.
function testEqZero(int32 exponent) external pure {
Float wrapZero = Float.wrap(0);
Float packZeroBasic = LibDecimalFloat.packLossless(0, 0);
Float packZero = LibDecimalFloat.packLossless(0, exponent);

assertTrue(wrapZero.eq(packZero));
assertTrue(wrapZero.eq(packZeroBasic));
assertEq(Float.unwrap(wrapZero), Float.unwrap(packZeroBasic));
}
}
18 changes: 18 additions & 0 deletions test/src/lib/LibDecimalFloat.lt.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import {Test} from "forge-std/Test.sol";
contract LibDecimalFloatLtTest is Test {
using LibDecimalFloat for Float;

function checkExample(
int256 signedCoefficientA,
int32 exponentA,
int256 signedCoefficientB,
int32 exponentB,
bool expected
) internal pure {
Float a = LibDecimalFloat.packLossless(signedCoefficientA, exponentA);
Float b = LibDecimalFloat.packLossless(signedCoefficientB, exponentB);

bool actual = LibDecimalFloat.lt(a, b);
assertEq(actual, expected);
}

function testLtReference(Float a, Float b) external pure {
bool actual = LibDecimalFloat.lt(a, b);
(int256 signedCoefficientA, int256 exponentA) = a.unpack();
Expand Down Expand Up @@ -139,4 +153,8 @@ contract LibDecimalFloatLtTest is Test {
LibDecimalFloat.packLossless(1, type(int32).max), LibDecimalFloat.packLossless(1, type(int32).min)
);
}

function testLtExamples() external pure {
checkExample(999999999999974209482711874742541185097679753153111, -51, 0, 0, false);
}
}