|
|
|
@ -54,6 +54,12 @@ impl Number for NativeFloat64 { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn display_debug() { |
|
|
|
|
let x = NativeFloat64::parse("123.4"); assert_eq!(format!("{}", x), format!("{}", 123.40_f64)); |
|
|
|
|
let x = NativeFloat64::parse("123.4"); assert_eq!(format!("{:?}", x), format!("NativeFloat64({})", 123.40_f64)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn rounding() { |
|
|
|
|
let mut x = NativeFloat64::parse("55.550"); x.floor_mut(2); assert_eq!(x, NativeFloat64::parse("55.55")); |
|
|
|
@ -90,6 +96,15 @@ impl Assign<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
fn assign(&mut self, src: &NativeFloat64) { self.0 = src.0; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn assign() { |
|
|
|
|
let a = NativeFloat64::parse("123.45"); |
|
|
|
|
let b = NativeFloat64::parse("678.90"); |
|
|
|
|
|
|
|
|
|
let mut x = a.clone(); x.assign(b.clone()); assert_eq!(x, b); |
|
|
|
|
let mut x = a.clone(); x.assign(&b); assert_eq!(x, b); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<usize> for NativeFloat64 { |
|
|
|
|
fn from(n: usize) -> Self { Self(n as ImplType) } |
|
|
|
|
} |
|
|
|
@ -139,9 +154,7 @@ impl ops::Div for NativeFloat64 { |
|
|
|
|
|
|
|
|
|
impl ops::Rem for NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn rem(self, _rhs: Self) -> Self::Output { |
|
|
|
|
todo!() |
|
|
|
|
} |
|
|
|
|
fn rem(self, rhs: Self) -> Self::Output { Self(self.0 % rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
@ -153,33 +166,32 @@ fn arith_owned_owned() { |
|
|
|
|
assert_eq!(a.clone() - b.clone(), NativeFloat64::from(123.45_f64 - 678.90_f64)); |
|
|
|
|
assert_eq!(a.clone() * b.clone(), NativeFloat64::from(123.45_f64 * 678.90_f64)); |
|
|
|
|
assert_eq!(a.clone() / b.clone(), NativeFloat64::from(123.45_f64 / 678.90_f64)); |
|
|
|
|
assert_eq!(b.clone() % a.clone(), NativeFloat64::from(678.90_f64 % 123.45_f64)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Add<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn add(self, rhs: &NativeFloat64) -> Self::Output { Self(self.0 + &rhs.0) } |
|
|
|
|
fn add(self, rhs: &NativeFloat64) -> Self::Output { Self(self.0 + rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Sub<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn sub(self, rhs: &NativeFloat64) -> Self::Output { Self(self.0 - &rhs.0) } |
|
|
|
|
fn sub(self, rhs: &NativeFloat64) -> Self::Output { Self(self.0 - rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Mul<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn mul(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 * &rhs.0) } |
|
|
|
|
fn mul(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 * rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Div<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn div(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 / &rhs.0) } |
|
|
|
|
fn div(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 / rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Rem<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn rem(self, _rhs: &NativeFloat64) -> Self::Output { |
|
|
|
|
todo!() |
|
|
|
|
} |
|
|
|
|
fn rem(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 % rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
@ -191,6 +203,7 @@ fn arith_owned_ref() { |
|
|
|
|
assert_eq!(a.clone() - &b, NativeFloat64::from(123.45_f64 - 678.90_f64)); |
|
|
|
|
assert_eq!(a.clone() * &b, NativeFloat64::from(123.45_f64 * 678.90_f64)); |
|
|
|
|
assert_eq!(a.clone() / &b, NativeFloat64::from(123.45_f64 / 678.90_f64)); |
|
|
|
|
assert_eq!(b.clone() % &a, NativeFloat64::from(678.90_f64 % 123.45_f64)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::AddAssign for NativeFloat64 { |
|
|
|
@ -206,13 +219,11 @@ impl ops::MulAssign for NativeFloat64 { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::DivAssign for NativeFloat64 { |
|
|
|
|
fn div_assign(&mut self, rhs: Self) { self.0 /= &rhs.0; } |
|
|
|
|
fn div_assign(&mut self, rhs: Self) { self.0 /= rhs.0; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::RemAssign for NativeFloat64 { |
|
|
|
|
fn rem_assign(&mut self, _rhs: Self) { |
|
|
|
|
todo!() |
|
|
|
|
} |
|
|
|
|
fn rem_assign(&mut self, rhs: Self) { self.0 %= rhs.0; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
@ -224,28 +235,27 @@ fn arithassign_owned() { |
|
|
|
|
let mut x = a.clone(); x -= b.clone(); assert_eq!(x, NativeFloat64::from(123.45_f64 - 678.90_f64)); |
|
|
|
|
let mut x = a.clone(); x *= b.clone(); assert_eq!(x, NativeFloat64::from(123.45_f64 * 678.90_f64)); |
|
|
|
|
let mut x = a.clone(); x /= b.clone(); assert_eq!(x, NativeFloat64::from(123.45_f64 / 678.90_f64)); |
|
|
|
|
let mut x = b.clone(); x %= a.clone(); assert_eq!(x, NativeFloat64::from(678.90_f64 % 123.45_f64)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::AddAssign<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
fn add_assign(&mut self, rhs: &NativeFloat64) { self.0 += &rhs.0; } |
|
|
|
|
fn add_assign(&mut self, rhs: &NativeFloat64) { self.0 += rhs.0; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::SubAssign<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
fn sub_assign(&mut self, rhs: &NativeFloat64) { self.0 -= &rhs.0; } |
|
|
|
|
fn sub_assign(&mut self, rhs: &NativeFloat64) { self.0 -= rhs.0; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::MulAssign<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
fn mul_assign(&mut self, rhs: &NativeFloat64) { self.0 *= &rhs.0; } |
|
|
|
|
fn mul_assign(&mut self, rhs: &NativeFloat64) { self.0 *= rhs.0; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::DivAssign<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
fn div_assign(&mut self, rhs: &NativeFloat64) { self.0 /= &rhs.0; } |
|
|
|
|
fn div_assign(&mut self, rhs: &NativeFloat64) { self.0 /= rhs.0; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::RemAssign<&NativeFloat64> for NativeFloat64 { |
|
|
|
|
fn rem_assign(&mut self, _rhs: &NativeFloat64) { |
|
|
|
|
todo!() |
|
|
|
|
} |
|
|
|
|
fn rem_assign(&mut self, rhs: &NativeFloat64) { self.0 %= rhs.0; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
@ -257,38 +267,37 @@ fn arithassign_ref() { |
|
|
|
|
let mut x = a.clone(); x -= &b; assert_eq!(x, NativeFloat64::from(123.45_f64 - 678.90_f64)); |
|
|
|
|
let mut x = a.clone(); x *= &b; assert_eq!(x, NativeFloat64::from(123.45_f64 * 678.90_f64)); |
|
|
|
|
let mut x = a.clone(); x /= &b; assert_eq!(x, NativeFloat64::from(123.45_f64 / 678.90_f64)); |
|
|
|
|
let mut x = b.clone(); x %= &a; assert_eq!(x, NativeFloat64::from(678.90_f64 % 123.45_f64)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Neg for &NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn neg(self) -> Self::Output { NativeFloat64(-&self.0) } |
|
|
|
|
fn neg(self) -> Self::Output { NativeFloat64(-self.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Add<Self> for &NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn add(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(&self.0 + &rhs.0) } |
|
|
|
|
fn add(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 + rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Sub<Self> for &NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn sub(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(&self.0 - &rhs.0) } |
|
|
|
|
fn sub(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 - rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Mul<Self> for &NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn mul(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(&self.0 * &rhs.0) } |
|
|
|
|
fn mul(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 * rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Div<Self> for &NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn div(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(&self.0 / &rhs.0) } |
|
|
|
|
fn div(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 / rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl ops::Rem<Self> for &NativeFloat64 { |
|
|
|
|
type Output = NativeFloat64; |
|
|
|
|
fn rem(self, _rhs: &NativeFloat64) -> Self::Output { |
|
|
|
|
todo!() |
|
|
|
|
} |
|
|
|
|
fn rem(self, rhs: &NativeFloat64) -> Self::Output { NativeFloat64(self.0 % rhs.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
@ -300,6 +309,7 @@ fn arith_ref_ref() { |
|
|
|
|
assert_eq!(&a - &b, NativeFloat64::from(123.45_f64 - 678.90_f64)); |
|
|
|
|
assert_eq!(&a * &b, NativeFloat64::from(123.45_f64 * 678.90_f64)); |
|
|
|
|
assert_eq!(&a / &b, NativeFloat64::from(123.45_f64 / 678.90_f64)); |
|
|
|
|
assert_eq!(&b % &a, NativeFloat64::from(678.90_f64 % 123.45_f64)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|