// These are adapted from libm, a port of musl libc's libm to Rust. // libm can be found online [here](https://github.com/rust-lang/libm), // and is similarly licensed under an Apache2.0/MIT license
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs #[test] fn fabsf_spec_test() {
assert!(libm::fabsf(f32::NAN).is_nan()); for f in [0.0, -0.0].iter().copied() {
assert_eq!(libm::fabsf(f), 0.0);
} for f in [f32::INFINITY, f32::NEG_INFINITY].iter().copied() {
assert_eq!(libm::fabsf(f), f32::INFINITY);
}
}
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/sqrt #[test] fn sqrtf_spec_test() { // Not Asserted: FE_INVALID exception is raised if argument is negative.
assert!(libm::sqrtf(-1.0).is_nan());
assert!(libm::sqrtf(f32::NAN).is_nan()); for f in [0.0, -0.0, f32::INFINITY].iter().copied() {
assert_eq!(libm::sqrtf(f), f);
}
}
#[test] fn powd_one_as_base() {
powd_test_sets_as_exponent(1.0, ALL, 1.0);
}
#[test] fn powd_nan_inputs() { // NAN as the base: // (NAN ^ anything *but 0* should be NAN)
powd_test_sets_as_exponent(f64::NAN, &ALL[2..], f64::NAN);
// NAN as the exponent: // (anything *but 1* ^ NAN should be NAN)
powd_test_sets_as_base(&ALL[..(ALL.len() - 2)], f64::NAN, f64::NAN);
}
#[test] fn powd_infinity_as_base() { // Positive Infinity as the base: // (+Infinity ^ positive anything but 0 and NAN should be +Infinity)
powd_test_sets_as_exponent(f64::INFINITY, &POS[1..], f64::INFINITY);
// (+Infinity ^ negative anything except 0 and NAN should be 0.0)
powd_test_sets_as_exponent(f64::INFINITY, &NEG[1..], 0.0);
// Negative Infinity as the base: // (-Infinity ^ positive odd ints should be -Infinity)
powd_test_sets_as_exponent(f64::NEG_INFINITY, &[POS_ODDS], f64::NEG_INFINITY);
// (-Infinity ^ anything but odd ints should be == -0 ^ (-anything)) // We can lump in pos/neg odd ints here because they don't seem to // cause panics (div by zero) in release mode (I think).
powd_test_sets(ALL, &|v: f64| libm::powd(f64::NEG_INFINITY, v), &|v: f64| libm::powd(-0.0, -v));
}
#[test] fn infinity_as_exponent() { // Positive/Negative base greater than 1: // (pos/neg > 1 ^ Infinity should be Infinity - note this excludes NAN as the base)
powd_test_sets_as_base(&ALL[5..(ALL.len() - 2)], f64::INFINITY, f64::INFINITY);
// (pos/neg > 1 ^ -Infinity should be 0.0)
powd_test_sets_as_base(&ALL[5..ALL.len() - 2], f64::NEG_INFINITY, 0.0);
// Positive/Negative base less than 1: let base_below_one = &[POS_ZERO, NEG_ZERO, NEG_SMALL_FLOATS, POS_SMALL_FLOATS];
// (pos/neg < 1 ^ Infinity should be 0.0 - this also excludes NAN as the base)
powd_test_sets_as_base(base_below_one, f64::INFINITY, 0.0);
// (pos/neg < 1 ^ -Infinity should be Infinity)
powd_test_sets_as_base(base_below_one, f64::NEG_INFINITY, f64::INFINITY);
// Positive/Negative 1 as the base: // (pos/neg 1 ^ Infinity should be 1)
powd_test_sets_as_base(&[NEG_ONE, POS_ONE], f64::INFINITY, 1.0);
// (pos/neg 1 ^ -Infinity should be 1)
powd_test_sets_as_base(&[NEG_ONE, POS_ONE], f64::NEG_INFINITY, 1.0);
}
#[test] fn powd_zero_as_base() { // Positive Zero as the base: // (+0 ^ anything positive but 0 and NAN should be +0)
powd_test_sets_as_exponent(0.0, &POS[1..], 0.0);
// (+0 ^ anything negative but 0 and NAN should be Infinity) // (this should panic because we're dividing by zero)
powd_test_sets_as_exponent(0.0, &NEG[1..], f64::INFINITY);
// Negative Zero as the base: // (-0 ^ anything positive but 0, NAN, and odd ints should be +0)
powd_test_sets_as_exponent(-0.0, &POS[3..], 0.0);
// (-0 ^ anything negative but 0, NAN, and odd ints should be Infinity) // (should panic because of divide by zero)
powd_test_sets_as_exponent(-0.0, &NEG[3..], f64::INFINITY);
// (-0 ^ positive odd ints should be -0)
powd_test_sets_as_exponent(-0.0, &[POS_ODDS], -0.0);
// (-0 ^ negative odd ints should be -Infinity) // (should panic because of divide by zero)
powd_test_sets_as_exponent(-0.0, &[NEG_ODDS], f64::NEG_INFINITY);
}
#[test] fn special_cases() { // One as the exponent: // (anything ^ 1 should be anything - i.e. the base)
powd_test_sets(ALL, &|v: f64| libm::powd(v, 1.0), &|v: f64| v);
// Negative One as the exponent: // (anything ^ -1 should be 1/anything)
powd_test_sets(ALL, &|v: f64| libm::powd(v, -1.0), &|v: f64| 1.0 / v);
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs #[test] fn fabsd_spec_test() {
assert!(libm::fabsd(f64::NAN).is_nan()); for f in [0.0, -0.0].iter().copied() {
assert_eq!(libm::fabsd(f), 0.0);
} for f in [f64::INFINITY, f64::NEG_INFINITY].iter().copied() {
assert_eq!(libm::fabsd(f), f64::INFINITY);
}
}
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/sqrt #[test] fn sqrtd_spec_test() { // Not Asserted: FE_INVALID exception is raised if argument is negative.
assert!(libm::sqrtd(-1.0).is_nan());
assert!(libm::sqrtd(f64::NAN).is_nan()); for f in [0.0, -0.0, f64::INFINITY].iter().copied() {
assert_eq!(libm::sqrtd(f), f);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-23)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.