Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/rayon/src/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  math.rs

  Sprache: Rust
 

use std::ops::{Bound, Range, RangeBounds};

/// Divide `n` by `divisor`, and round up to the nearest integer
/// if not evenly divisible.
#[inline]
pub(superfn div_round_up(n: usize, divisor: usize) -> usize {
    debug_assert!(divisor != 0"Division by zero!");
    if n == 0 {
        0
    } else {
        (n - 1) / divisor + 1
    }
}

/// Normalize arbitrary `RangeBounds` to a `Range`
pub(superfn simplify_range(range: impl RangeBounds<usize>, len: usize) -> Range<usize> {
    let start = match range.start_bound() {
        Bound::Unbounded => 0,
        Bound::Included(&i) if i <= len => i,
        Bound::Excluded(&i) if i < len => i + 1,
        bound => panic!("range start {:?} should be <= length {}", bound, len),
    };
    let end = match range.end_bound() {
        Bound::Unbounded => len,
        Bound::Excluded(&i) if i <= len => i,
        Bound::Included(&i) if i < len => i + 1,
        bound => panic!("range end {:?} should be <= length {}", bound, len),
    };
    if start > end {
        panic!(
            "range start {:?} should be <= range end {:?}",
            range.start_bound(),
            range.end_bound()
        );
    }
    start..end
}

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

    #[test]
    fn check_div_round_up() {
        assert_eq!(0, div_round_up(05));
        assert_eq!(1, div_round_up(55));
        assert_eq!(1, div_round_up(15));
        assert_eq!(2, div_round_up(32));
        assert_eq!(
            usize::max_value() / 2 + 1,
            div_round_up(usize::max_value(), 2)
        );
    }
}

Messung V0.5 in Prozent
C=51 H=94 G=75

¤ Dauer der Verarbeitung: 0.6 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

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.