|
96 | 96 | #include <boost/endian/conversion.hpp> |
97 | 97 | #include <boost/math/special_functions/fpclassify.hpp> |
98 | 98 |
|
99 | | -// namespace alias fp_classify |
100 | | -namespace fp = lslboost::math; |
101 | | - |
102 | | -// namespace alias endian |
103 | | -namespace endian = lslboost::endian; |
104 | | - |
105 | 99 | // generic type traits for numeric types |
| 100 | +#include "portable_archive_exception.hpp" |
| 101 | +#include <cstdint> |
106 | 102 | #include <type_traits> |
107 | 103 |
|
108 | | -#include <boost/cstdint.hpp> |
| 104 | +namespace lsl { |
| 105 | +/*template<typename T> |
| 106 | +int fpclassify(T val) { return std::fpclassify(val); }*/ |
| 107 | +namespace detail { |
109 | 108 |
|
110 | | -#include "portable_archive_exception.hpp" |
| 109 | +template <typename T> struct fp_traits_consts {}; |
| 110 | +template <> struct fp_traits_consts<double> { |
| 111 | + using bits = uint64_t; |
| 112 | + static constexpr bits sign = (0x80000000ull) << 32, exponent = (0x7ff00000ll) << 32, |
| 113 | + significand = ((0x000fffffll) << 32) + (0xfffffffful); |
| 114 | +}; |
| 115 | +template <> struct fp_traits_consts<float> { |
| 116 | + using bits = uint32_t; |
| 117 | + static constexpr bits sign = 0x80000000u, exponent = 0x7f800000, significand = 0x007fffff; |
| 118 | + static void get_bits(float src, bits &dst) { std::memcpy(&dst, &src, sizeof(src)); } |
| 119 | + static void set_bits(float &dst, bits src) { std::memcpy(&dst, &src, sizeof(src)); } |
| 120 | +}; |
| 121 | + |
| 122 | +template <typename T> struct fp_traits { |
| 123 | + using type = fp_traits_consts<T>; |
| 124 | + static void get_bits(double src, typename type::bits &dst) { |
| 125 | + std::memcpy(&dst, &src, sizeof(src)); |
| 126 | + } |
| 127 | + static void set_bits(double &dst, typename type::bits src) { |
| 128 | + std::memcpy(&dst, &src, sizeof(src)); |
| 129 | + } |
| 130 | +}; |
| 131 | + |
| 132 | +} // namespace detail |
| 133 | +} // namespace lsl |
| 134 | + |
| 135 | +namespace fp = lslboost::math; |
| 136 | +// namespace alias endian |
| 137 | +namespace endian = lslboost::endian; |
111 | 138 |
|
112 | 139 | // hint from Johan Rade: on VMS there is still support for |
113 | 140 | // the VAX floating point format and this macro detects it |
|
0 commit comments