-
Notifications
You must be signed in to change notification settings - Fork 646
Open
Description
function tickToWord(tick: number): number {
let compressed = Math.floor(tick / tickSpacing)
// May not necessary?
if (tick < 0 && tick % tickSpacing !== 0) {
compressed -= 1
}
return compressed >> 8
}
const minWord = tickToWord(-887272)
const maxWord = tickToWord(887272)Why is compressed -= 1 needed here?
According to Solidity’s official documentation, integer division rounds towards zero:
Since the type of the result of an operation is always the type of one of the operands, division on integers always results in an integer. In Solidity, division rounds towards zero. This means that
int256(-5) / int256(2) == int256(-2).
The contract code includes an adjustment to round towards negative infinity:
if (tick < 0 && tick % tickSpacing != 0) compressed--; // round towards negative infinityHowever, JavaScript’s Math.floor already rounds towards negative infinity by default. For this reason, I believe the compressed -= 1 adjustment in the above code is unnecessary.
I might be misunderstanding this—please correct me if that’s the case.
Metadata
Metadata
Assignees
Labels
No labels