[libc-commits] [libc] [libc][stdfix] Implement fixed point fxbits functions in llvm-libc (PR #114912)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri Nov 8 16:06:56 PST 2024


================
@@ -163,6 +163,10 @@ template <typename T> LIBC_INLINE constexpr T round(T x, int n) {
   return bit_and((x + round_bit), rounding_mask);
 }
 
+template <typename T, typename XType> LIBC_INLINE constexpr T fx_bits(XType x) {
+  return cpp::bit_cast<T, XType>(x);
+}
+
----------------
michaelrj-google wrote:

I don't think adding an int constructor would be too difficult, it should just be checking that the input type is the same as `StorageType`, but there's another possibility:

This function is equivalent to just calling `bit_cast` directly, so you could replace all of the uses in the other functions with `bit_cast`.

https://github.com/llvm/llvm-project/pull/114912


More information about the libc-commits mailing list