Skip to content

Commit 8b63fcd

Browse files
committed
make floor/ceil tenses consistent
1 parent cdc653d commit 8b63fcd

File tree

4 files changed

+64
-64
lines changed

4 files changed

+64
-64
lines changed

packages/std/src/math/fraction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<T: Copy + From<u8> + PartialEq> Fraction<T> for (T, T) {
3535
macro_rules! impl_mul_fraction {
3636
($Uint:ident) => {
3737
impl $Uint {
38-
pub fn checked_mul_floored<F: Fraction<T>, T: Into<$Uint>>(
38+
pub fn checked_mul_floor<F: Fraction<T>, T: Into<$Uint>>(
3939
self,
4040
rhs: F,
4141
) -> Result<Self, CheckedMultiplyFractionError> {
@@ -46,8 +46,8 @@ macro_rules! impl_mul_fraction {
4646
Ok(res.try_into()?)
4747
}
4848

49-
pub fn mul_floored<F: Fraction<T>, T: Into<$Uint>>(self, rhs: F) -> Self {
50-
self.checked_mul_floored(rhs).unwrap()
49+
pub fn mul_floor<F: Fraction<T>, T: Into<$Uint>>(self, rhs: F) -> Self {
50+
self.checked_mul_floor(rhs).unwrap()
5151
}
5252

5353
pub fn checked_mul_ceil<F: Fraction<T>, T: Into<$Uint>>(
@@ -58,7 +58,7 @@ macro_rules! impl_mul_fraction {
5858
let remainder = self
5959
.full_mul(rhs.numerator().into())
6060
.checked_rem(divisor.into())?;
61-
let floor_result = self.checked_mul_floored(rhs)?;
61+
let floor_result = self.checked_mul_floor(rhs)?;
6262
if !remainder.is_zero() {
6363
Ok($Uint::one().checked_add(floor_result)?)
6464
} else {

packages/std/src/math/uint128.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,62 +1047,62 @@ mod tests {
10471047
}
10481048

10491049
#[test]
1050-
fn mul_floored_works_with_zero() {
1050+
fn mul_floor_works_with_zero() {
10511051
let fraction = (Uint128::zero(), Uint128::new(21));
1052-
let res = Uint128::new(123456).mul_floored(fraction);
1052+
let res = Uint128::new(123456).mul_floor(fraction);
10531053
assert_eq!(Uint128::zero(), res)
10541054
}
10551055

10561056
#[test]
1057-
fn mul_floored_does_nothing_with_one() {
1057+
fn mul_floor_does_nothing_with_one() {
10581058
let fraction = (Uint128::one(), Uint128::one());
1059-
let res = Uint128::new(123456).mul_floored(fraction);
1059+
let res = Uint128::new(123456).mul_floor(fraction);
10601060
assert_eq!(Uint128::new(123456), res)
10611061
}
10621062

10631063
#[test]
1064-
fn mul_floored_rounds_down_with_normal_case() {
1064+
fn mul_floor_rounds_down_with_normal_case() {
10651065
let fraction = (8u128, 21u128);
1066-
let res = Uint128::new(123456).mul_floored(fraction); // 47030.8571
1066+
let res = Uint128::new(123456).mul_floor(fraction); // 47030.8571
10671067
assert_eq!(Uint128::new(47030), res)
10681068
}
10691069

10701070
#[test]
1071-
fn mul_floored_does_not_round_on_even_divide() {
1071+
fn mul_floor_does_not_round_on_even_divide() {
10721072
let fraction = (2u128, 5u128);
1073-
let res = Uint128::new(25).mul_floored(fraction);
1073+
let res = Uint128::new(25).mul_floor(fraction);
10741074
assert_eq!(Uint128::new(10), res)
10751075
}
10761076

10771077
#[test]
1078-
fn mul_floored_works_when_operation_temporarily_takes_above_max() {
1078+
fn mul_floor_works_when_operation_temporarily_takes_above_max() {
10791079
let fraction = (8u128, 21u128);
1080-
let res = Uint128::MAX.mul_floored(fraction); // 129_631_377_874_643_224_176_523_659_974_006_937_697.14285
1080+
let res = Uint128::MAX.mul_floor(fraction); // 129_631_377_874_643_224_176_523_659_974_006_937_697.14285
10811081
assert_eq!(
10821082
Uint128::new(129_631_377_874_643_224_176_523_659_974_006_937_697),
10831083
res
10841084
)
10851085
}
10861086

10871087
#[test]
1088-
fn mul_floored_works_with_decimal() {
1088+
fn mul_floor_works_with_decimal() {
10891089
let decimal = Decimal::from_ratio(8u128, 21u128);
1090-
let res = Uint128::new(123456).mul_floored(decimal); // 47030.8571
1090+
let res = Uint128::new(123456).mul_floor(decimal); // 47030.8571
10911091
assert_eq!(Uint128::new(47030), res)
10921092
}
10931093

10941094
#[test]
10951095
#[should_panic(expected = "ConversionOverflowError")]
1096-
fn mul_floored_panics_on_overflow() {
1096+
fn mul_floor_panics_on_overflow() {
10971097
let fraction = (21u128, 8u128);
1098-
Uint128::MAX.mul_floored(fraction);
1098+
Uint128::MAX.mul_floor(fraction);
10991099
}
11001100

11011101
#[test]
1102-
fn checked_mul_floored_does_not_panic_on_overflow() {
1102+
fn checked_mul_floor_does_not_panic_on_overflow() {
11031103
let fraction = (21u128, 8u128);
11041104
assert_eq!(
1105-
Uint128::MAX.checked_mul_floored(fraction),
1105+
Uint128::MAX.checked_mul_floor(fraction),
11061106
Err(ConversionOverflow(ConversionOverflowError {
11071107
source_type: "Uint256",
11081108
target_type: "Uint128",
@@ -1113,16 +1113,16 @@ mod tests {
11131113

11141114
#[test]
11151115
#[should_panic(expected = "DivideByZeroError")]
1116-
fn mul_floored_panics_on_zero_div() {
1116+
fn mul_floor_panics_on_zero_div() {
11171117
let fraction = (21u128, 0u128);
1118-
Uint128::new(123456).mul_floored(fraction);
1118+
Uint128::new(123456).mul_floor(fraction);
11191119
}
11201120

11211121
#[test]
1122-
fn checked_mul_floored_does_not_panic_on_zero_div() {
1122+
fn checked_mul_floor_does_not_panic_on_zero_div() {
11231123
let fraction = (21u128, 0u128);
11241124
assert_eq!(
1125-
Uint128::new(123456).checked_mul_floored(fraction),
1125+
Uint128::new(123456).checked_mul_floor(fraction),
11261126
Err(DivideByZero(DivideByZeroError {
11271127
operand: "2592576".to_string()
11281128
})),

packages/std/src/math/uint256.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,37 +1669,37 @@ mod tests {
16691669
}
16701670

16711671
#[test]
1672-
fn mul_floored_works_with_zero() {
1672+
fn mul_floor_works_with_zero() {
16731673
let fraction = (Uint256::zero(), Uint256::from(21u32));
1674-
let res = Uint256::from(123456u32).mul_floored(fraction);
1674+
let res = Uint256::from(123456u32).mul_floor(fraction);
16751675
assert_eq!(Uint256::zero(), res)
16761676
}
16771677

16781678
#[test]
1679-
fn mul_floored_does_nothing_with_one() {
1679+
fn mul_floor_does_nothing_with_one() {
16801680
let fraction = (Uint256::one(), Uint256::one());
1681-
let res = Uint256::from(123456u32).mul_floored(fraction);
1681+
let res = Uint256::from(123456u32).mul_floor(fraction);
16821682
assert_eq!(Uint256::from(123456u32), res)
16831683
}
16841684

16851685
#[test]
1686-
fn mul_floored_rounds_down_with_normal_case() {
1686+
fn mul_floor_rounds_down_with_normal_case() {
16871687
let fraction = (Uint256::from(8u128), Uint256::from(21u128));
1688-
let res = Uint256::from(123456u32).mul_floored(fraction); // 47030.8571
1688+
let res = Uint256::from(123456u32).mul_floor(fraction); // 47030.8571
16891689
assert_eq!(Uint256::from(47030u32), res)
16901690
}
16911691

16921692
#[test]
1693-
fn mul_floored_does_not_round_on_even_divide() {
1693+
fn mul_floor_does_not_round_on_even_divide() {
16941694
let fraction = (2u128, 5u128);
1695-
let res = Uint256::from(25u32).mul_floored(fraction);
1695+
let res = Uint256::from(25u32).mul_floor(fraction);
16961696
assert_eq!(Uint256::from(10u32), res)
16971697
}
16981698

16991699
#[test]
1700-
fn mul_floored_works_when_operation_temporarily_takes_above_max() {
1700+
fn mul_floor_works_when_operation_temporarily_takes_above_max() {
17011701
let fraction = (8u128, 21u128);
1702-
let res = Uint256::MAX.mul_floored(fraction); // 44_111_272_090_406_169_685_169_899_050_928_726_801_245_708_444_053_548_205_507_651_050_633_573_196_165.71428571
1702+
let res = Uint256::MAX.mul_floor(fraction); // 44_111_272_090_406_169_685_169_899_050_928_726_801_245_708_444_053_548_205_507_651_050_633_573_196_165.71428571
17031703
assert_eq!(
17041704
Uint256::from_str(
17051705
"44111272090406169685169899050928726801245708444053548205507651050633573196165"
@@ -1710,31 +1710,31 @@ mod tests {
17101710
}
17111711

17121712
#[test]
1713-
fn mul_floored_works_with_decimal() {
1713+
fn mul_floor_works_with_decimal() {
17141714
let decimal = Decimal::from_ratio(8u128, 21u128);
1715-
let res = Uint256::from(123456u32).mul_floored(decimal); // 47030.8571
1715+
let res = Uint256::from(123456u32).mul_floor(decimal); // 47030.8571
17161716
assert_eq!(Uint256::from(47030u32), res)
17171717
}
17181718

17191719
#[test]
1720-
fn mul_floored_works_with_decimal256() {
1720+
fn mul_floor_works_with_decimal256() {
17211721
let decimal = Decimal256::from_ratio(8u128, 21u128);
1722-
let res = Uint256::from(123456u32).mul_floored(decimal); // 47030.8571
1722+
let res = Uint256::from(123456u32).mul_floor(decimal); // 47030.8571
17231723
assert_eq!(Uint256::from(47030u32), res)
17241724
}
17251725

17261726
#[test]
17271727
#[should_panic(expected = "ConversionOverflowError")]
1728-
fn mul_floored_panics_on_overflow() {
1728+
fn mul_floor_panics_on_overflow() {
17291729
let fraction = (21u128, 8u128);
1730-
Uint256::MAX.mul_floored(fraction);
1730+
Uint256::MAX.mul_floor(fraction);
17311731
}
17321732

17331733
#[test]
1734-
fn checked_mul_floored_does_not_panic_on_overflow() {
1734+
fn checked_mul_floor_does_not_panic_on_overflow() {
17351735
let fraction = (21u128, 8u128);
17361736
assert_eq!(
1737-
Uint256::MAX.checked_mul_floored(fraction),
1737+
Uint256::MAX.checked_mul_floor(fraction),
17381738
Err(ConversionOverflow(ConversionOverflowError {
17391739
source_type: "Uint512",
17401740
target_type: "Uint256",
@@ -1747,16 +1747,16 @@ mod tests {
17471747

17481748
#[test]
17491749
#[should_panic(expected = "DivideByZeroError")]
1750-
fn mul_floored_panics_on_zero_div() {
1750+
fn mul_floor_panics_on_zero_div() {
17511751
let fraction = (21u128, 0u128);
1752-
Uint256::from(123456u32).mul_floored(fraction);
1752+
Uint256::from(123456u32).mul_floor(fraction);
17531753
}
17541754

17551755
#[test]
1756-
fn checked_mul_floored_does_not_panic_on_zero_div() {
1756+
fn checked_mul_floor_does_not_panic_on_zero_div() {
17571757
let fraction = (21u128, 0u128);
17581758
assert_eq!(
1759-
Uint256::from(123456u32).checked_mul_floored(fraction),
1759+
Uint256::from(123456u32).checked_mul_floor(fraction),
17601760
Err(DivideByZero(DivideByZeroError {
17611761
operand: "2592576".to_string()
17621762
})),

packages/std/src/math/uint64.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -961,52 +961,52 @@ mod tests {
961961
}
962962

963963
#[test]
964-
fn mul_floored_works_with_zero() {
964+
fn mul_floor_works_with_zero() {
965965
let fraction = (0u32, 21u32);
966-
let res = Uint64::new(123456).mul_floored(fraction);
966+
let res = Uint64::new(123456).mul_floor(fraction);
967967
assert_eq!(Uint64::zero(), res)
968968
}
969969

970970
#[test]
971-
fn mul_floored_does_nothing_with_one() {
971+
fn mul_floor_does_nothing_with_one() {
972972
let fraction = (Uint64::one(), Uint64::one());
973-
let res = Uint64::new(123456).mul_floored(fraction);
973+
let res = Uint64::new(123456).mul_floor(fraction);
974974
assert_eq!(Uint64::new(123456), res)
975975
}
976976

977977
#[test]
978-
fn mul_floored_rounds_down_with_normal_case() {
978+
fn mul_floor_rounds_down_with_normal_case() {
979979
let fraction = (8u64, 21u64);
980-
let res = Uint64::new(123456).mul_floored(fraction); // 47030.8571
980+
let res = Uint64::new(123456).mul_floor(fraction); // 47030.8571
981981
assert_eq!(Uint64::new(47030), res)
982982
}
983983

984984
#[test]
985-
fn mul_floored_does_not_round_on_even_divide() {
985+
fn mul_floor_does_not_round_on_even_divide() {
986986
let fraction = (2u64, 5u64);
987-
let res = Uint64::new(25).mul_floored(fraction);
987+
let res = Uint64::new(25).mul_floor(fraction);
988988
assert_eq!(Uint64::new(10), res)
989989
}
990990

991991
#[test]
992-
fn mul_floored_works_when_operation_temporarily_takes_above_max() {
992+
fn mul_floor_works_when_operation_temporarily_takes_above_max() {
993993
let fraction = (8u64, 21u64);
994-
let res = Uint64::MAX.mul_floored(fraction); // 7_027_331_075_698_876_805.71428571
994+
let res = Uint64::MAX.mul_floor(fraction); // 7_027_331_075_698_876_805.71428571
995995
assert_eq!(Uint64::new(7_027_331_075_698_876_805), res)
996996
}
997997

998998
#[test]
999999
#[should_panic(expected = "ConversionOverflowError")]
1000-
fn mul_floored_panics_on_overflow() {
1000+
fn mul_floor_panics_on_overflow() {
10011001
let fraction = (21u64, 8u64);
1002-
Uint64::MAX.mul_floored(fraction);
1002+
Uint64::MAX.mul_floor(fraction);
10031003
}
10041004

10051005
#[test]
1006-
fn checked_mul_floored_does_not_panic_on_overflow() {
1006+
fn checked_mul_floor_does_not_panic_on_overflow() {
10071007
let fraction = (21u64, 8u64);
10081008
assert_eq!(
1009-
Uint64::MAX.checked_mul_floored(fraction),
1009+
Uint64::MAX.checked_mul_floor(fraction),
10101010
Err(ConversionOverflow(ConversionOverflowError {
10111011
source_type: "Uint128",
10121012
target_type: "Uint64",
@@ -1017,16 +1017,16 @@ mod tests {
10171017

10181018
#[test]
10191019
#[should_panic(expected = "DivideByZeroError")]
1020-
fn mul_floored_panics_on_zero_div() {
1020+
fn mul_floor_panics_on_zero_div() {
10211021
let fraction = (21u64, 0u64);
1022-
Uint64::new(123456).mul_floored(fraction);
1022+
Uint64::new(123456).mul_floor(fraction);
10231023
}
10241024

10251025
#[test]
1026-
fn checked_mul_floored_does_not_panic_on_zero_div() {
1026+
fn checked_mul_floor_does_not_panic_on_zero_div() {
10271027
let fraction = (21u64, 0u64);
10281028
assert_eq!(
1029-
Uint64::new(123456).checked_mul_floored(fraction),
1029+
Uint64::new(123456).checked_mul_floor(fraction),
10301030
Err(DivideByZero(DivideByZeroError {
10311031
operand: "2592576".to_string()
10321032
})),

0 commit comments

Comments
 (0)