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
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ contract LibDecimalFloatImplementationDivTest is Test {
this.divExternal(1e76, 76, 1, type(int256).min + 76);
}

/// A positive dividend over a negative power of ten divisor, with the
/// quotient exponent exactly `type(int256).max`: `1e76 10^(max - 76)` over
/// `-1 10^-76` is exactly `-1e76 10^max`, which needs no shed digit, so it
/// returns. Only a `type(int256).min` dividend there has a 2^255 quotient.
function testDivNegativePowerOfTenDivisorAtMax() external pure {
int256 max = type(int256).max;
checkDiv(1e76, max - 76, -1, -76, -1e76, max);
checkDiv(-1e76, max - 76, -1, -76, 1e76, max);
checkDiv(type(int256).max, max - 76, -1, -76, -type(int256).max, max);
}

/// An unfull divisor at the floor overflows the quotient exponent for a
/// numerator with a non-negative maximized exponent.
function testDivUnfullDivisorExponentOverflow() external {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,15 +538,22 @@ contract LibDecimalFloatImplementationMainEquivalenceTest is Test {
// #368: a positive 2^255 quotient below the floor, by each scale,
// down to the last digit it keeps.
for (int256 u = 1; u <= 76; u++) {
assertDiffers(
abi.encodeCall(this.mainDiv, (min, min + 76, -1e76, u)),
abi.encodeCall(this.prDiv, (min, min + 76, -1e76, u))
);
checkDiv(min, min + 76, -1e76, u);
checkDiv(min, min + 75, -1e75, u);
this.checkDivMinByMinusScaleBelowFloor(u);
}
}

/// One shed of the #368 loop, in its own call frame so memory does not
/// accumulate across the 76 sheds.
function checkDivMinByMinusScaleBelowFloor(int256 u) external view {
int256 min = type(int256).min;
assertDiffers(
abi.encodeCall(this.mainDiv, (min, min + 76, -1e76, u)),
abi.encodeCall(this.prDiv, (min, min + 76, -1e76, u))
);
checkDiv(min, min + 76, -1e76, u);
checkDiv(min, min + 75, -1e75, u);
}

function testMainEquivalenceAddFloorExamples() external view {
int256 min = type(int256).min;
assertDiffers(abi.encodeCall(this.mainAdd, (1, min, 1, min)), abi.encodeCall(this.prAdd, (1, min, 1, min)));
Expand Down
Loading