TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ grisu2() [2/2]

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 16374 of file json.hpp.

16375{
16376 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
16377 "internal error: not enough precision");
16378 JSON_ASSERT(std::isfinite(value));
16379 JSON_ASSERT(value > 0);
16380 // If the neighbors (and boundaries) of 'value' are always computed for double-precision
16381 // numbers, all float's can be recovered using strtod (and strtof). However, the resulting
16382 // decimal representations are not exactly "short".
16383 //
16384 // The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars)
16385 // says "value is converted to a string as if by std::sprintf in the default ("C") locale"
16386 // and since sprintf promotes float's to double's, I think this is exactly what 'std::to_chars'
16387 // does.
16388 // On the other hand, the documentation for 'std::to_chars' requires that "parsing the
16389 // representation using the corresponding std::from_chars function recovers value exactly". That
16390 // indicates that single precision floating-point numbers should be recovered using
16391 // 'std::strtof'.
16392 //
16393 // NB: If the neighbors are computed for single-precision numbers, there is a single float
16394 // (7.0385307e-26f) which can't be recovered using strtod. The resulting double precision
16395 // value is off by 1 ulp.
16396#if 0
16397 const boundaries w = compute_boundaries(static_cast<double>(value));
16398#else
16399 const boundaries w = compute_boundaries(value);
16400#endif
16401 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
16402}
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
Definition: json.hpp:16321
boundaries compute_boundaries(FloatType value)
Definition: json.hpp:15709