MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / dump_float

Method dump_float

Source/Utils/json.hpp:16198–16217  ·  view source on GitHub ↗

! @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 */

Source from the content-addressed store, hash-verified

16196 @param[in] x floating-point number to dump
16197 */
16198 void dump_float(number_float_t x)
16199 {
16200 // NaN / inf
16201 if (!std::isfinite(x))
16202 {
16203 o->write_characters("null", 4);
16204 return;
16205 }
16206
16207 // If number_float_t is an IEEE-754 single or double precision number,
16208 // use the Grisu2 algorithm to produce short numbers which are
16209 // guaranteed to round-trip, using strtof and strtod, resp.
16210 //
16211 // NB: The test below works if <long double> == <double>.
16212 static constexpr bool is_ieee_single_or_double
16213 = (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) ||
16214 (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);
16215
16216 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
16217 }
16218
16219 void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/)
16220 {

Callers

nothing calls this directly

Calls 5

findFunction · 0.85
write_charactersMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected