Skip to content

Commit 072b6f2

Browse files
committed
Implement fxbits()
1 parent 63fe052 commit 072b6f2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libc/src/__support/fixed_point/fx_bits.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ template <typename T> LIBC_INLINE constexpr T round(T x, int n) {
163163
return bit_and((x + round_bit), rounding_mask);
164164
}
165165

166+
// u?int_fx_t --> Fixed point
167+
template <typename T, typename XType> LIBC_INLINE constexpr T fxbits(XType x) {
168+
// Example: rbits(0x2000) where fract has 15 fractional bits,
169+
// 0x2000 --> 0010 0000 0000 0000 --> 0.010 0000 0000 0000 = 0.25
170+
171+
return cpp::bit_cast<T, XType>(x);
172+
}
166173
} // namespace fixed_point
167174
} // namespace LIBC_NAMESPACE_DECL
168175

0 commit comments

Comments
 (0)