MCPcopy Create free account
hub / github.com/apache/tvm-ffi / FastMathSafeIsNaN

Function FastMathSafeIsNaN

tests/cpp/extra/test_json_parser.cc:31–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29using namespace tvm::ffi;
30
31inline bool FastMathSafeIsNaN(double x) {
32#ifdef __FAST_MATH__
33 // Bit-level NaN detection (IEEE 754 double)
34 // IEEE 754 standard: https://en.wikipedia.org/wiki/IEEE_754
35 // NaN is encoded as all 1s in the exponent and non-zero in the mantissa
36 static_assert(sizeof(double) == sizeof(uint64_t), "Unexpected double size");
37 uint64_t bits = *reinterpret_cast<const uint64_t*>(&x);
38 uint64_t exponent = (bits >> 52) & 0x7FF;
39 uint64_t mantissa = bits & 0xFFFFFFFFFFFFFull;
40 return (exponent == 0x7FF) && (mantissa != 0);
41#else
42 // Safe to use std::isnan when fast-math is off
43 return std::isnan(x);
44#endif
45}
46
47inline bool FastMathSafeIsInf(double x) {
48#ifdef __FAST_MATH__

Callers 2

WriteFloatMethod · 0.85
TESTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected