[libc-commits] [libc] [libc][math] implement `signbit` (PR #97791)

Akiel Aries via libc-commits libc-commits at lists.llvm.org
Fri Jul 5 17:48:01 PDT 2024


================
@@ -0,0 +1,87 @@
+//===-- Unittests for stdbit ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "test/UnitTest/Test.h"
+
+/*
+ * The intent of this test is validate that the generic math macros operate as
+ * intended
+ */
+#include "include/llvm-libc-macros/generic-math-macros.h"
+
+// INF can be defined as a number with zeroed out mantissa and 1s in the 
+// exponent
+static uint32_t positive_infinity = 0x7F800000;
+static uint32_t negative_infinity = 0xFF800000;
+static const float pos_inf = *(float *) &positive_infinity;
+static const float neg_inf = *(float *) &negative_infinity;
+
+// NaN can be defined as a number with all 1s in the exponent
+static uint32_t positive_nan = 0x7F800001;
+static uint32_t negative_nan = 0xFF800001;
+static const float pos_nan = *(float *) &positive_nan;
+static const float neg_nan = *(float *) &negative_nan;
+
+#define PI 3.14159265358979323846
+#define CASE_DIV_BY_ZERO            PI / 0.0
+#define CASE_DIV_BY_POS_INF         PI / pos_inf
+#define CASE_DIV_BY_NEG_INF         PI / neg_inf
+#define CASE_MULT_ZERO_BY_POS_INF   0 * pos_inf
+#define CASE_MULT_ZERO_BY_NEG_INF   0 * neg_inf
----------------
akielaries wrote:

libc best practice for common variables used across a test suite? Throw this in a test fixture class?

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


More information about the libc-commits mailing list