[libc-commits] [libc] [libc][stdfix] Implement fixed point fxbits functions in llvm-libc (PR #114912)
via libc-commits
libc-commits at lists.llvm.org
Sat Nov 9 11:56:10 PST 2024
================
@@ -0,0 +1,53 @@
+//===-- Utility class to test int to fixed point conversions ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "test/UnitTest/Test.h"
+
+#include "include/llvm-libc-types/stdfix-types.h"
+#include "src/__support/CPP/bit.h"
+#include "src/__support/fixed_point/fx_bits.h"
+template <typename T, typename XType>
+class FxBitsTest : public LIBC_NAMESPACE::testing::Test {
+ using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<T>;
+ static constexpr T zero = FXRep::ZERO();
+ static constexpr T min = FXRep::MIN();
+ static constexpr T max = FXRep::MAX();
+ static constexpr T half = static_cast<T>(0.5);
+ static constexpr T quarter = static_cast<T>(0.25);
+ static constexpr T one =
+ (FXRep::INTEGRAL_LEN > 0) ? static_cast<T>(1) : FXRep::MAX();
+ static constexpr T eps = FXRep::EPS();
+ constexpr XType get_one_or_saturated_fraction() {
+ if (FXRep::INTEGRAL_LEN > 0) {
+ return (XType)((XType)0x1 << FXRep::FRACTION_LEN);
----------------
lntue wrote:
use `static_cast` instead of C-style cast.
https://github.com/llvm/llvm-project/pull/114912
More information about the libc-commits
mailing list