[libc-commits] [libc] [libc][math][c23] add c23 floating point fmaximum and fminimum functions. (PR #86016)

via libc-commits libc-commits at lists.llvm.org
Sun Mar 24 21:40:58 PDT 2024


================
@@ -0,0 +1,100 @@
+//===-- Utility class to test fminimum_num[f|l] -----------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_FMINIMUMNUMTEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_FMINIMUMNUMTEST_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+template <typename T>
+class FMinimumNumTest : public LIBC_NAMESPACE::testing::Test {
+
+  DECLARE_SPECIAL_CONSTANTS(T)
+
+public:
+  typedef T (*FMinimumNumFunc)(T, T);
+
+  void testNaN(FMinimumNumFunc func) {
+    EXPECT_FP_EQ(inf, func(FPBits::quiet_nan().get_val(), inf));
+    EXPECT_FP_EQ(inf, func(FPBits::signaling_nan().get_val(), inf));
+    EXPECT_FP_EQ(neg_inf, func(neg_inf, FPBits::quiet_nan().get_val()));
+    EXPECT_FP_EQ(neg_inf, func(neg_inf, FPBits::signaling_nan().get_val()));
+    EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), func(aNaN, aNaN));
+    EXPECT_FP_EQ(0.0, func(FPBits::quiet_nan().get_val(), 0.0));
+    EXPECT_FP_EQ(-0.0, func(-0.0, FPBits::quiet_nan().get_val()));
+    EXPECT_FP_EQ(0.0, func(FPBits::signaling_nan().get_val(), 0.0));
+    EXPECT_FP_EQ(-0.0, func(-0.0, FPBits::signaling_nan().get_val()));
+    EXPECT_FP_EQ(T(-1.2345), func(FPBits::quiet_nan().get_val(), T(-1.2345)));
+    EXPECT_FP_EQ(T(1.2345), func(T(1.2345), FPBits::quiet_nan().get_val()));
+    EXPECT_FP_EQ(T(-1.2345),
----------------
lntue wrote:

Sorry, I meant that change all the `EXPECT_FP_EQ` to `EXPECT_FP_EQ_WITH_EXCEPTION` if one of the input is signaling nan.

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


More information about the libc-commits mailing list