Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add tests for floats
  • Loading branch information
jcapriot committed Nov 12, 2025
commit 14f3f346b03b56e2eac1cff75d8fa5b7eb2bed6d
77 changes: 76 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2670,7 +2670,7 @@ pub(crate) mod test {

#[test]
#[cfg(any(feature = "std", feature = "libm"))]
fn test_mul_add_float() {
fn test_mul_add_float_complex_complex() {
assert_eq!(_05_05i.mul_add(_05_05i, _0_0i), _05_05i * _05_05i + _0_0i);
assert_eq!(_05_05i * _05_05i + _0_0i, _05_05i.mul_add(_05_05i, _0_0i));
assert_eq!(_0_1i.mul_add(_0_1i, _0_1i), _neg1_1i);
Expand All @@ -2694,6 +2694,81 @@ pub(crate) mod test {
}
}

#[test]
#[cfg(any(feature = "std", feature = "libm"))]
fn test_mul_add_float_real_complex() {
assert_eq!(_05_05i.mul_add(0.5, _0_0i), _05_05i * 0.5 + _0_0i);
assert_eq!(_05_05i * 0.5 + _0_0i, _05_05i.mul_add(0.5, _0_0i));
assert_eq!(_1_0i.mul_add(1.0, _1_0i), _1_0i * 1.0 + _1_0i);
assert_eq!(_1_0i * 1.0 + _1_0i, _1_0i.mul_add(1.0, _1_0i));

let mut x = _1_0i;
x.mul_add_assign(1.0, _1_0i);
assert_eq!(x, _1_0i * 1.0 + _1_0i);

for &a in &all_consts {
for &b in &[-1.0, -0.5, 0.0, 0.5, 1.0] {
for &c in &all_consts {
let abc = a * b + c;
assert_eq!(a.mul_add(b, c), abc);
let mut x = a;
x.mul_add_assign(b, c);
assert_eq!(x, abc);
}
}
}
}

#[test]
#[cfg(any(feature = "std", feature = "libm"))]
fn test_mul_add_float_complex_real() {
assert_eq!(_05_05i.mul_add(_05_05i, 0.0), _05_05i * _05_05i + 0.0);
assert_eq!(_05_05i * _05_05i + 0.0, _05_05i.mul_add(_05_05i, 0.0));
assert_eq!(_1_0i.mul_add(_1_0i, 1.0), _1_0i * _1_0i + 1.0);
assert_eq!(_1_0i * _1_0i + 1.0, _1_0i.mul_add(_1_0i, 1.0));

let mut x = _1_0i;
x.mul_add_assign(_1_0i, 1.0);
assert_eq!(x, _1_0i * _1_0i + 1.0);

for &a in &all_consts {
for &b in &all_consts {
for &c in &[-1.0, -0.5, 0.0, 0.5, 1.0] {
let abc = a * b + c;
assert_eq!(a.mul_add(b, c), abc);
let mut x = a;
x.mul_add_assign(b, c);
assert_eq!(x, abc);
}
}
}
}

#[test]
#[cfg(any(feature = "std", feature = "libm"))]
fn test_mul_add_float_real_real() {
assert_eq!(_05_05i.mul_add(0.5, 0.0), _05_05i * 0.5 + 0.0);
assert_eq!(_05_05i * 0.5 + 0.0, _05_05i.mul_add(0.5, 0.0));
assert_eq!(_1_0i.mul_add(1.0, 1.0), _1_0i * 1.0 + 1.0);
assert_eq!(_1_0i * 1.0 + 1.0, _1_0i.mul_add(1.0, 1.0));

let mut x = _1_0i;
x.mul_add_assign(1.0, 1.0);
assert_eq!(x, _1_0i * 1.0 + 1.0);

for &a in &all_consts {
for &b in &[-1.0, -0.5, 0.0, 0.5, 1.0] {
for &c in &[-1.0, -0.5, 0.0, 0.5, 1.0] {
let abc = a * b + c;
assert_eq!(a.mul_add(b, c), abc);
let mut x = a;
x.mul_add_assign(b, c);
assert_eq!(x, abc);
}
}
}
}

#[test]
fn test_mul_add_complex_complex() {
assert_eq!(_1_0i_i32.mul_add(_1_0i_i32, _0_0i_i32), _1_0i_i32 * _1_0i_i32 + _0_0i_i32);
Expand Down