implements the Grisu2 algorithm for binary to decimal floating-point conversion. More...
Classes | |
struct | boundaries |
struct | cached_power |
struct | diyfp |
Functions | |
JSON_HEDLEY_RETURNS_NON_NULL char * | append_exponent (char *buf, int e) |
appends a decimal representation of e to buf More... | |
template<typename FloatType > | |
boundaries | compute_boundaries (FloatType value) |
Compute the (normalized) diyfp representing the input number 'value' and its boundaries. More... | |
int | find_largest_pow10 (const std::uint32_t n, std::uint32_t &pow10) |
For n != 0, returns k, such that pow10 := 10^(k-1) <= n < 10^k. More... | |
JSON_HEDLEY_RETURNS_NON_NULL char * | format_buffer (char *buf, int len, int decimal_exponent, int min_exp, int max_exp) |
prettify v = buf * 10^decimal_exponent More... | |
cached_power | get_cached_power_for_binary_exponent (int e) |
For a normalized diyfp w = f * 2^e, this function returns a (normalized) cached power-of-ten c = f_c * 2^e_c, such that the exponent of the product w * c satisfies (Definition 3.2 from [1]) More... | |
void | grisu2 (char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus) |
v = buf * 10^decimal_exponent len is the length of the buffer (number of decimal digits) The buffer must be large enough, i.e. More... | |
template<typename FloatType > | |
void | grisu2 (char *buf, int &len, int &decimal_exponent, FloatType value) |
v = buf * 10^decimal_exponent len is the length of the buffer (number of decimal digits) The buffer must be large enough, i.e. More... | |
void | grisu2_digit_gen (char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus) |
Generates V = buffer * 10^decimal_exponent, such that M- <= V <= M+. More... | |
void | grisu2_round (char *buf, int len, std::uint64_t dist, std::uint64_t delta, std::uint64_t rest, std::uint64_t ten_k) |
template<typename Target , typename Source > | |
Target | reinterpret_bits (const Source source) |
Variables | |
constexpr int | kAlpha = -60 |
constexpr int | kGamma = -32 |
implements the Grisu2 algorithm for binary to decimal floating-point conversion.
This implementation is a slightly modified version of the reference implementation which may be obtained from http://florian.loitsch.com/publications (bench.tar.gz).
The code is distributed under the MIT license, Copyright (c) 2009 Florian Loitsch.
For a detailed description of the algorithm see:
[1] Loitsch, "Printing Floating-Point Numbers Quickly and Accurately with Integers", Proceedings of the ACM SIGPLAN 2010 Conference on Programming Language Design and Implementation, PLDI 2010 [2] Burger, Dybvig, "Printing Floating-Point Numbers Quickly and Accurately", Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation, PLDI 1996
|
inline |
appends a decimal representation of e to buf
Definition at line 15336 of file json.h.
References JSON_ASSERT, and bianchi11ax::k.
Referenced by format_buffer().
boundaries nlohmann::detail::dtoa_impl::compute_boundaries | ( | FloatType | value | ) |
Compute the (normalized) diyfp representing the input number 'value' and its boundaries.
Definition at line 14595 of file json.h.
References nlohmann::detail::dtoa_impl::diyfp::e, E, nlohmann::detail::dtoa_impl::diyfp::f, JSON_ASSERT, nlohmann::detail::dtoa_impl::diyfp::normalize(), nlohmann::detail::dtoa_impl::diyfp::normalize_to(), and nlohmann::detail::value.
Referenced by grisu2().
|
inline |
For n != 0, returns k, such that pow10 := 10^(k-1) <= n < 10^k.
For n == 0, returns 1 and sets pow10 := 1.
Definition at line 14898 of file json.h.
Referenced by grisu2_digit_gen().
|
inline |
prettify v = buf * 10^decimal_exponent
If v is in the range [10^min_exp, 10^max_exp) it will be printed in fixed-point notation. Otherwise it will be printed in exponential notation.
Definition at line 15388 of file json.h.
References append_exponent(), JSON_ASSERT, and bianchi11ax::k.
Referenced by nlohmann::detail::to_chars().
|
inline |
For a normalized diyfp w = f * 2^e, this function returns a (normalized) cached power-of-ten c = f_c * 2^e_c, such that the exponent of the product w * c satisfies (Definition 3.2 from [1])
alpha <= e_c + e + q <= gamma.
Definition at line 14734 of file json.h.
References nlohmann::detail::dtoa_impl::cached_power::e, f(), JSON_ASSERT, bianchi11ax::k, kAlpha, and kGamma.
Referenced by grisu2().
|
inline |
v = buf * 10^decimal_exponent len is the length of the buffer (number of decimal digits) The buffer must be large enough, i.e.
>= max_digits10.
Definition at line 15236 of file json.h.
References nlohmann::detail::dtoa_impl::diyfp::e, nlohmann::detail::dtoa_impl::cached_power::e, nlohmann::detail::dtoa_impl::diyfp::f, nlohmann::detail::dtoa_impl::cached_power::f, get_cached_power_for_binary_exponent(), grisu2_digit_gen(), JSON_ASSERT, nlohmann::detail::dtoa_impl::cached_power::k, and nlohmann::detail::dtoa_impl::diyfp::mul().
Referenced by grisu2(), and nlohmann::detail::to_chars().
void nlohmann::detail::dtoa_impl::grisu2 | ( | char * | buf, |
int & | len, | ||
int & | decimal_exponent, | ||
FloatType | value | ||
) |
v = buf * 10^decimal_exponent len is the length of the buffer (number of decimal digits) The buffer must be large enough, i.e.
>= max_digits10.
Definition at line 15296 of file json.h.
References compute_boundaries(), grisu2(), JSON_ASSERT, nlohmann::detail::dtoa_impl::diyfp::kPrecision, nlohmann::detail::dtoa_impl::boundaries::minus, nlohmann::detail::dtoa_impl::boundaries::plus, nlohmann::detail::value, and nlohmann::detail::dtoa_impl::boundaries::w.
|
inline |
Generates V = buffer * 10^decimal_exponent, such that M- <= V <= M+.
M- and M+ must be normalized and share the same exponent -60 <= e <= -32.
Definition at line 14995 of file json.h.
References nlohmann::detail::dtoa_impl::diyfp::e, nlohmann::detail::dtoa_impl::diyfp::f, find_largest_pow10(), grisu2_round(), JSON_ASSERT, bianchi11ax::k, kAlpha, kGamma, max, and nlohmann::detail::dtoa_impl::diyfp::sub().
Referenced by grisu2().
|
inline |
Definition at line 14954 of file json.h.
References JSON_ASSERT.
Referenced by grisu2_digit_gen().
Target nlohmann::detail::dtoa_impl::reinterpret_bits | ( | const Source | source | ) |
|
constexpr |
Definition at line 14717 of file json.h.
Referenced by get_cached_power_for_binary_exponent(), and grisu2_digit_gen().
|
constexpr |
Definition at line 14718 of file json.h.
Referenced by get_cached_power_for_binary_exponent(), and grisu2_digit_gen().