Fixed compilation errors generated by clang

This commit is contained in:
Benoit Steiner 2016-04-29 18:30:40 -07:00
parent d217217842
commit 2b890ae618
2 changed files with 21 additions and 19 deletions

View File

@ -46,6 +46,8 @@
// Make our own __half definition that is similar to CUDA's.
struct __half {
__half() {}
explicit __half(unsigned short raw) : x(raw) {}
unsigned short x;
};
@ -292,7 +294,7 @@ static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half float_to_half_rtne(float ff)
const FP32 f16max = { (127 + 16) << 23 };
const FP32 denorm_magic = { ((127 - 15) + (23 - 10) + 1) << 23 };
unsigned int sign_mask = 0x80000000u;
__half o = { 0 };
__half o(0);
unsigned int sign = f.u & sign_mask;
f.u ^= sign;

View File

@ -31,9 +31,9 @@ void test_conversion()
VERIFY_IS_EQUAL(half(1.19209e-07f).x, 0x0002);
// Verify round-to-nearest-even behavior.
float val1 = float(half(__half{0x3c00}));
float val2 = float(half(__half{0x3c01}));
float val3 = float(half(__half{0x3c02}));
float val1 = float(half(__half(0x3c00)));
float val2 = float(half(__half(0x3c01)));
float val3 = float(half(__half(0x3c02)));
VERIFY_IS_EQUAL(half(0.5 * (val1 + val2)).x, 0x3c00);
VERIFY_IS_EQUAL(half(0.5 * (val2 + val3)).x, 0x3c02);
@ -49,21 +49,21 @@ void test_conversion()
VERIFY_IS_EQUAL(half(true).x, 0x3c00);
// Conversion to float.
VERIFY_IS_EQUAL(float(half(__half{0x0000})), 0.0f);
VERIFY_IS_EQUAL(float(half(__half{0x3c00})), 1.0f);
VERIFY_IS_EQUAL(float(half(__half(0x0000))), 0.0f);
VERIFY_IS_EQUAL(float(half(__half(0x3c00))), 1.0f);
// Denormals.
VERIFY_IS_APPROX(float(half(__half{0x8001})), -5.96046e-08f);
VERIFY_IS_APPROX(float(half(__half{0x0001})), 5.96046e-08f);
VERIFY_IS_APPROX(float(half(__half{0x0002})), 1.19209e-07f);
VERIFY_IS_APPROX(float(half(__half(0x8001))), -5.96046e-08f);
VERIFY_IS_APPROX(float(half(__half(0x0001))), 5.96046e-08f);
VERIFY_IS_APPROX(float(half(__half(0x0002))), 1.19209e-07f);
// NaNs and infinities.
VERIFY(!(numext::isinf)(float(half(65504.0f)))); // Largest finite number.
VERIFY(!(numext::isnan)(float(half(0.0f))));
VERIFY((numext::isinf)(float(half(__half{0xfc00}))));
VERIFY((numext::isnan)(float(half(__half{0xfc01}))));
VERIFY((numext::isinf)(float(half(__half{0x7c00}))));
VERIFY((numext::isnan)(float(half(__half{0x7c01}))));
VERIFY((numext::isinf)(float(half(__half(0xfc00)))));
VERIFY((numext::isnan)(float(half(__half(0xfc01)))));
VERIFY((numext::isinf)(float(half(__half(0x7c00)))));
VERIFY((numext::isnan)(float(half(__half(0x7c01)))));
#if !EIGEN_COMP_MSVC
// Visual Studio errors out on divisions by 0
@ -73,12 +73,12 @@ void test_conversion()
#endif
// Exactly same checks as above, just directly on the half representation.
VERIFY(!(numext::isinf)(half(__half{0x7bff})));
VERIFY(!(numext::isnan)(half(__half{0x0000})));
VERIFY((numext::isinf)(half(__half{0xfc00})));
VERIFY((numext::isnan)(half(__half{0xfc01})));
VERIFY((numext::isinf)(half(__half{0x7c00})));
VERIFY((numext::isnan)(half(__half{0x7c01})));
VERIFY(!(numext::isinf)(half(__half(0x7bff))));
VERIFY(!(numext::isnan)(half(__half(0x0000))));
VERIFY((numext::isinf)(half(__half(0xfc00))));
VERIFY((numext::isnan)(half(__half(0xfc01))));
VERIFY((numext::isinf)(half(__half(0x7c00))));
VERIFY((numext::isnan)(half(__half(0x7c01))));
#if !EIGEN_COMP_MSVC
// Visual Studio errors out on divisions by 0