Skip to content

Commit de7b4ea

Browse files
committed
feat: implement unary negation for bfloat16
Signed-off-by: Krishna Pandey <[email protected]>
1 parent 49febca commit de7b4ea

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libc/src/__support/FPUtil/bfloat16.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ struct BFloat16 {
5757
uint32_t x_bits = static_cast<uint32_t>(bits) << 16U;
5858
return cpp::bit_cast<float>(x_bits);
5959
}
60+
61+
LIBC_INLINE constexpr BFloat16 operator-() const {
62+
fputil::FPBits<bfloat16> result(*this);
63+
result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
64+
return result.get_val();
65+
}
66+
6067
}; // struct BFloat16
6168

6269
} // namespace fputil

0 commit comments

Comments
 (0)