implements the Grisu2 algorithm for binary to decimal floating-point conversion. More...
Classes | |
| struct | boundaries |
| struct | cached_power |
| struct | diyfp |
Functions | |
| __attribute__ ((__nonnull__(1))) inline void grisu2(char *buf | |
| 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 > | |
| __attribute__ ((__nonnull__(1))) void grisu2(char *buf | |
| 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... | |
| return | append_exponent (buf, n - 1) |
| const diyfp | c_minus_k (cached.f, cached.e) |
| 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... | |
| 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... | |
| grisu2 (buf, len, decimal_exponent, w.minus, w.w, w.plus) | |
| grisu2_digit_gen (buf, len, decimal_exponent, M_minus, w, M_plus) | |
| 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) |
| static_cast< bool >(e< 1000) ? void(0) | if (e< 0) |
| if (k<=n &&n<=max_exp) | |
| if (k==1) | |
| template<typename Target , typename Source > | |
| Target | reinterpret_bits (const Source source) |
| static_cast< bool > (static_cast< bool >(value > 0) ? void(0) :__assert_fail("value > 0", __builtin_FILE(), __builtin_LINE(), __extension__ __PRETTY_FUNCTION__)) | |
Variables | |
| * | buf = static_cast<char>('0' + k / 10) |
| static_cast< bool >(m_plus.e==v.e) ? void(0) const cached_power | cached = get_cached_power_for_binary_exponent(m_plus.e) |
| int int & | decimal_exponent = -cached.k |
| int | e |
| else | |
| auto | k = static_cast<std::uint32_t>(e) |
| constexpr int | kAlpha = -60 |
| constexpr int | kGamma = -32 |
| int & | len |
| int int diyfp | m_minus |
| const diyfp | M_minus (w_minus.f+1, w_minus.e) |
| int int diyfp diyfp diyfp | m_plus |
| const diyfp | M_plus (w_plus.f - 1, w_plus.e) |
| int int int int | max_exp |
| int int int | min_exp |
| const int | n = len + decimal_exponent |
| int int diyfp diyfp | v |
| int int FloatType | value |
| const diyfp | w = diyfp::mul(v, c_minus_k) |
| const diyfp | w_minus = diyfp::mul(m_minus, c_minus_k) |
| const diyfp | w_plus = diyfp::mul(m_plus, c_minus_k) |
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
| nlohmann::detail::dtoa_impl::__attribute__ | ( | (__nonnull__(1)) | ) |
v = buf * 10^decimal_exponent len is the length of the buffer (number of decimal digits) The buffer must be large enough, i.e.
prettify v = buf * 10^decimal_exponent
appends a decimal representation of e to buf
>= max_digits10.
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.
| nlohmann::detail::dtoa_impl::__attribute__ | ( | (__nonnull__(1)) | ) |
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.
| boundaries nlohmann::detail::dtoa_impl::compute_boundaries | ( | FloatType | value | ) |
Compute the (normalized) diyfp representing the input number 'value' and its boundaries.
| int nlohmann::detail::dtoa_impl::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.
For n == 0, returns 1 and sets pow10 := 1.
| cached_power nlohmann::detail::dtoa_impl::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])
alpha <= e_c + e + q <= gamma.
| void nlohmann::detail::dtoa_impl::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+.
M- and M+ must be normalized and share the same exponent -60 <= e <= -32.
References nlohmann::detail::array.
| int nlohmann::detail::dtoa_impl::e |
| nlohmann::detail::dtoa_impl::else |