diff options
Diffstat (limited to 'libc/src/__support/FPUtil/bfloat16.h')
| -rw-r--r-- | libc/src/__support/FPUtil/bfloat16.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h index ba97b42e2321..13e151208567 100644 --- a/libc/src/__support/FPUtil/bfloat16.h +++ b/libc/src/__support/FPUtil/bfloat16.h @@ -29,7 +29,9 @@ struct BFloat16 { LIBC_INLINE BFloat16() = default; - template <typename T> LIBC_INLINE constexpr explicit BFloat16(T value) { + template <typename T> + LIBC_INLINE constexpr explicit BFloat16(T value) + : bits(static_cast<uint16_t>(0U)) { if constexpr (cpp::is_floating_point_v<T>) { bits = fputil::cast<bfloat16>(value).bits; } else if constexpr (cpp::is_integral_v<T>) { @@ -46,6 +48,8 @@ struct BFloat16 { xd(sign, 0, value); bits = xd.template as<bfloat16, /*ShouldSignalExceptions=*/true>().bits; + } else if constexpr (cpp::is_convertible_v<T, BFloat16>) { + bits = value.operator BFloat16().bits; } else { bits = fputil::cast<bfloat16>(static_cast<float>(value)).bits; } |
