Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/serde_json/tests/lexical/   (Fast Lexical Analyzer Version 2.6©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  algorithm.rs

  Sprache: Rust
 

// Adapted from https://github.com/Alexhuszagh/rust-lexical.

use crate::lexical::algorithm::*;
use crate::lexical::num::Float;

#[test]
fn float_fast_path_test() {
    // valid
    let mantissa = (1 << f32::MANTISSA_SIZE) - 1;
    let (min_exp, max_exp) = f32::exponent_limit();
    for exp in min_exp..=max_exp {
        let f = fast_path::<f32>(mantissa, exp);
        assert!(f.is_some(), "should be valid {:?}.", (mantissa, exp));
    }

    // Check slightly above valid exponents
    let f = fast_path::<f32>(12315);
    assert_eq!(f, Some(1.23e+17));

    // Exponent is 1 too high, pushes over the mantissa.
    let f = fast_path::<f32>(12316);
    assert!(f.is_none());

    // Mantissa is too large, checked_mul should overflow.
    let f = fast_path::<f32>(mantissa, 11);
    assert!(f.is_none());

    // invalid exponents
    let (min_exp, max_exp) = f32::exponent_limit();
    let f = fast_path::<f32>(mantissa, min_exp - 1);
    assert!(f.is_none(), "exponent under min_exp");

    let f = fast_path::<f32>(mantissa, max_exp + 1);
    assert!(f.is_none(), "exponent above max_exp");
}

#[test]
fn double_fast_path_test() {
    // valid
    let mantissa = (1 << f64::MANTISSA_SIZE) - 1;
    let (min_exp, max_exp) = f64::exponent_limit();
    for exp in min_exp..=max_exp {
        let f = fast_path::<f64>(mantissa, exp);
        assert!(f.is_some(), "should be valid {:?}.", (mantissa, exp));
    }

    // invalid exponents
    let (min_exp, max_exp) = f64::exponent_limit();
    let f = fast_path::<f64>(mantissa, min_exp - 1);
    assert!(f.is_none(), "exponent under min_exp");

    let f = fast_path::<f64>(mantissa, max_exp + 1);
    assert!(f.is_none(), "exponent above max_exp");

    assert_eq!(
        Some(0.04628372940652459),
        fast_path::<f64>(4628372940652459, -17)
    );
    assert_eq!(None, fast_path::<f64>(26383446160308229, -272));
}

#[test]
fn moderate_path_test() {
    let (f, valid) = moderate_path::<f64>(1234567890, -1false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.0);

    let (f, valid) = moderate_path::<f64>(1234567891, -1false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.1);

    let (f, valid) = moderate_path::<f64>(12345678912, -2false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.12);

    let (f, valid) = moderate_path::<f64>(123456789123, -3false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.123);

    let (f, valid) = moderate_path::<f64>(1234567891234, -4false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.1234);

    let (f, valid) = moderate_path::<f64>(12345678912345, -5false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.12345);

    let (f, valid) = moderate_path::<f64>(123456789123456, -6false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.123456);

    let (f, valid) = moderate_path::<f64>(1234567891234567, -7false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.1234567);

    let (f, valid) = moderate_path::<f64>(12345678912345679, -8false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 123456789.12345679);

    let (f, valid) = moderate_path::<f64>(4628372940652459, -17false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 0.04628372940652459);

    let (f, valid) = moderate_path::<f64>(26383446160308229, -272false);
    assert!(valid, "should be valid");
    assert_eq!(f.into_float::<f64>(), 2.6383446160308229e-256);

    let (_, valid) = moderate_path::<f64>(26383446160308230, -272false);
    assert!(!valid, "should be invalid");
}

Messung V0.5 in Prozent
C=80 H=92 G=86

¤ Dauer der Verarbeitung: 0.26 Sekunden  (vorverarbeitet am  2026-06-27) ¤

*© 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.