Files
clang-p2996/libc/utils/MPFRWrapper/MPFRUtils.h
Siva Chandra Reddy 5fedf7f420 [libc] Move implementations of cosf, sinf, sincosf to src/math directory.
NFC intended in the implementaton. Only mechanical changes to fit the LLVM
libc implementation standard have been done.

Math testing infrastructure has been added. This infrastructure compares the
results produced by the libc with the high precision results from MPFR.
Tests making use of this infrastructure have been added for cosf, sinf and
sincosf.

Reviewers: abrachet, phosek

Differential Revision: https://reviews.llvm.org/D76825
2020-04-16 08:46:10 -07:00

52 lines
1.7 KiB
C++

//===-- MPFRUtils.h ---------------------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H
#define LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H
#include <stdint.h>
namespace __llvm_libc {
namespace testing {
namespace mpfr {
struct Tolerance {
// Number of bits used to represent the fractional
// part of a value of type 'float'.
static constexpr unsigned int floatPrecision = 23;
// Number of bits used to represent the fractional
// part of a value of type 'double'.
static constexpr unsigned int doublePrecision = 52;
// The base precision of the number. For example, for values of
// type float, the base precision is the value |floatPrecision|.
unsigned int basePrecision;
unsigned int width; // Number of valid LSB bits in |value|.
// The bits in the tolerance value. The tolerance value will be
// sum(bits[width - i] * 2 ^ (- basePrecision - i)) for |i| in
// range [1, width].
uint32_t bits;
};
// Return true if |libcOutput| is within the tolerance |t| of the cos(x)
// value as evaluated by MPFR.
bool equalsCos(float x, float libcOutput, const Tolerance &t);
// Return true if |libcOutput| is within the tolerance |t| of the sin(x)
// value as evaluated by MPFR.
bool equalsSin(float x, float libcOutput, const Tolerance &t);
} // namespace mpfr
} // namespace testing
} // namespace __llvm_libc
#endif // LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H