mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-02 07:18:18 +00:00
Refactor test.cpp (#7487)
* Add timing command to cmakelist * Start to split test.cpp. Move flexbuffers tests * Move monster related tests to own file * Move parser related tests to own file * Move json related tests to own file * Move proto related tests to own file * moved more functions to parser test * moved more functions to parser test2 * move monster extra tests to monster test * move evolution tests to own file * move reflection tests to own file * move util tests to own file * rehomed various tests * move optional scalars test to own file: * rehome more tests * move fuzz tests. Got rid of global test_data_path * fixes for CI failures * add bazel files
This commit is contained in:
41
tests/is_quiet_nan.h
Normal file
41
tests/is_quiet_nan.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef TESTS_IS_QUIET_NAN_H
|
||||
#define TESTS_IS_QUIET_NAN_H
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace tests {
|
||||
|
||||
#if defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)
|
||||
// The IEEE-754 quiet_NaN is not simple binary constant.
|
||||
// All binary NaN bit strings have all the bits of the biased exponent field E
|
||||
// set to 1. A quiet NaN bit string should be encoded with the first bit d[1]
|
||||
// of the trailing significand field T being 1 (d[0] is implicit bit).
|
||||
// It is assumed that endianness of floating-point is same as integer.
|
||||
template<typename T, typename U, U qnan_base> bool is_quiet_nan_impl(T v) {
|
||||
static_assert(sizeof(T) == sizeof(U), "unexpected");
|
||||
U b = 0;
|
||||
std::memcpy(&b, &v, sizeof(T));
|
||||
return ((b & qnan_base) == qnan_base);
|
||||
}
|
||||
# if defined(__mips__) || defined(__hppa__)
|
||||
inline bool is_quiet_nan(float v) {
|
||||
return is_quiet_nan_impl<float, uint32_t, 0x7FC00000u>(v) ||
|
||||
is_quiet_nan_impl<float, uint32_t, 0x7FBFFFFFu>(v);
|
||||
}
|
||||
inline bool is_quiet_nan(double v) {
|
||||
return is_quiet_nan_impl<double, uint64_t, 0x7FF8000000000000ul>(v) ||
|
||||
is_quiet_nan_impl<double, uint64_t, 0x7FF7FFFFFFFFFFFFu>(v);
|
||||
}
|
||||
# else
|
||||
inline bool is_quiet_nan(float v) {
|
||||
return is_quiet_nan_impl<float, uint32_t, 0x7FC00000u>(v);
|
||||
}
|
||||
inline bool is_quiet_nan(double v) {
|
||||
return is_quiet_nan_impl<double, uint64_t, 0x7FF8000000000000ul>(v);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
} // namespace tests
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // TESTS_IS_QUIET_NAN_H
|
||||
Reference in New Issue
Block a user