[libc-commits] [libc] [libc][stdfix] Implement fxdivi functions (rdivi) (PR #154914)
via libc-commits
libc-commits at lists.llvm.org
Mon Aug 25 09:40:04 PDT 2025
================
@@ -0,0 +1,49 @@
+//===-- Utility class to test fxdivi functions ------------------*- 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 "src/__support/fixed_point/fx_rep.h"
+#include "src/__support/macros/sanitizer.h"
+
+#include "hdr/signal_macros.h"
+
+template <typename XType>
+class DivITest : public LIBC_NAMESPACE::testing::Test {
+ using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<int>;
+
+public:
+ typedef XType (*DivIFunc)(int, int);
+
+ void testBasic(DivIFunc func) {
+ auto c1 = func(2, 3);
+ auto e1 = 0.666666;
+ EXPECT_EQ(static_cast<XType>(c1), static_cast<XType>(e1));
+
+ c1 = func(3, 4);
+ e1 = 0.75;
+ EXPECT_EQ(static_cast<XType>(c1), static_cast<XType>(e1));
+
+ c1 = func(1043, 2764);
+ e1 = 0.37735;
+ EXPECT_EQ(static_cast<XType>(c1), static_cast<XType>(e1));
+
+ c1 = func(60000, 720293);
+ e1 = 0.083299;
+ EXPECT_EQ(static_cast<XType>(c1), static_cast<XType>(e1));
+
+ c1 = func(7, 3);
+ e1 = 2.33333;
----------------
PiJoules wrote:
For fract types this shouldn't be an expected result type since fract types can't be grater than 1. This might be useful once we get the accum divi functions, but it's not needed now.
https://github.com/llvm/llvm-project/pull/154914
More information about the libc-commits
mailing list