[libc-commits] [libc] [libc][math][c++23] Implement basic arithmetic operations for BFloat16 (PR #151228)
via libc-commits
libc-commits at lists.llvm.org
Sat Aug 2 04:44:08 PDT 2025
================
@@ -81,6 +84,29 @@ struct BFloat16 {
LIBC_INLINE bool operator>=(BFloat16 other) const {
return fputil::greater_than_or_equals(*this, other);
}
+
+ LIBC_INLINE constexpr BFloat16 operator-() const {
+ fputil::FPBits<bfloat16> result(*this);
+ result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
+ return result.get_val();
+ }
+
+ LIBC_INLINE BFloat16 operator+(BFloat16 other) const {
+ return fputil::generic::add<BFloat16>(*this, other);
+ }
+
+ LIBC_INLINE BFloat16 operator-(BFloat16 other) const {
+ return fputil::generic::sub<BFloat16>(*this, other);
+ }
+
+ LIBC_INLINE BFloat16 operator*(BFloat16 other) const {
+ return fputil::generic::mul<bfloat16>(*this, other);
+ }
+
+ LIBC_INLINE BFloat16 operator/(BFloat16 other) const {
+ return fputil::generic::div<bfloat16>(*this, other);
+ }
+
----------------
overmighty wrote:
Nit: extra blank line.
https://github.com/llvm/llvm-project/pull/151228
More information about the libc-commits
mailing list