Copyright 2020 Junekey Jeon Copyright 2020 Alexander Bolz
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
char* output_end = Dtoa(buffer, value);
Converts the given double-precision number into decimal form and stores the result in the given buffer.
The buffer must be large enough, i.e. >= DtoaMinBufferLength. The output format is similar to printf("%g"). The output is _not null-terminted.
The output is optimal, i.e. the output string
- rounds back to the input number when read in (using round-to-nearest-even)
- is as short as possible,
- is as close to the input number as possible.
Note: This function may temporarily write up to DtoaMinBufferLength characters into the buffer.
This file contains an implementation of Junekey Jeon's Dragonbox algorithm.
It is a simplified version of the reference implementation found here: https://github.com/jk-jeon/dragonbox
The reference implementation also works with single-precision floating-point numbers and has options to configure the rounding mode.
namespace Returns floor(x / 2^n).
Technically, right-shift of negative integers is implementation defined... Should easily be optimized into SAR (or equivalent) instruction.
Returns whether value is divisible by 2^e2Returns whether value is divisible by 5^e5Returns (x * y) / 2^128Consts
dtoaMinBufferLength: cint = 64
- Source Edit
exponentBias: int32 = 1075'i32
- Source Edit
exponentMask: BitsType = 9218868437227405312'u64
- Source Edit
maxIeeeExponent: BitsType = 2047'u
- Source Edit
significandMask: BitsType = 4503599627370495'u64
- Source Edit
significandSize: int32 = 53
- Source Edit
Procs
proc computePow10(k: int32): uint64x2 {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc constructDouble(bits: BitsType): Double {....raises: [], tags: [], forbids: [].}
- Source Edit
proc constructDouble(value: ValueType): Double {....raises: [], tags: [], forbids: [].}
- Source Edit
proc decimalLength(v: uint64): int {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc floorLog2Pow10(e: int32): int32 {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc floorLog10Pow2(e: int32): int32 {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc floorLog10ThreeQuartersPow2(e: int32): int32 {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc physicalExponent(this: Double): BitsType {.noSideEffect, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc physicalSignificand(this: Double): BitsType {.noSideEffect, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc toDecimal64(ieeeSignificand: uint64; ieeeExponent: uint64): FloatingDecimal64 {. inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc toDecimal64AsymmetricInterval(e2: int32): FloatingDecimal64 {.inline, ...raises: [], tags: [], forbids: [].}
- NB: accept_lower_endpoint = true accept_upper_endpoint = true Source Edit