| 1 |
|
| 2 |
mod radix_10p19_u64 { |
| 3 |
use super::*; |
| 4 |
use super::RADIX_10p19_u64 as Radix; |
| 5 |
|
| 6 |
#[test] |
| 7 |
fn split_wide_digit_10e19_0() { |
| 8 |
let (hi, lo) = Radix::split_wide_digit(0); |
| 9 |
assert_eq!(hi, 0); |
| 10 |
assert_eq!(lo, 0); |
| 11 |
} |
| 12 |
|
| 13 |
#[test] |
| 14 |
fn split_wide_digit_10e19_sqrd() { |
| 15 |
let (hi, lo) = Radix::split_wide_digit(99999999999999999980000000000000000001); |
| 16 |
assert_eq!(hi, 9999999999999999998); |
| 17 |
assert_eq!(lo, 1); |
| 18 |
} |
| 19 |
|
| 20 |
#[test] |
| 21 |
fn split_wide_digit_5060270152244608514849739578370464703() { |
| 22 |
let (hi, lo) = Radix::split_wide_digit(5060270152244608514849739578370464703); |
| 23 |
assert_eq!(hi, 506027015224460851); |
| 24 |
assert_eq!(lo, 4849739578370464703); |
| 25 |
} |
| 26 |
|
| 27 |
#[test] |
| 28 |
fn add_with_carry() { |
| 29 |
let mut carry = 20; |
| 30 |
let sum = Radix::add_carry(222292843123382, &mut carry); |
| 31 |
assert_eq!(sum, 222292843123402); |
| 32 |
assert_eq!(carry, 0); |
| 33 |
} |
| 34 |
|
| 35 |
#[test] |
| 36 |
fn add_with_carry_overflow_18446744073709551600_55() { |
| 37 |
let mut carry = 55; |
| 38 |
let sum = Radix::add_carry(18446744073709551600, &mut carry); |
| 39 |
assert_eq!(sum, 8446744073709551655); |
| 40 |
assert_eq!(carry, 1); |
| 41 |
} |
| 42 |
|
| 43 |
#[test] |
| 44 |
fn add_with_carry_overflow_2() { |
| 45 |
let result = &mut [0, 1, 2]; |
| 46 |
let mut carry = 40; |
| 47 |
Radix::add_carry_into_slice(result, &mut carry); |
| 48 |
assert_eq!(result, &[40, 1, 2]); |
| 49 |
assert_eq!(carry, 0); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
mod radix_u64 { |
| 54 |
use super::*; |
| 55 |
use super::RADIX_u64 as Radix; |
| 56 |
|
| 57 |
#[test] |
| 58 |
fn add_with_carry_overflow_1() { |
| 59 |
let mut carry = 55; |
| 60 |
let sum = Radix::add_carry(18446744073709551600, &mut carry); |
| 61 |
assert_eq!(sum, 39); |
| 62 |
assert_eq!(carry, 1); |
| 63 |
} |
| 64 |
|
| 65 |
#[test] |
| 66 |
fn add_with_carry_overflow_2() { |
| 67 |
let result = &mut 0; |
| 68 |
let mut carry = 40; |
| 69 |
Radix::addassign_carry(result, &mut carry); |
| 70 |
assert_eq!(*result, 40); |
| 71 |
assert_eq!(carry, 0); |
| 72 |
} |
| 73 |
|
| 74 |
#[test] |
| 75 |
fn add_with_carry_overflow_3() { |
| 76 |
let mut result = 3533561901698977160; |
| 77 |
let mut carry = 17004058994074047095; |
| 78 |
Radix::addassign_carry(&mut result, &mut carry); |
| 79 |
assert_eq!(result, 2090876822063472639); |
| 80 |
assert_eq!(carry, 1); |
| 81 |
} |
| 82 |
} |