This commit is contained in:
Matthew Kennedy 2022-07-15 15:17:57 -07:00
parent c144cdf500
commit bb91d99e1b
2 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <cstdint>
#include "isnan.h"
#include "scaled_channel.h"
namespace priv {

View File

@ -0,0 +1,14 @@
#pragma once
#if defined(__cplusplus) && defined(__OPTIMIZE__)
#include <type_traits>
// "g++ -O2" version, adds more strict type check and yet no "strict-aliasing" warnings!
#define cisnan(f) ({ \
static_assert(sizeof(f) == sizeof(int32_t)); \
union cisnanu_t { std::remove_reference_t<decltype(f)> __f; int32_t __i; } __cisnan_u = { f }; \
__cisnan_u.__i == 0x7FC00000; \
})
#else
// "g++ -O0" or other C++/C compilers
#define cisnan(f) (*(((int*) (&f))) == 0x7FC00000)
#endif /* __cplusplus && __OPTIMIZE__ */