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

William Tran-Viet via libc-commits libc-commits at lists.llvm.org
Thu Nov 7 20:32:12 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);
+}
+
----------------
smallp-o-p wrote:

The `FXBits<T>(XType x)` constructor checks if `XType` and `T` are the same type, so it wouldn't compile if passed `some_int_type` as x. Correct me if I'm wrong though.

I could add another constructor but that feels a little too hefty for this series of functions. 

Let me know what you think. 

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


More information about the libc-commits mailing list