-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: threshold check in SD59x18 exp2 function #228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,14 @@ | |
pragma solidity >=0.8.19 <0.9.0; | ||
|
||
import { sd } from "src/sd59x18/Casting.sol"; | ||
import { E, EXP2_MAX_INPUT, MIN_SD59x18, MIN_WHOLE_SD59x18, PI, UNIT, ZERO } from "src/sd59x18/Constants.sol"; | ||
import { E, EXP2_MAX_INPUT, MIN_SD59x18, MIN_WHOLE_SD59x18, PI, UNIT, ZERO, uEXP2_MIN_THRESHOLD, EXP2_MIN_THRESHOLD } from "src/sd59x18/Constants.sol"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. has to be ordered alphabetically |
||
import { PRBMath_SD59x18_Exp2_InputTooBig } from "src/sd59x18/Errors.sol"; | ||
import { exp2 } from "src/sd59x18/Math.sol"; | ||
import { SD59x18 } from "src/sd59x18/ValueType.sol"; | ||
|
||
import { SD59x18_Unit_Test } from "../../SD59x18.t.sol"; | ||
|
||
contract Exp2_Unit_Test is SD59x18_Unit_Test { | ||
/// @dev Any input smaller than this makes the result zero. | ||
SD59x18 internal constant THRESHOLD = SD59x18.wrap(-59_794705707972522261); | ||
|
||
function test_Exp2_Zero() external pure { | ||
SD59x18 x = ZERO; | ||
|
@@ -28,7 +26,7 @@ contract Exp2_Unit_Test is SD59x18_Unit_Test { | |
delete sets; | ||
sets.push(set({ x: MIN_SD59x18, expected: 0 })); | ||
sets.push(set({ x: MIN_WHOLE_SD59x18, expected: 0 })); | ||
sets.push(set({ x: THRESHOLD - sd(1), expected: 0 })); | ||
sets.push(set({ x: EXP2_MIN_THRESHOLD - sd(1), expected: 0 })); | ||
return sets; | ||
} | ||
|
||
|
@@ -39,7 +37,9 @@ contract Exp2_Unit_Test is SD59x18_Unit_Test { | |
|
||
function negativeAndGteMinPermitted_Sets() internal returns (Set[] memory) { | ||
delete sets; | ||
sets.push(set({ x: THRESHOLD, expected: 0.000000000000000001e18 })); | ||
sets.push(set({ x: EXP2_MIN_THRESHOLD, expected: 0.000000000000000001e18 })); | ||
sets.push(set({ x: EXP2_MIN_THRESHOLD - sd(1), expected: 0 })); | ||
sets.push(set({ x: -sd(2**255-1), expected: 0 })); | ||
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smallest value has to be at the top
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use |
||
sets.push(set({ x: -33.333333e18, expected: 0.000000000092398923e18 })); | ||
sets.push(set({ x: -20.82e18, expected: 0.000000540201132438e18 })); | ||
sets.push(set({ x: -16e18, expected: 0.0000152587890625e18 })); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexplained. We need to add an explanatory comment