Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/libm/src/math/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 635 B image not shown  

Quelle  round.rs   Sprache: unbekannt

 
use super::copysign;
use super::trunc;
use core::f64;

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn round(x: f64) -> f64 {
    trunc(x + copysign(0.5 - 0.25 * f64::EPSILON, x))
}

#[cfg(test)]
mod tests {
    use super::round;

    #[test]
    fn negative_zero() {
        assert_eq!(round(-0.0_f64).to_bits(), (-0.0_f64).to_bits());
    }

    #[test]
    fn sanity_check() {
        assert_eq!(round(-1.0), -1.0);
        assert_eq!(round(2.8), 3.0);
        assert_eq!(round(-0.5), -1.0);
        assert_eq!(round(0.5), 1.0);
        assert_eq!(round(-1.5), -2.0);
        assert_eq!(round(1.5), 2.0);
    }
}

[ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet)  ]