1 // Copyright 2018 Ulf Adams
2 //
3 // The contents of this file may be used under the terms of the Apache License,
4 // Version 2.0.
5 //
6 //    (See accompanying file LICENSE-Apache or copy at
7 //     http://www.apache.org/licenses/LICENSE-2.0)
8 //
9 // Alternatively, the contents of this file may be used under the terms of
10 // the Boost Software License, Version 1.0.
11 //    (See accompanying file LICENSE-Boost or copy at
12 //     https://www.boost.org/LICENSE_1_0.txt)
13 //
14 // Unless required by applicable law or agreed to in writing, this software
15 // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 // KIND, either express or implied.
17 
18 #include "ryu/common.h"
19 
__pow5bits(const int32_t e)20 int32_t __pow5bits(const int32_t e) {
21   // This approximation works up to the point that the multiplication overflows at e = 3529.
22   // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater
23   // than 2^9297.
24   assert(e >= 0);
25   assert(e <= 3528);
26   return (int32_t) (((((uint32_t) e) * 1217359) >> 19) + 1);
27 }
28 
29