Skip to content

Commit

Permalink
Merge pull request #8 from Flocqst/add-new-methods
Browse files Browse the repository at this point in the history
Add isSameSideReducing & divDecimalToDimensionless
  • Loading branch information
tommyrharper authored Mar 27, 2024
2 parents d1e14aa + 2ef09d9 commit 4e32f32
Show file tree
Hide file tree
Showing 62 changed files with 2,591 additions and 979 deletions.
1,982 changes: 1,027 additions & 955 deletions .gas-snapshot

Large diffs are not rendered by default.

84 changes: 60 additions & 24 deletions lcov.info
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ DA:79,0
FN:83,InteractionsBaseInt128.zero
FNDA:0,InteractionsBaseInt128.zero
DA:84,0
FNF:9
FN:88,InteractionsBaseInt128.isSameSideReducing
FNDA:0,InteractionsBaseInt128.isSameSideReducing
DA:93,0
FNF:10
FNH:0
LF:9
LF:10
LH:0
BRF:0
BRH:0
Expand Down Expand Up @@ -66,9 +69,12 @@ DA:112,0
FN:116,InteractionsBaseQuantoPerUSDInt128.zero
FNDA:0,InteractionsBaseQuantoPerUSDInt128.zero
DA:117,0
FNF:10
FN:121,InteractionsBaseQuantoPerUSDInt128.isSameSideReducing
FNDA:0,InteractionsBaseQuantoPerUSDInt128.isSameSideReducing
DA:125,0
FNF:11
FNH:0
LF:10
LF:11
LH:0
BRF:0
BRH:0
Expand Down Expand Up @@ -102,9 +108,12 @@ DA:87,0
FN:91,InteractionsQuantoInt128.zero
FNDA:0,InteractionsQuantoInt128.zero
DA:92,0
FNF:9
FN:96,InteractionsQuantoInt128.isSameSideReducing
FNDA:0,InteractionsQuantoInt128.isSameSideReducing
DA:101,0
FNF:10
FNH:0
LF:9
LF:10
LH:0
BRF:0
BRH:0
Expand Down Expand Up @@ -135,9 +144,12 @@ DA:57,0
FN:61,InteractionsUSDInt128.zero
FNDA:0,InteractionsUSDInt128.zero
DA:62,0
FNF:8
FN:66,InteractionsUSDInt128.isSameSideReducing
FNDA:0,InteractionsUSDInt128.isSameSideReducing
DA:71,0
FNF:9
FNH:0
LF:8
LF:9
LH:0
BRF:0
BRH:0
Expand Down Expand Up @@ -175,9 +187,12 @@ DA:107,0
FN:111,InteractionsUSDPerBaseInt128.zero
FNDA:0,InteractionsUSDPerBaseInt128.zero
DA:112,0
FNF:10
FN:116,InteractionsUSDPerBaseInt128.isSameSideReducing
FNDA:0,InteractionsUSDPerBaseInt128.isSameSideReducing
DA:121,0
FNF:11
FNH:0
LF:11
LF:12
LH:0
BRF:0
BRH:0
Expand Down Expand Up @@ -215,9 +230,12 @@ DA:109,0
FN:113,InteractionsUSDPerQuantoInt128.zero
FNDA:0,InteractionsUSDPerQuantoInt128.zero
DA:114,0
FNF:10
FN:118,InteractionsUSDPerQuantoInt128.isSameSideReducing
FNDA:0,InteractionsUSDPerQuantoInt128.isSameSideReducing
DA:123,0
FNF:11
FNH:0
LF:11
LF:12
LH:0
BRF:0
BRH:0
Expand All @@ -239,9 +257,12 @@ DA:39,0
FN:43,InteractionsBaseInt256.zero
FNDA:0,InteractionsBaseInt256.zero
DA:44,0
FNF:5
FN:48,InteractionsBaseInt256.isSameSideReducing
FNDA:0,InteractionsBaseInt256.isSameSideReducing
DA:53,0
FNF:6
FNH:0
LF:5
LF:6
LH:0
BRF:0
BRH:0
Expand All @@ -266,9 +287,12 @@ DA:64,0
FN:70,InteractionsBaseQuantoPerUSDInt256.zero
FNDA:0,InteractionsBaseQuantoPerUSDInt256.zero
DA:71,0
FNF:6
FN:75,InteractionsBaseQuantoPerUSDInt256.isSameSideReducing
FNDA:0,InteractionsBaseQuantoPerUSDInt256.isSameSideReducing
DA:79,0
FNF:7
FNH:0
LF:6
LF:7
LH:0
BRF:0
BRH:0
Expand All @@ -290,9 +314,12 @@ DA:47,0
FN:51,InteractionsQuantoInt256.zero
FNDA:0,InteractionsQuantoInt256.zero
DA:52,0
FNF:5
FN:56,InteractionsQuantoInt256.isSameSideReducing
FNDA:0,InteractionsQuantoInt256.isSameSideReducing
DA:61,0
FNF:6
FNH:0
LF:5
LF:6
LH:0
BRF:0
BRH:0
Expand All @@ -311,9 +338,12 @@ DA:26,0
FN:30,InteractionsUSDInt256.zero
FNDA:0,InteractionsUSDInt256.zero
DA:31,0
FNF:4
FN:35,InteractionsUSDInt256.isSameSideReducing
FNDA:0,InteractionsUSDInt256.isSameSideReducing
DA:40,0
FNF:5
FNH:0
LF:4
LF:5
LH:0
BRF:0
BRH:0
Expand All @@ -339,9 +369,12 @@ DA:63,0
FN:67,InteractionsUSDPerBaseInt256.zero
FNDA:0,InteractionsUSDPerBaseInt256.zero
DA:68,0
FNF:6
FN:72,InteractionsUSDPerBaseInt256.isSameSideReducing
FNDA:0,InteractionsUSDPerBaseInt256.isSameSideReducing
DA:77,0
FNF:7
FNH:0
LF:7
LF:8
LH:0
BRF:0
BRH:0
Expand All @@ -366,9 +399,12 @@ DA:63,0
FN:69,InteractionsUSDPerQuantoInt256.zero
FNDA:0,InteractionsUSDPerQuantoInt256.zero
DA:70,0
FNF:6
FN:74,InteractionsUSDPerQuantoInt256.isSameSideReducing
FNDA:0,InteractionsUSDPerQuantoInt256.isSameSideReducing
DA:79,0
FNF:7
FNH:0
LF:6
LF:7
LH:0
BRF:0
BRH:0
Expand Down
9 changes: 9 additions & 0 deletions src/Int128/BaseInt128/Interactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ library InteractionsBaseInt128 {
function zero() internal pure returns (BaseInt128) {
return BaseInt128.wrap(0);
}

/// @notice Returns is same side reducing Boolean for the BaseInt128 type.
function isSameSideReducing(BaseInt128 x, BaseInt128 y)
internal
pure
returns (bool)
{
return sameSide(x, y) && abs128(y) < abs128(x);
}
}
9 changes: 9 additions & 0 deletions src/Int128/BaseInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ function divToDimensionless(BaseInt128 x, BaseInt128 y)
result = x.unwrap() / y.unwrap();
}

