1 //===-- MPFRUtils.h ---------------------------------------------*- C++ -*-===//
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 #ifndef LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H
10 #define LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H
11 
12 #include <stdint.h>
13 
14 namespace __llvm_libc {
15 namespace testing {
16 namespace mpfr {
17 
18 struct Tolerance {
19   // Number of bits used to represent the fractional
20   // part of a value of type 'float'.
21   static constexpr unsigned int floatPrecision = 23;
22 
23   // Number of bits used to represent the fractional
24   // part of a value of type 'double'.
25   static constexpr unsigned int doublePrecision = 52;
26 
27   // The base precision of the number. For example, for values of
28   // type float, the base precision is the value |floatPrecision|.
29   unsigned int basePrecision;
30 
31   unsigned int width; // Number of valid LSB bits in |value|.
32 
33   // The bits in the tolerance value. The tolerance value will be
34   // sum(bits[width - i] * 2 ^ (- basePrecision - i)) for |i| in
35   // range [1, width].
36   uint32_t bits;
37 };
38 
39 // Return true if |libcOutput| is within the tolerance |t| of the cos(x)
40 // value as evaluated by MPFR.
41 bool equalsCos(float x, float libcOutput, const Tolerance &t);
42 
43 // Return true if |libcOutput| is within the tolerance |t| of the sin(x)
44 // value as evaluated by MPFR.
45 bool equalsSin(float x, float libcOutput, const Tolerance &t);
46 
47 } // namespace mpfr
48 } // namespace testing
49 } // namespace __llvm_libc
50 
51 #endif // LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H
52