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

via libc-commits libc-commits at lists.llvm.org
Sat Jul 6 07:43:14 PDT 2024


================
@@ -0,0 +1,87 @@
+//===-- Unittests for generic-math-macros ---------------------------------===//
+//
+// 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 pos_inf_bits = 0x7F800000;
+static uint32_t neg_inf_bits = 0xFF800000;
+static const float pos_inf = *(float *) &pos_inf_bits;
+static const float neg_inf = *(float *) &neg_inf_bits;
+
+// NaN can be defined as a number with all 1s in the exponent
+static uint32_t pos_nan_bits = 0x7F800001;
+static uint32_t neg_nan_bits = 0xFF800001;
+static const float pos_nan = *(float *) &pos_nan_bits;
+static const float neg_nan = *(float *) &neg_nan_bits;
+
+#define PI 3.14159265358979323846
----------------
lntue wrote:

Also if you want some special floating point constants, we prefer to use hexadecimal-floating point format instead.

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


More information about the libc-commits mailing list