MCPcopy Create free account
hub / github.com/KTH-RPL/dufomap / fpclassify

Function fpclassify

src/toml.hpp:2089–2105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2087 };
2088
2089 TOML_PURE_GETTER
2090 inline fp_class fpclassify(const double& val) noexcept
2091 {
2092 static_assert(sizeof(uint64_t) == sizeof(double));
2093
2094 static constexpr uint64_t sign = 0b1000000000000000000000000000000000000000000000000000000000000000ull;
2095 static constexpr uint64_t exponent = 0b0111111111110000000000000000000000000000000000000000000000000000ull;
2096 static constexpr uint64_t mantissa = 0b0000000000001111111111111111111111111111111111111111111111111111ull;
2097
2098 uint64_t val_bits;
2099 std::memcpy(&val_bits, &val, sizeof(val));
2100 if ((val_bits & exponent) != exponent)
2101 return fp_class::ok;
2102 if ((val_bits & mantissa))
2103 return fp_class::nan;
2104 return (val_bits & sign) ? fp_class::neg_inf : fp_class::pos_inf;
2105 }
2106
2107 // Q: "why not use std::find and std::min?"
2108 // A: Because <algorithm> is _huge_ and these would be the only things I used from it.

Callers 4

operator==Function · 0.85
valueMethod · 0.85
toml.hppFile · 0.85
printMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected