[libc] [llvm] [libc][complex] Testing infra for MPC (PR #121261)
Shourya Goel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 23 04:10:57 PST 2025
================
@@ -0,0 +1,356 @@
+//===-- Utils which wrap MPC ----------------------------------------------===//
+//
+// 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 "MPCUtils.h"
+
+#include "src/__support/CPP/array.h"
+#include "src/__support/CPP/stringstream.h"
+#include "utils/MPFRWrapper/MPCommon.h"
+
+#include <stdint.h>
+
+#include "mpc.h"
+
+template <typename T> using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
+
+namespace LIBC_NAMESPACE_DECL {
+namespace testing {
+namespace mpc {
+
+static inline cpp::string str(RoundingMode mode) {
+ switch (mode) {
+ case RoundingMode::Upward:
+ return "MPFR_RNDU";
+ case RoundingMode::Downward:
+ return "MPFR_RNDD";
+ case RoundingMode::TowardZero:
+ return "MPFR_RNDZ";
+ case RoundingMode::Nearest:
+ return "MPFR_RNDN";
+ }
+}
+
+class MPCNumber {
+private:
+ unsigned int precision;
+ mpc_t value;
+ mpc_rnd_t mpc_rounding;
+
+public:
+ MPCNumber(unsigned int p) : precision(p), mpc_rounding(MPC_RNDNN) {
+ mpc_init2(value, precision);
+ }
+
+ MPCNumber() : precision(256), mpc_rounding(MPC_RNDNN) {
+ mpc_init2(value, 256);
+ }
+
+ template <typename XType,
+ cpp::enable_if_t<cpp::is_same_v<_Complex float, XType>, bool> = 0>
+ MPCNumber(XType x,
+ unsigned int precision = mpfr::ExtraPrecision<float>::VALUE,
+ RoundingMode rnd = RoundingMode::Nearest)
+ : precision(precision),
+ mpc_rounding(MPC_RND(mpfr::get_mpfr_rounding_mode(rnd),
+ mpfr::get_mpfr_rounding_mode(rnd))) {
+ mpc_init2(value, precision);
+ Complex<float> x_c = cpp::bit_cast<Complex<float>>(x);
+ mpfr_t real, imag;
----------------
Sh0g0-1758 wrote:
but why though ? That wrapper is not required here. `mpfr_t` here is only used since MPC does not allow us to use floats to initialize an `mpc_t`
https://github.com/llvm/llvm-project/pull/121261
More information about the llvm-commits
mailing list