[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / libc / fuzzing / math / sin_fuzz.cpp
bloba5f0fa95c1581659a7c479b8de384f416de2a8b7
1 //===-- sin_fuzz.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// Fuzzing test for llvm-libc sin implementation.
10 ///
11 //===----------------------------------------------------------------------===//
13 #include "src/math/sin.h"
14 #include "utils/MPFRWrapper/mpfr_inc.h"
15 #include <math.h>
17 extern "C" int LLVMFuzzerTestOneInput(const double x) {
18 // remove NaN and inf as preconditions
19 if (isnan(x))
20 return 0;
21 if (isinf(x))
22 return 0;
23 // signed zeros already tested in unit tests
24 if (signbit(x) && x == 0.0)
25 return 0;
26 mpfr_t input;
27 mpfr_init2(input, 53);
28 mpfr_set_d(input, x, MPFR_RNDN);
29 int output = mpfr_sin(input, input, MPFR_RNDN);
30 mpfr_subnormalize(input, output, MPFR_RNDN);
31 double to_compare = mpfr_get_d(input, MPFR_RNDN);
33 double result = LIBC_NAMESPACE::sin(x);
35 if (result != to_compare)
36 __builtin_trap();
38 mpfr_clear(input);
39 return 0;