/// @notice Divides BaseInt128 and BaseInt128 to dimensionless
function divDecimalToDimensionless(BaseInt128 x, BaseInt128 y)
pure
returns (int256 result)
{
result = x.unwrap().divDecimal(y.unwrap());
}

/// @notice Implements the ceiling division of BaseInt128 by BaseInt128 to dimensionless.
function ceilDivide(BaseInt128 x, BaseInt128 y) pure returns (int128) {
return x.unwrap() / y.unwrap()
Expand Down Expand Up @@ -199,6 +207,7 @@ using {
sameSide,
isZero,
divToDimensionless,
divDecimalToDimensionless,
ceilDivide,
greaterThanZero,
lessThanZero,
Expand Down
8 changes: 8 additions & 0 deletions src/Int128/BaseQuantoPerUSDInt128/Interactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,12 @@ library InteractionsBaseQuantoPerUSDInt128 {
function zero() internal pure returns (BaseQuantoPerUSDInt128) {
return BaseQuantoPerUSDInt128.wrap(0);
}

/// @notice Returns is same side reducing Boolean for the BaseQuantoPerUSDInt128 type.
function isSameSideReducing(
BaseQuantoPerUSDInt128 x,
BaseQuantoPerUSDInt128 y
) internal pure returns (bool) {
return sameSide(x, y) && abs128(y) < abs128(x);
}
}
9 changes: 9 additions & 0 deletions src/Int128/BaseQuantoPerUSDInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ function divToDimensionless(BaseQuantoPerUSDInt128 x, BaseQuantoPerUSDInt128 y)
result = x.unwrap() / y.unwrap();
}

/// @notice Divides BaseQuantoPerUSDInt128 and BaseQuantoPerUSDInt128 to dimensionless
function divDecimalToDimensionless(
BaseQuantoPerUSDInt128 x,
BaseQuantoPerUSDInt128 y
) pure returns (int256 result) {
result = x.unwrap().divDecimal(y.unwrap());
}

/// @notice Implements the ceiling division of BaseQuantoPerUSDInt128 by BaseQuantoPerUSDInt128 to dimensionless.
function ceilDivide(BaseQuantoPerUSDInt128 x, BaseQuantoPerUSDInt128 y)
pure
Expand Down Expand Up @@ -268,6 +276,7 @@ using {
sameSide,
isZero,
divToDimensionless,
divDecimalToDimensionless,
ceilDivide,
greaterThanZero,
lessThanZero,
Expand Down
9 changes: 9 additions & 0 deletions src/Int128/QuantoInt128/Interactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,13 @@ library InteractionsQuantoInt128 {
function zero() internal pure returns (QuantoInt128) {
return QuantoInt128.wrap(0);
}

/// @notice Returns is same side reducing Boolean for the QuantoInt128 type.
function isSameSideReducing(QuantoInt128 x, QuantoInt128 y)
internal
pure
returns (bool)
{
return sameSide(x, y) && abs128(y) < abs128(x);
}
}
9 changes: 9 additions & 0 deletions src/Int128/QuantoInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ function divToDimensionless(QuantoInt128 x, QuantoInt128 y)
result = x.unwrap() / y.unwrap();
}

/// @notice Divides QuantoInt128 and QuantoInt128 to dimensionless
function divDecimalToDimensionless(QuantoInt128 x, QuantoInt128 y)
pure
returns (int256 result)
{
result = x.unwrap().divDecimal(y.unwrap());
}

/// @notice Implements the ceiling division of QuantoInt128 by QuantoInt128 to dimensionless.
function ceilDivide(QuantoInt128 x, QuantoInt128 y) pure returns (int128) {
return x.unwrap() / y.unwrap()
Expand Down Expand Up @@ -220,6 +228,7 @@ using {
sameSide,
isZero,
divToDimensionless,
divDecimalToDimensionless,
ceilDivide,
greaterThanZero,
lessThanZero,
Expand Down
9 changes: 9 additions & 0 deletions src/Int128/USDInt128/Interactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ library InteractionsUSDInt128 {
function zero() internal pure returns (USDInt128) {
return USDInt128.wrap(0);
}

/// @notice Returns is same side reducing Boolean for the USDInt128 type.
function isSameSideReducing(USDInt128 x, USDInt128 y)
internal
pure
returns (bool)
{
return sameSide(x, y) && abs128(y) < abs128(x);
}
}
9 changes: 9 additions & 0 deletions src/Int128/USDInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ function divToDimensionless(USDInt128 x, USDInt128 y)
result = x.unwrap() / y.unwrap();
}

/// @notice Divides USDInt128 and USDInt128 to dimensionless
function divDecimalToDimensionless(USDInt128 x, USDInt128 y)
pure
returns (int256 result)
{
result = x.unwrap().divDecimal(y.unwrap());
}

/// @notice Implements the ceiling division of USDInt128 by USDInt128 to dimensionless.
function ceilDivide(USDInt128 x, USDInt128 y) pure returns (int128) {
return x.unwrap() / y.unwrap()
Expand Down Expand Up @@ -199,6 +207,7 @@ using {
sameSide,
isZero,
divToDimensionless,
divDecimalToDimensionless,
ceilDivide,
greaterThanZero,
lessThanZero,
Expand Down
9 changes: 9 additions & 0 deletions src/Int128/USDPerBaseInt128/Interactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,13 @@ library InteractionsUSDPerBaseInt128 {
function zero() internal pure returns (USDPerBaseInt128) {
return USDPerBaseInt128.wrap(0);
}

/// @notice Returns is same side reducing Boolean for the USDPerBaseInt128 type.
function isSameSideReducing(USDPerBaseInt128 x, USDPerBaseInt128 y)
internal
pure
returns (bool)
{
return sameSide(x, y) && abs128(y) < abs128(x);
}
}
9 changes: 9 additions & 0 deletions src/Int128/USDPerBaseInt128/ValueType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ function divToDimensionless(USDPerBaseInt128 x, USDPerBaseInt128 y)
result = x.unwrap() / y.unwrap();
}

/// @notice Divides USDPerBaseInt128 and USDPerBaseInt128 to dimensionless
function divDecimalToDimensionless(USDPerBaseInt128 x, USDPerBaseInt128 y)
pure
returns (int256 result)
{
result = x.unwrap().divDecimal(y.unwrap());
}

/// @notice Implements the ceiling division of USDPerBaseInt128 by USDPerBaseInt128 to dimensionless.
function ceilDivide(USDPerBaseInt128 x, USDPerBaseInt128 y)
pure
Expand Down Expand Up @@ -238,6 +246,7 @@ using {
sameSide,
isZero,
divToDimensionless,
divDecimalToDimensionless,
ceilDivide,
greaterThanZero,
lessThanZero,
Expand Down
9 changes: 9 additions & 0 deletions src/Int128/USDPerQuantoInt128/Interactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,13 @@ library InteractionsUSDPerQuantoInt128 {
function zero() internal pure returns (USDPerQuantoInt128) {
return USDPerQuantoInt128.wrap(0);
}

/// @notice Returns is same side reducing Boolean for the USDPerQuantoInt128 type.
function isSameSideReducing(USDPerQuantoInt128 x, USDPerQuantoInt128 y)
internal
pure
returns (bool)
{
return sameSide(x, y) && abs128(y) < abs128(x);
}
}
Loading

0 comments on commit 4e32f32

Please sign in to comment.