[libc-commits] [libc] [libc] created fuzz test for sin function (PR #101411)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Jul 31 16:10:55 PDT 2024
================
@@ -0,0 +1,40 @@
+//===-- sin_fuzz.cpp ----------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// Fuzzing test for llvm-libc sin implementation.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/math/sin.h"
+#include <cmath>
+#include <mpfr.h>
+
+extern "C" int LLVMFuzzerTestOneInput(const double x) {
+ // remove NaN and inf as preconditions
+ if (std::isnan(x))
+ return 0;
+ if (std::isinf(x))
+ return 0;
+ // signed zeros already tested in unit tests
+ if (std::signbit(x) && x == 0.0)
+ return 0;
+ mpfr_t input;
+ mpfr_init2(input, 64);
----------------
michaelrj-google wrote:
For MPFR it's generally best to match exactly the precision you're trying to compare against. A double precision float has an effective precision of `53` since its mantissa is 52 bits + 1 for the implicit leading bit, so instead of `64` this number should be `53`.
https://github.com/llvm/llvm-project/pull/101411
More information about the libc-commits
mailing list