Skip to content

Commit c8e9540

Browse files
wip on maximize
1 parent 3453a4b commit c8e9540

2 files changed

Lines changed: 10 additions & 22 deletions

File tree

src/lib/implementation/LibDecimalFloatImplementation.sol

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
} from "../../generated/LogTables.pointers.sol";
1212
import {LibDecimalFloat} from "../LibDecimalFloat.sol";
1313

14+
import {console2} from "forge-std/console2.sol";
15+
1416
error WithTargetExponentOverflow(int256 signedCoefficient, int256 exponent, int256 targetExponent);
1517

1618
uint256 constant ADD_MAX_EXPONENT_DIFF = 76;
@@ -560,21 +562,7 @@ library LibDecimalFloatImplementation {
560562
// know until we try. This pushes us into [1e76,type(int256).max] and
561563
// [-type(int256).max,-1e76] ranges, if that's possible.
562564
int256 trySignedCoefficient = signedCoefficient * 10;
563-
564-
// Checking for overflow without branching logic.
565-
bool notOverflow;
566-
assembly ("memory-safe") {
567-
// Sign is same if the high bits are both 0 or both 1.
568-
let signSame := iszero(shr(0xff, xor(trySignedCoefficient, signedCoefficient)))
569-
// If the sign is the same, then the new value is larger if
570-
// dividing it by the old value is non-zero.
571-
let bigger := iszero(iszero(sdiv(trySignedCoefficient, signedCoefficient)))
572-
573-
// We didn't overflow if the sign is the same and the new value
574-
// is larger than the old value.
575-
notOverflow := and(signSame, bigger)
576-
}
577-
if (notOverflow) {
565+
if (signedCoefficient == trySignedCoefficient / 10) {
578566
signedCoefficient = trySignedCoefficient;
579567
exponent -= 1;
580568
}

test/src/lib/implementation/LibDecimalFloatImplementation.log10.t.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ contract LibDecimalFloatImplementationLog10Test is LogTest {
3131
}
3232

3333
function testExactLookupsLog10() external {
34-
checkLog10(1001, 0, 3.0004e75, -75);
35-
checkLog10(100.1e1, -1, 2.0004e75, -75);
36-
checkLog10(10.01e2, -2, 1.0004e75, -75);
34+
checkLog10(1001, 0, 3.0004e76, -76);
35+
checkLog10(100.1e1, -1, 2.0004e76, -76);
36+
checkLog10(10.01e2, -2, 1.0004e76, -76);
3737
checkLog10(1.001e3, -3, 0.0004e38, -38);
3838

39-
checkLog10(10.02e2, -2, 1.0009e75, -75);
40-
checkLog10(10.99e2, -2, 1.0411e75, -75);
39+
checkLog10(10.02e2, -2, 1.0009e76, -76);
40+
checkLog10(10.99e2, -2, 1.0411e76, -76);
4141

42-
checkLog10(6566, 0, 3.8173e75, -75);
42+
checkLog10(6566, 0, 3.8173e76, -76);
4343
}
4444

4545
function testInterpolatedLookups() external {
46-
checkLog10(10.015e3, -3, 1.00065e75, -75);
46+
checkLog10(10.015e3, -3, 1.00065e76, -76);
4747
}
4848

4949
function testSub1() external {

0 commit comments

Comments
 (0)