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#![allow(
23 clippy::approx_constant,
24 clippy::cast_possible_wrap,
25 clippy::cast_sign_loss,
26 clippy::excessive_precision,
27 clippy::unreadable_literal,
28 clippy::wildcard_imports
29)]
30
31#[path = "../src/common.rs"]
32mod common;
33
34use common::*;
35
36#[test]
37fn test_decimal_length9() {
38 assert_eq!(1, decimal_length9(0));
39 assert_eq!(1, decimal_length9(1));
40 assert_eq!(1, decimal_length9(9));
41 assert_eq!(2, decimal_length9(10));
42 assert_eq!(2, decimal_length9(99));
43 assert_eq!(3, decimal_length9(100));
44 assert_eq!(3, decimal_length9(999));
45 assert_eq!(9, decimal_length9(999999999));
46}
47
48#[test]
49fn test_ceil_log2_pow5() {
50 assert_eq!(1, ceil_log2_pow5(0));
51 assert_eq!(3, ceil_log2_pow5(1));
52 assert_eq!(5, ceil_log2_pow5(2));
53 assert_eq!(7, ceil_log2_pow5(3));
54 assert_eq!(10, ceil_log2_pow5(4));
55 assert_eq!(8192, ceil_log2_pow5(3528));
56}
57
58#[test]
59fn test_log10_pow2() {
60 assert_eq!(0, log10_pow2(0));
61 assert_eq!(0, log10_pow2(1));
62 assert_eq!(0, log10_pow2(2));
63 assert_eq!(0, log10_pow2(3));
64 assert_eq!(1, log10_pow2(4));
65 assert_eq!(496, log10_pow2(1650));
66}
67
68#[test]
69fn test_log10_pow5() {
70 assert_eq!(0, log10_pow5(0));
71 assert_eq!(0, log10_pow5(1));
72 assert_eq!(1, log10_pow5(2));
73 assert_eq!(2, log10_pow5(3));
74 assert_eq!(2, log10_pow5(4));
75 assert_eq!(1831, log10_pow5(2620));
76}
77
78#[test]
79fn test_float_to_bits() {
80 assert_eq!(0, 0.0_f32.to_bits());
81 assert_eq!(0x40490fda, 3.1415926_f32.to_bits());
82}
83
84#[test]
85fn test_double_to_bits() {
86 assert_eq!(0, 0.0_f64.to_bits());
87 assert_eq!(
88 0x400921FB54442D18,
89 3.1415926535897932384626433_f64.to_bits(),
90 );
91}
92