! @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 */
| 14426 | @param[in] x floating-point number to dump |
| 14427 | */ |
| 14428 | void dump_float(number_float_t x) |
| 14429 | { |
| 14430 | // NaN / inf |
| 14431 | if (not std::isfinite(x)) |
| 14432 | { |
| 14433 | o->write_characters("null", 4); |
| 14434 | return; |
| 14435 | } |
| 14436 | |
| 14437 | // If number_float_t is an IEEE-754 single or double precision number, |
| 14438 | // use the Grisu2 algorithm to produce short numbers which are |
| 14439 | // guaranteed to round-trip, using strtof and strtod, resp. |
| 14440 | // |
| 14441 | // NB: The test below works if <long double> == <double>. |
| 14442 | static constexpr bool is_ieee_single_or_double |
| 14443 | = (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 24 and std::numeric_limits<number_float_t>::max_exponent == 128) or |
| 14444 | (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 53 and std::numeric_limits<number_float_t>::max_exponent == 1024); |
| 14445 | |
| 14446 | dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>()); |
| 14447 | } |
| 14448 | |
| 14449 | void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/) |
| 14450 | { |