! @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 */
| 17190 | @param[in] x floating-point number to dump |
| 17191 | */ |
| 17192 | void dump_float(number_float_t x) |
| 17193 | { |
| 17194 | // NaN / inf |
| 17195 | if (!std::isfinite(x)) |
| 17196 | { |
| 17197 | o->write_characters("null", 4); |
| 17198 | return; |
| 17199 | } |
| 17200 | |
| 17201 | // If number_float_t is an IEEE-754 single or double precision number, |
| 17202 | // use the Grisu2 algorithm to produce short numbers which are |
| 17203 | // guaranteed to round-trip, using strtof and strtod, resp. |
| 17204 | // |
| 17205 | // NB: The test below works if <long double> == <double>. |
| 17206 | static constexpr bool is_ieee_single_or_double |
| 17207 | = (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) || |
| 17208 | (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); |
| 17209 | |
| 17210 | dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>()); |
| 17211 | } |
| 17212 | |
| 17213 | void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/) |
| 17214 | { |