ryu/common

Copyright 2018 Ulf Adams

The contents of this file may be used under the terms of the Apache License, Version 2.0.

(See accompanying file LICENSE-Apache or copy at
http://www.apache.org/licenses/LICENSE-2.0)

Alternatively, the contents of this file may be used under the terms of

the Boost Software License, Version 1.0.
(See accompanying file LICENSE-Boost or copy at
https://www.boost.org/LICENSE_1_0.txt)

Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Procs

proc decimalLength9(v: uint32): uint32 {...}{.inline, raises: [], tags: [].}
Returns the number of decimal digits in v, which must not contain more than 9 digits. Function precondition: v is not a 10-digit number.
proc log2pow5(e: int32): int32 {...}{.inline, raises: [], tags: [].}
Returns e == 0 ? 1 : [log_2(5^e)]; requires 0 <= e <= 3528. This approximation works up to the point that the multiplication overflows at e = 3529. If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater than 2^9297.
proc pow5bits(e: int32): int32 {...}{.inline, raises: [], tags: [].}
Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 3528. This approximation works up to the point that the multiplication overflows at e = 3529. If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater than 2^9297.
proc ceil_log2pow5(e: int32): int32 {...}{.inline, raises: [], tags: [].}
Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 3528.
proc log10Pow2(e: int32): uint32 {...}{.inline, raises: [], tags: [].}
Returns floor(log_10(2^e)); requires 0 <= e <= 1650. The first value this approximation fails for is 2^1651 which is just greater than 10^297.
proc log10Pow5(e: int32): uint32 {...}{.inline, raises: [], tags: [].}
Returns floor(log_10(5^e)); requires 0 <= e <= 2620. The first value this approximation fails for is 5^2621 which is just greater than 10^1832.
proc copySpecialStr(buff: var string; sign, exponent, mantissa: bool): int {...}{.raises: [],
    tags: [].}
proc floatToBits(f: float32): uint32 {...}{.inline, raises: [], tags: [].}
proc floatToBits(f: float64): uint64 {...}{.inline, raises: [], tags: [].}
proc doubleToBits(f: float64): uint64 {...}{.inline, raises: [], tags: [].}