From 4ab32e2de2511746e2108563a43cbbeb1922fbf2 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 11 Jul 2020 12:50:46 +0200 Subject: Allow implicit conversion from bfloat16 to float and double Conversion from `bfloat16` to `float` and `double` is lossless. It seems natural to allow the conversion to be implicit, as the C++ language also support implicit conversion from a smaller to a larger floating point type. Intel's OneDLL bfloat16 implementation also has an implicit `operator float()`: https://github.com/oneapi-src/oneDNN/blob/v1.5/src/common/bfloat16.hpp --- test/bfloat16_float.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/bfloat16_float.cpp') diff --git a/test/bfloat16_float.cpp b/test/bfloat16_float.cpp index eb55f7d45..478aef3a3 100644 --- a/test/bfloat16_float.cpp +++ b/test/bfloat16_float.cpp @@ -53,9 +53,9 @@ void test_conversion() VERIFY_IS_EQUAL(bfloat16(3.40e38f).value, 0x7f80); // Becomes infinity. // Verify round-to-nearest-even behavior. - float val1 = static_cast(bfloat16(__bfloat16_raw(0x3c00))); - float val2 = static_cast(bfloat16(__bfloat16_raw(0x3c01))); - float val3 = static_cast(bfloat16(__bfloat16_raw(0x3c02))); + float val1 = bfloat16(__bfloat16_raw(0x3c00)); + float val2 = bfloat16(__bfloat16_raw(0x3c01)); + float val3 = bfloat16(__bfloat16_raw(0x3c02)); VERIFY_IS_EQUAL(bfloat16(0.5f * (val1 + val2)).value, 0x3c00); VERIFY_IS_EQUAL(bfloat16(0.5f * (val2 + val3)).value, 0x3c02); -- cgit v1.2.3