diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt index f157d90abb8aa..372eba374d8eb 100644 --- a/libc/src/__support/FPUtil/CMakeLists.txt +++ b/libc/src/__support/FPUtil/CMakeLists.txt @@ -274,6 +274,7 @@ add_header_library( bfloat16.h DEPENDS .cast + .comparison_operations .dyadic_float libc.src.__support.CPP.bit libc.src.__support.CPP.type_traits diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h index bc0b8b23896fc..05edbba048cb7 100644 --- a/libc/src/__support/FPUtil/bfloat16.h +++ b/libc/src/__support/FPUtil/bfloat16.h @@ -12,6 +12,7 @@ #include "src/__support/CPP/bit.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/cast.h" +#include "src/__support/FPUtil/comparison_operations.h" #include "src/__support/FPUtil/dyadic_float.h" #include "src/__support/macros/config.h" #include "src/__support/macros/properties/types.h" @@ -57,6 +58,30 @@ struct BFloat16 { uint32_t x_bits = static_cast(bits) << 16U; return cpp::bit_cast(x_bits); } + + LIBC_INLINE constexpr bool operator==(BFloat16 other) const { + return fputil::equals(*this, other); + } + + LIBC_INLINE constexpr bool operator!=(BFloat16 other) const { + return !fputil::equals(*this, other); + } + + LIBC_INLINE constexpr bool operator<(BFloat16 other) const { + return fputil::less_than(*this, other); + } + + LIBC_INLINE constexpr bool operator<=(BFloat16 other) const { + return fputil::less_than_or_equals(*this, other); + } + + LIBC_INLINE constexpr bool operator>(BFloat16 other) const { + return fputil::greater_than(*this, other); + } + + LIBC_INLINE constexpr bool operator>=(BFloat16 other) const { + return fputil::greater_than_or_equals(*this, other); + } }; // struct BFloat16 } // namespace fputil