mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 22:51:13 +00:00
fix lstrip in biguint (#6151)
* add failing test for multiply_by_rational * fix BigUint * fix length * bump version * merge tests
This commit is contained in:
@@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 251,
|
||||
impl_version: 0,
|
||||
impl_version: 1,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
};
|
||||
|
||||
@@ -151,7 +151,7 @@ impl BigUint {
|
||||
// has the ability to cause this. There is nothing to do if the number already has 1
|
||||
// limb only. call it a day and return.
|
||||
if self.len().is_zero() { return; }
|
||||
let index = self.digits.iter().position(|&elem| elem != 0).unwrap_or(0);
|
||||
let index = self.digits.iter().position(|&elem| elem != 0).unwrap_or(self.len() - 1);
|
||||
|
||||
if index > 0 {
|
||||
self.digits = self.digits[index..].to_vec()
|
||||
@@ -581,19 +581,19 @@ pub mod tests {
|
||||
fn strip_works() {
|
||||
let mut a = BigUint::from_limbs(&[0, 1, 0]);
|
||||
a.lstrip();
|
||||
assert_eq!(a, BigUint { digits: vec![1, 0] });
|
||||
assert_eq!(a.digits, vec![1, 0]);
|
||||
|
||||
let mut a = BigUint::from_limbs(&[0, 0, 1]);
|
||||
a.lstrip();
|
||||
assert_eq!(a, BigUint { digits: vec![1] });
|
||||
assert_eq!(a.digits, vec![1]);
|
||||
|
||||
let mut a = BigUint::from_limbs(&[0, 0]);
|
||||
a.lstrip();
|
||||
assert_eq!(a, BigUint { digits: vec![0] });
|
||||
assert_eq!(a.digits, vec![0]);
|
||||
|
||||
let mut a = BigUint::from_limbs(&[0, 0, 0]);
|
||||
a.lstrip();
|
||||
assert_eq!(a, BigUint { digits: vec![0] });
|
||||
assert_eq!(a.digits, vec![0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -360,6 +360,15 @@ mod tests {
|
||||
multiply_by_rational(1_000_000_000, MAX128 / 8, MAX128 / 2).unwrap(),
|
||||
250000000,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
multiply_by_rational(
|
||||
29459999999999999988000u128,
|
||||
1000000000000000000u128,
|
||||
10000000000000000000u128
|
||||
).unwrap(),
|
||||
2945999999999999998800u128
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user