[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 22:02:44 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:

Yes, section F.10.9.5 from https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf states that:
- If one input is a number, and the other input is a NaN (quiet or signaling), then return the number.
- If both inputs are NaN (quiet or signaling), then return a quiet NaN.
- If any of the inputs is a signaling NaN, the invalid floating point exception is raised (even if the other input is a number)

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


More information about the libc-commits mailing list