File: test.rs

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (38 lines) | stat: -rw-r--r-- 1,185 bytes parent folder | download | duplicates (48)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extern crate dtoa;

use std::str;

#[test]
fn test_f64() {
    test_write(1.234e20f64, "123400000000000000000.0");
    test_write(1.234e21f64, "1.234e21");
    test_write(2.71828f64, "2.71828");
    test_write(0.0f64, "0.0");
    test_write(-0.0f64, "-0.0");
    test_write(1.1e128f64, "1.1e128");
    test_write(1.1e-64f64, "1.1e-64");
    test_write(2.718281828459045f64, "2.718281828459045");
    test_write(5e-324f64, "5e-324");
    test_write(::std::f64::MAX, "1.7976931348623157e308");
}

#[test]
fn test_f32() {
    test_write(1.234e20f32, "123400000000000000000.0");
    test_write(1.234e21f32, "1.234e21");
    test_write(2.71828f32, "2.71828");
    test_write(0.0f32, "0.0");
    test_write(-0.0f32, "-0.0");
    test_write(1.1e32f32, "1.1e32");
    test_write(1.1e-32f32, "1.1e-32");
    test_write(2.7182817f32, "2.7182817");
    test_write(1e-45f32, "1e-45");
    test_write(::std::f32::MAX, "3.4028235e38");
}

fn test_write<F: dtoa::Floating>(value: F, expected: &'static str) {
    let mut buf = [b'\0'; 30];
    let len = dtoa::write(&mut buf[..], value).unwrap();
    let result = str::from_utf8(&buf[..len]).unwrap();
    assert_eq!(result, expected.to_string());
}