[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / math / exp10f_test.cpp
blobd7100fae294704a8ae0411685df3928717f2f48c
1 //===-- Unittests for exp10f ----------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "src/__support/FPUtil/FPBits.h"
10 #include "src/math/exp10f.h"
11 #include "test/UnitTest/FPMatcher.h"
12 #include "test/UnitTest/Test.h"
13 #include "utils/MPFRWrapper/MPFRUtils.h"
14 #include <math.h>
16 #include <errno.h>
17 #include <stdint.h>
19 namespace mpfr = __llvm_libc::testing::mpfr;
21 DECLARE_SPECIAL_CONSTANTS(float)
23 TEST(LlvmLibcExp10fTest, SpecialNumbers) {
24 errno = 0;
26 EXPECT_FP_EQ(aNaN, __llvm_libc::exp10f(aNaN));
27 EXPECT_MATH_ERRNO(0);
29 EXPECT_FP_EQ(inf, __llvm_libc::exp10f(inf));
30 EXPECT_MATH_ERRNO(0);
32 EXPECT_FP_EQ(0.0f, __llvm_libc::exp10f(neg_inf));
33 EXPECT_MATH_ERRNO(0);
35 EXPECT_FP_EQ(1.0f, __llvm_libc::exp10f(0.0f));
36 EXPECT_MATH_ERRNO(0);
38 EXPECT_FP_EQ(1.0f, __llvm_libc::exp10f(-0.0f));
39 EXPECT_MATH_ERRNO(0);
42 TEST(LlvmLibcExp10fTest, Overflow) {
43 errno = 0;
44 EXPECT_FP_EQ(inf, __llvm_libc::exp10f(float(FPBits(0x7f7fffffU))));
45 EXPECT_MATH_ERRNO(ERANGE);
47 EXPECT_FP_EQ(inf, __llvm_libc::exp10f(float(FPBits(0x43000000U))));
48 EXPECT_MATH_ERRNO(ERANGE);
50 EXPECT_FP_EQ(inf, __llvm_libc::exp10f(float(FPBits(0x43000001U))));
51 EXPECT_MATH_ERRNO(ERANGE);
54 TEST(LlvmLibcExp10fTest, TrickyInputs) {
55 constexpr int N = 20;
56 constexpr uint32_t INPUTS[N] = {
57 0x325e5bd8, // x = 0x1.bcb7bp-27f
58 0x325e5bd9, // x = 0x1.bcb7b2p-27f
59 0x325e5bda, // x = 0x1.bcb7b4p-27f
60 0x3d14d956, // x = 0x1.29b2acp-5f
61 0x4116498a, // x = 0x1.2c9314p3f
62 0x4126f431, // x = 0x1.4de862p3f
63 0x4187d13c, // x = 0x1.0fa278p4f
64 0x4203e9da, // x = 0x1.07d3b4p5f
65 0x420b5f5d, // x = 0x1.16bebap5f
66 0x42349e35, // x = 0x1.693c6ap5f
67 0x3f800000, // x = 1.0f
68 0x40000000, // x = 2.0f
69 0x40400000, // x = 3.0f
70 0x40800000, // x = 4.0f
71 0x40a00000, // x = 5.0f
72 0x40c00000, // x = 6.0f
73 0x40e00000, // x = 7.0f
74 0x41000000, // x = 8.0f
75 0x41100000, // x = 9.0f
76 0x41200000, // x = 10.0f
78 for (int i = 0; i < N; ++i) {
79 errno = 0;
80 float x = float(FPBits(INPUTS[i]));
81 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
82 __llvm_libc::exp10f(x), 0.5);
83 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, -x,
84 __llvm_libc::exp10f(-x), 0.5);
88 TEST(LlvmLibcExp10fTest, InFloatRange) {
89 constexpr uint32_t COUNT = 1000000;
90 constexpr uint32_t STEP = UINT32_MAX / COUNT;
91 for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
92 float x = float(FPBits(v));
93 if (isnan(x) || isinf(x))
94 continue;
95 errno = 0;
96 float result = __llvm_libc::exp10f(x);
98 // If the computation resulted in an error or did not produce valid result
99 // in the single-precision floating point range, then ignore comparing with
100 // MPFR result as MPFR can still produce valid results because of its
101 // wider precision.
102 if (isnan(result) || isinf(result) || errno != 0)
103 continue;
104 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
105 __llvm_libc::exp10f(x), 0.5);