TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ to_chars()

template<typename FloatType >
JSON_HEDLEY_RETURNS_NON_NULL char * nlohmann::detail::to_chars ( char *  first,
const char *  last,
FloatType  value 
)

generates a decimal representation of the floating-point number value in [first, last).

The format of the resulting decimal representation is similar to printf's g format. Returns an iterator pointing past-the-end of the decimal representation.

Note
The input number must be finite, i.e. NaN's and Inf's are not supported.
The buffer must be large enough.
The result is NOT null-terminated.

Definition at line 16546 of file json.hpp.

16547{
16548 static_cast<void>(last); // maybe unused - fix warning
16549 JSON_ASSERT(std::isfinite(value));
16550
16551 // Use signbit(value) instead of (value < 0) since signbit works for -0.
16552 if (std::signbit(value))
16553 {
16554 value = -value;
16555 *first++ = '-';
16556 }
16557
16558#ifdef __GNUC__
16559#pragma GCC diagnostic push
16560#pragma GCC diagnostic ignored "-Wfloat-equal"
16561#endif
16562
16563 if (value == 0) // +-0
16564 {
16565 *first++ = '0';
16566 // Make it look like a floating-point number (#362, #378)
16567 *first++ = '.';
16568 *first++ = '0';
16569 return first;
16570 }
16571
16572#ifdef __GNUC__
16573#pragma GCC diagnostic pop
16574#endif
16575 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
16576 // Compute v = buffer * 10^decimal_exponent.
16577 // The decimal digits are stored in the buffer, which needs to be interpreted
16578 // as an unsigned decimal integer.
16579 // len is the length of the buffer, i.e. the number of decimal digits.
16580 int len = 0;
16581 int decimal_exponent = 0;
16582 dtoa_impl::grisu2(first, len, decimal_exponent, value);
16583 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
16584 // Format the buffer like printf("%.*g", prec, value)
16585 constexpr int kMinExp = -4;
16586 // Use digits10 here to increase compatibility with version 2.
16587 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
16588 JSON_ASSERT(last - first >= kMaxExp + 2);
16589 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
16590 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
16591 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
16592}
@ value
the parser finished reading a JSON value