Classes | Functions | Variables
nlohmann::detail::dtoa_impl Namespace Reference

implements the Grisu2 algorithm for binary to decimal floating-point conversion. More...

Classes

struct  boundaries
 
struct  cached_power
 
struct  diyfp
 

Functions

char * append_exponent (char *buf, int e)
 appends a decimal representation of e to buf More...
 
template<typename FloatType >
boundaries compute_boundaries (FloatType value)
 
int find_largest_pow10 (const uint32_t n, uint32_t &pow10)
 
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)
 
void grisu2 (char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
 
template<typename FloatType >
void grisu2 (char *buf, int &len, int &decimal_exponent, FloatType value)
 
void grisu2_digit_gen (char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
 
void grisu2_round (char *buf, int len, uint64_t dist, uint64_t delta, uint64_t rest, uint64_t ten_k)
 
template<typename Target , typename Source >
Target reinterpret_bits (const Source source)
 

Variables

constexpr int kAlpha = -60
 
constexpr int kGamma = -32
 

Detailed Description

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

Function Documentation

char* nlohmann::detail::dtoa_impl::append_exponent ( char *  buf,
int  e 
)
inline

appends a decimal representation of e to buf

Returns
a pointer to the element following the exponent.
Precondition
-1000 < e < 1000

Definition at line 8066 of file json.hpp.

template<typename FloatType >
boundaries nlohmann::detail::dtoa_impl::compute_boundaries ( FloatType  value)

Compute the (normalized) diyfp representing the input number 'value' and its boundaries.

Precondition
value must be finite and positive

Definition at line 7329 of file json.hpp.

int nlohmann::detail::dtoa_impl::find_largest_pow10 ( const uint32_t  n,
uint32_t &  pow10 
)
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 7632 of file json.hpp.

char* nlohmann::detail::dtoa_impl::format_buffer ( char *  buf,
int  len,
int  decimal_exponent,
int  min_exp,
int  max_exp 
)
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.

Precondition
min_exp < 0
max_exp > 0

Definition at line 8116 of file json.hpp.

cached_power nlohmann::detail::dtoa_impl::get_cached_power_for_binary_exponent ( int  e)
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 7468 of file json.hpp.

void nlohmann::detail::dtoa_impl::grisu2 ( char *  buf,
int &  len,
int &  decimal_exponent,
diyfp  m_minus,
diyfp  v,
diyfp  m_plus 
)
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 7969 of file json.hpp.

template<typename FloatType >
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 8028 of file json.hpp.

void nlohmann::detail::dtoa_impl::grisu2_digit_gen ( char *  buffer,
int &  length,
int &  decimal_exponent,
diyfp  M_minus,
diyfp  w,
diyfp  M_plus 
)
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 7729 of file json.hpp.

void nlohmann::detail::dtoa_impl::grisu2_round ( char *  buf,
int  len,
uint64_t  dist,
uint64_t  delta,
uint64_t  rest,
uint64_t  ten_k 
)
inline

Definition at line 7688 of file json.hpp.

template<typename Target , typename Source >
Target nlohmann::detail::dtoa_impl::reinterpret_bits ( const Source  source)

Definition at line 7187 of file json.hpp.

Variable Documentation

constexpr int nlohmann::detail::dtoa_impl::kAlpha = -60

Definition at line 7451 of file json.hpp.

constexpr int nlohmann::detail::dtoa_impl::kGamma = -32

Definition at line 7452 of file json.hpp.



json_transport
Author(s): Paul Bovbel
autogenerated on Wed Jan 27 2021 03:58:48