! @brief dump a floating-point number Dump a given floating-point number to output stream @a o. Works internally with @a number_buffer. @param[in] x floating-point number to dump */
| 18681 | @param[in] x floating-point number to dump |
| 18682 | */ |
| 18683 | void dump_float(number_float_t x) |
| 18684 | { |
| 18685 | // NaN / inf |
| 18686 | if (!std::isfinite(x)) |
| 18687 | { |
| 18688 | o->write_characters("null", 4); |
| 18689 | return; |
| 18690 | } |
| 18691 | |
| 18692 | // If number_float_t is an IEEE-754 single or double precision number, |
| 18693 | // use the Grisu2 algorithm to produce short numbers which are |
| 18694 | // guaranteed to round-trip, using strtof and strtod, resp. |
| 18695 | // |
| 18696 | // NB: The test below works if <long double> == <double>. |
| 18697 | static constexpr bool is_ieee_single_or_double |
| 18698 | = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) || |
| 18699 | (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024); |
| 18700 | |
| 18701 | dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>()); |
| 18702 | } |
| 18703 | |
| 18704 | void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/) |
| 18705 | { |