• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Translated from C to Rust. The original C code can be found at
2 // https://github.com/ulfjack/ryu and carries the following license:
3 //
4 // Copyright 2018 Ulf Adams
5 //
6 // The contents of this file may be used under the terms of the Apache License,
7 // Version 2.0.
8 //
9 //    (See accompanying file LICENSE-Apache or copy at
10 //     http://www.apache.org/licenses/LICENSE-2.0)
11 //
12 // Alternatively, the contents of this file may be used under the terms of
13 // the Boost Software License, Version 1.0.
14 //    (See accompanying file LICENSE-Boost or copy at
15 //     https://www.boost.org/LICENSE_1_0.txt)
16 //
17 // Unless required by applicable law or agreed to in writing, this software
18 // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 // KIND, either express or implied.
20 
21 #![allow(dead_code)]
22 
23 #[path = "../src/common.rs"]
24 mod common;
25 
26 use common::*;
27 
28 #[test]
test_decimal_length9()29 fn test_decimal_length9() {
30     assert_eq!(1, decimal_length9(0));
31     assert_eq!(1, decimal_length9(1));
32     assert_eq!(1, decimal_length9(9));
33     assert_eq!(2, decimal_length9(10));
34     assert_eq!(2, decimal_length9(99));
35     assert_eq!(3, decimal_length9(100));
36     assert_eq!(3, decimal_length9(999));
37     assert_eq!(9, decimal_length9(999999999));
38 }
39 
40 #[test]
test_ceil_log2_pow5()41 fn test_ceil_log2_pow5() {
42     assert_eq!(1, ceil_log2_pow5(0));
43     assert_eq!(3, ceil_log2_pow5(1));
44     assert_eq!(5, ceil_log2_pow5(2));
45     assert_eq!(7, ceil_log2_pow5(3));
46     assert_eq!(10, ceil_log2_pow5(4));
47     assert_eq!(8192, ceil_log2_pow5(3528));
48 }
49 
50 #[test]
test_log10_pow2()51 fn test_log10_pow2() {
52     assert_eq!(0, log10_pow2(0));
53     assert_eq!(0, log10_pow2(1));
54     assert_eq!(0, log10_pow2(2));
55     assert_eq!(0, log10_pow2(3));
56     assert_eq!(1, log10_pow2(4));
57     assert_eq!(496, log10_pow2(1650));
58 }
59 
60 #[test]
test_log10_pow5()61 fn test_log10_pow5() {
62     assert_eq!(0, log10_pow5(0));
63     assert_eq!(0, log10_pow5(1));
64     assert_eq!(1, log10_pow5(2));
65     assert_eq!(2, log10_pow5(3));
66     assert_eq!(2, log10_pow5(4));
67     assert_eq!(1831, log10_pow5(2620));
68 }
69 
70 #[test]
test_float_to_bits()71 fn test_float_to_bits() {
72     assert_eq!(0, 0.0_f32.to_bits());
73     assert_eq!(0x40490fda, 3.1415926_f32.to_bits());
74 }
75 
76 #[test]
test_double_to_bits()77 fn test_double_to_bits() {
78     assert_eq!(0, 0.0_f64.to_bits());
79     assert_eq!(
80         0x400921FB54442D18,
81         3.1415926535897932384626433_f64.to_bits(),
82     );
83 }
84