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::cast_lossless,
24 clippy::cast_possible_truncation,
25 clippy::unreadable_literal
26)]
27
28#[path = "../src/d2s_intrinsics.rs"]
29mod d2s_intrinsics;
30
31use d2s_intrinsics::pow5_factor;
32
33#[test]
34fn test_pow5_factor() {
35 assert_eq!(0, pow5_factor(1));
36 assert_eq!(0, pow5_factor(2));
37 assert_eq!(0, pow5_factor(3));
38 assert_eq!(0, pow5_factor(4));
39 assert_eq!(1, pow5_factor(5));
40 assert_eq!(0, pow5_factor(6));
41 assert_eq!(0, pow5_factor(7));
42 assert_eq!(0, pow5_factor(8));
43 assert_eq!(0, pow5_factor(9));
44 assert_eq!(1, pow5_factor(10));
45
46 assert_eq!(0, pow5_factor(12));
47 assert_eq!(0, pow5_factor(14));
48 assert_eq!(0, pow5_factor(16));
49 assert_eq!(0, pow5_factor(18));
50 assert_eq!(1, pow5_factor(20));
51
52 assert_eq!(2, pow5_factor(5 * 5));
53 assert_eq!(3, pow5_factor(5 * 5 * 5));
54 assert_eq!(4, pow5_factor(5 * 5 * 5 * 5));
55 assert_eq!(5, pow5_factor(5 * 5 * 5 * 5 * 5));
56 assert_eq!(6, pow5_factor(5 * 5 * 5 * 5 * 5 * 5));
57 assert_eq!(7, pow5_factor(5 * 5 * 5 * 5 * 5 * 5 * 5));
58 assert_eq!(8, pow5_factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5));
59 assert_eq!(9, pow5_factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5));
60 assert_eq!(10, pow5_factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5));
61
62 assert_eq!(0, pow5_factor(42));
63 assert_eq!(1, pow5_factor(42 * 5));
64 assert_eq!(2, pow5_factor(42 * 5 * 5));
65 assert_eq!(3, pow5_factor(42 * 5 * 5 * 5));
66 assert_eq!(4, pow5_factor(42 * 5 * 5 * 5 * 5));
67 assert_eq!(5, pow5_factor(42 * 5 * 5 * 5 * 5 * 5));
68
69 assert_eq!(27, pow5_factor(7450580596923828125)); // 5^27, largest power of 5 < 2^64.
70 assert_eq!(1, pow5_factor(18446744073709551615)); // 2^64 - 1, largest multiple of 5 < 2^64.
71 assert_eq!(0, pow5_factor(18446744073709551614)); // 2^64 - 2, largest non-multiple of 5 < 2^64.
72}
73