2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 // This include (and the associated definition of __test_capture_signbit)
21 // must be placed before any files that include <cmath> (gtest.h in this case).
23 // <math.h> is required to define generic macros signbit, isfinite and
24 // several other such functions.
26 // <cmath> is required to undef declarations of these macros in the global
27 // namespace and make equivalent functions available in namespace std. Our
28 // stlport implementation does this only for signbit, isfinite, isinf and
31 // NOTE: We don't write our test using std::signbit because we want to be
32 // sure that we're testing the bionic version of signbit. The C++ libraries
33 // are free to reimplement signbit or delegate to compiler builtins if they
37 template<typename T> inline int test_capture_signbit(const T in) {
40 template<typename T> inline int test_capture_isfinite(const T in) {
43 template<typename T> inline int test_capture_isnan(const T in) {
46 template<typename T> inline int test_capture_isinf(const T in) {
51 #include "math_data_test.h"
53 #include <gtest/gtest.h>
60 #include <private/ScopeGuard.h>
62 float float_subnormal() {
71 double double_subnormal() {
76 u.i = 0x000fffffffffffffLL;
80 long double ldouble_subnormal() {
83 unsigned char c[sizeof(long double)];
86 // Subnormals must have a zero exponent and non zero significand.
87 // On all supported representation the 17 bit (counting from either sides)
88 // is part of the significand so it should be enough to set that.
89 // It also applies for the case sizeof(double) = sizeof(long double)
90 for (unsigned int i = 0; i < sizeof(long double); i++) {
93 u.c[sizeof(long double) - 3] = 0x80;
99 TEST(math, fpclassify) {
100 ASSERT_EQ(FP_INFINITE, fpclassify(INFINITY));
101 ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VALF));
102 ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VAL));
103 ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VALL));
105 ASSERT_EQ(FP_NAN, fpclassify(nanf("")));
106 ASSERT_EQ(FP_NAN, fpclassify(nan("")));
107 ASSERT_EQ(FP_NAN, fpclassify(nanl("")));
109 ASSERT_EQ(FP_NORMAL, fpclassify(1.0f));
110 ASSERT_EQ(FP_NORMAL, fpclassify(1.0));
111 ASSERT_EQ(FP_NORMAL, fpclassify(1.0L));
113 ASSERT_EQ(FP_SUBNORMAL, fpclassify(float_subnormal()));
114 ASSERT_EQ(FP_SUBNORMAL, fpclassify(double_subnormal()));
115 ASSERT_EQ(FP_SUBNORMAL, fpclassify(ldouble_subnormal()));
117 ASSERT_EQ(FP_ZERO, fpclassify(0.0f));
118 ASSERT_EQ(FP_ZERO, fpclassify(0.0));
119 ASSERT_EQ(FP_ZERO, fpclassify(0.0L));
122 TEST(math, isfinite) {
123 ASSERT_TRUE(test_capture_isfinite(123.0f));
124 ASSERT_TRUE(test_capture_isfinite(123.0));
125 ASSERT_TRUE(test_capture_isfinite(123.0L));
126 ASSERT_FALSE(test_capture_isfinite(HUGE_VALF));
127 ASSERT_FALSE(test_capture_isfinite(HUGE_VAL));
128 ASSERT_FALSE(test_capture_isfinite(HUGE_VALL));
132 ASSERT_FALSE(test_capture_isinf(123.0f));
133 ASSERT_FALSE(test_capture_isinf(123.0));
134 ASSERT_FALSE(test_capture_isinf(123.0L));
135 ASSERT_TRUE(test_capture_isinf(HUGE_VALF));
136 ASSERT_TRUE(test_capture_isinf(HUGE_VAL));
137 ASSERT_TRUE(test_capture_isinf(HUGE_VALL));
141 ASSERT_FALSE(test_capture_isnan(123.0f));
142 ASSERT_FALSE(test_capture_isnan(123.0));
143 ASSERT_FALSE(test_capture_isnan(123.0L));
144 ASSERT_TRUE(test_capture_isnan(nanf("")));
145 ASSERT_TRUE(test_capture_isnan(nan("")));
146 ASSERT_TRUE(test_capture_isnan(nanl("")));
149 TEST(math, isnormal) {
150 ASSERT_TRUE(isnormal(123.0f));
151 ASSERT_TRUE(isnormal(123.0));
152 ASSERT_TRUE(isnormal(123.0L));
153 ASSERT_FALSE(isnormal(float_subnormal()));
154 ASSERT_FALSE(isnormal(double_subnormal()));
155 ASSERT_FALSE(isnormal(ldouble_subnormal()));
158 // TODO: isgreater, isgreaterequals, isless, islessequal, islessgreater, isunordered
159 TEST(math, signbit) {
160 ASSERT_EQ(0, test_capture_signbit(0.0f));
161 ASSERT_EQ(0, test_capture_signbit(0.0));
162 ASSERT_EQ(0, test_capture_signbit(0.0L));
164 ASSERT_EQ(0, test_capture_signbit(1.0f));
165 ASSERT_EQ(0, test_capture_signbit(1.0));
166 ASSERT_EQ(0, test_capture_signbit(1.0L));
168 ASSERT_NE(0, test_capture_signbit(-1.0f));
169 ASSERT_NE(0, test_capture_signbit(-1.0));
170 ASSERT_NE(0, test_capture_signbit(-1.0L));
173 TEST(math, __fpclassifyd) {
174 #if defined(__GLIBC__)
175 #define __fpclassifyd __fpclassify
177 ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL));
178 ASSERT_EQ(FP_NAN, __fpclassifyd(nan("")));
179 ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0));
180 ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal()));
181 ASSERT_EQ(FP_ZERO, __fpclassifyd(0.0));
184 TEST(math, __fpclassifyf) {
185 ASSERT_EQ(FP_INFINITE, __fpclassifyf(HUGE_VALF));
186 ASSERT_EQ(FP_NAN, __fpclassifyf(nanf("")));
187 ASSERT_EQ(FP_NORMAL, __fpclassifyf(1.0f));
188 ASSERT_EQ(FP_SUBNORMAL, __fpclassifyf(float_subnormal()));
189 ASSERT_EQ(FP_ZERO, __fpclassifyf(0.0f));
192 TEST(math, __fpclassifyl) {
193 EXPECT_EQ(FP_INFINITE, __fpclassifyl(HUGE_VALL));
194 EXPECT_EQ(FP_NAN, __fpclassifyl(nanl("")));
195 EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0L));
196 EXPECT_EQ(FP_SUBNORMAL, __fpclassifyl(ldouble_subnormal()));
197 EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0L));
200 TEST(math, finitef) {
201 ASSERT_TRUE(finitef(123.0f));
202 ASSERT_FALSE(finitef(HUGE_VALF));
205 TEST(math, __isfinite) {
206 #if defined(__GLIBC__)
207 #define __isfinite __finite
209 ASSERT_TRUE(__isfinite(123.0));
210 ASSERT_FALSE(__isfinite(HUGE_VAL));
213 TEST(math, __isfinitef) {
214 #if defined(__GLIBC__)
215 #define __isfinitef __finitef
217 ASSERT_TRUE(__isfinitef(123.0f));
218 ASSERT_FALSE(__isfinitef(HUGE_VALF));
221 TEST(math, __isfinitel) {
222 #if defined(__GLIBC__)
223 #define __isfinitel __finitel
225 ASSERT_TRUE(__isfinitel(123.0L));
226 ASSERT_FALSE(__isfinitel(HUGE_VALL));
230 ASSERT_TRUE(finite(123.0));
231 ASSERT_FALSE(finite(HUGE_VAL));
234 TEST(math, isinf_function) {
235 // The isinf macro deals with all three types; the isinf function is for doubles.
236 ASSERT_FALSE((isinf)(123.0));
237 ASSERT_TRUE((isinf)(HUGE_VAL));
240 TEST(math, __isinff) {
241 ASSERT_FALSE(__isinff(123.0f));
242 ASSERT_TRUE(__isinff(HUGE_VALF));
245 TEST(math, __isinfl) {
246 ASSERT_FALSE(__isinfl(123.0L));
247 ASSERT_TRUE(__isinfl(HUGE_VALL));
250 TEST(math, isnan_function) {
251 // The isnan macro deals with all three types; the isnan function is for doubles.
252 ASSERT_FALSE((isnan)(123.0));
253 ASSERT_TRUE((isnan)(nan("")));
256 TEST(math, __isnanf) {
257 ASSERT_FALSE(__isnanf(123.0f));
258 ASSERT_TRUE(__isnanf(nanf("")));
261 TEST(math, __isnanl) {
262 ASSERT_FALSE(__isnanl(123.0L));
263 ASSERT_TRUE(__isnanl(nanl("")));
267 ASSERT_FALSE(isnanf(123.0f));
268 ASSERT_TRUE(isnanf(nanf("")));
271 TEST(math, __isnormal) {
272 #if defined(__BIONIC__)
273 ASSERT_TRUE(__isnormal(123.0));
274 ASSERT_FALSE(__isnormal(double_subnormal()));
276 GTEST_LOG_(INFO) << "glibc doesn't have __isnormal.\n";
280 TEST(math, __isnormalf) {
281 #if defined(__BIONIC__)
282 ASSERT_TRUE(__isnormalf(123.0f));
283 ASSERT_FALSE(__isnormalf(float_subnormal()));
285 GTEST_LOG_(INFO) << "glibc doesn't have __isnormalf.\n";
289 TEST(math, __isnormall) {
290 #if defined(__BIONIC__)
291 ASSERT_TRUE(__isnormall(123.0L));
292 ASSERT_FALSE(__isnormall(ldouble_subnormal()));
294 GTEST_LOG_(INFO) << "glibc doesn't have __isnormall.\n";
298 TEST(math, __signbit) {
299 ASSERT_EQ(0, __signbit(0.0));
300 ASSERT_EQ(0, __signbit(1.0));
301 ASSERT_NE(0, __signbit(-1.0));
304 TEST(math, __signbitf) {
305 ASSERT_EQ(0, __signbitf(0.0f));
306 ASSERT_EQ(0, __signbitf(1.0f));
307 ASSERT_NE(0, __signbitf(-1.0f));
310 TEST(math, __signbitl) {
311 ASSERT_EQ(0L, __signbitl(0.0L));
312 ASSERT_EQ(0L, __signbitl(1.0L));
313 ASSERT_NE(0L, __signbitl(-1.0L));
317 ASSERT_DOUBLE_EQ(M_PI/2.0, acos(0.0));
321 ASSERT_FLOAT_EQ(static_cast<float>(M_PI)/2.0f, acosf(0.0f));
325 ASSERT_DOUBLE_EQ(M_PI/2.0L, acosl(0.0L));
329 ASSERT_DOUBLE_EQ(0.0, asin(0.0));
333 ASSERT_FLOAT_EQ(0.0f, asinf(0.0f));
337 ASSERT_DOUBLE_EQ(0.0L, asinl(0.0L));
341 ASSERT_DOUBLE_EQ(0.0, atan(0.0));
345 ASSERT_FLOAT_EQ(0.0f, atanf(0.0f));
349 ASSERT_DOUBLE_EQ(0.0L, atanl(0.0L));
353 ASSERT_DOUBLE_EQ(0.0, atan2(0.0, 0.0));
357 ASSERT_FLOAT_EQ(0.0f, atan2f(0.0f, 0.0f));
361 ASSERT_DOUBLE_EQ(0.0L, atan2l(0.0L, 0.0L));
365 ASSERT_DOUBLE_EQ(1.0, cos(0.0));
369 ASSERT_FLOAT_EQ(1.0f, cosf(0.0f));
373 ASSERT_DOUBLE_EQ(1.0L, cosl(0.0L));
377 ASSERT_DOUBLE_EQ(0.0, sin(0.0));
381 ASSERT_FLOAT_EQ(0.0f, sinf(0.0f));
385 ASSERT_DOUBLE_EQ(0.0L, sinl(0.0L));
391 ASSERT_DOUBLE_EQ(0.0, s);
392 ASSERT_DOUBLE_EQ(1.0, c);
395 TEST(math, sincosf) {
397 sincosf(0.0f, &s, &c);
398 ASSERT_FLOAT_EQ(0.0f, s);
399 ASSERT_FLOAT_EQ(1.0f, c);
402 TEST(math, sincosl) {
404 sincosl(0.0L, &s, &c);
405 ASSERT_DOUBLE_EQ(0.0L, s);
406 ASSERT_DOUBLE_EQ(1.0L, c);
410 ASSERT_DOUBLE_EQ(0.0, tan(0.0));
414 ASSERT_FLOAT_EQ(0.0f, tanf(0.0f));
418 ASSERT_DOUBLE_EQ(0.0L, tanl(0.0L));
422 ASSERT_DOUBLE_EQ(0.0, acosh(1.0));
426 ASSERT_FLOAT_EQ(0.0f, acoshf(1.0f));
430 ASSERT_DOUBLE_EQ(0.0L, acoshl(1.0L));
434 ASSERT_DOUBLE_EQ(0.0, asinh(0.0));
438 ASSERT_FLOAT_EQ(0.0f, asinhf(0.0f));
442 ASSERT_DOUBLE_EQ(0.0L, asinhl(0.0L));
446 ASSERT_DOUBLE_EQ(0.0, atanh(0.0));
450 ASSERT_FLOAT_EQ(0.0f, atanhf(0.0f));
454 ASSERT_DOUBLE_EQ(0.0L, atanhl(0.0L));
458 ASSERT_DOUBLE_EQ(1.0, cosh(0.0));
462 ASSERT_FLOAT_EQ(1.0f, coshf(0.0f));
466 ASSERT_DOUBLE_EQ(1.0L, coshl(0.0L));
470 ASSERT_DOUBLE_EQ(0.0, sinh(0.0));
474 ASSERT_FLOAT_EQ(0.0f, sinhf(0.0f));
478 ASSERT_DOUBLE_EQ(0.0L, sinhl(0.0L));
482 ASSERT_DOUBLE_EQ(0.0, tanh(0.0));
486 ASSERT_FLOAT_EQ(0.0f, tanhf(0.0f));
490 ASSERT_DOUBLE_EQ(0.0L, tanhl(0.0L));
494 ASSERT_DOUBLE_EQ(1.0, log(M_E));
498 ASSERT_FLOAT_EQ(1.0f, logf(static_cast<float>(M_E)));
502 ASSERT_DOUBLE_EQ(1.0L, logl(M_E));
506 ASSERT_DOUBLE_EQ(12.0, log2(4096.0));
510 ASSERT_FLOAT_EQ(12.0f, log2f(4096.0f));
514 ASSERT_DOUBLE_EQ(12.0L, log2l(4096.0L));
518 ASSERT_DOUBLE_EQ(3.0, log10(1000.0));
522 ASSERT_FLOAT_EQ(3.0f, log10f(1000.0f));
526 ASSERT_DOUBLE_EQ(3.0L, log10l(1000.0L));
530 ASSERT_DOUBLE_EQ(3.0, cbrt(27.0));
534 ASSERT_FLOAT_EQ(3.0f, cbrtf(27.0f));
538 ASSERT_DOUBLE_EQ(3.0L, cbrtl(27.0L));
542 ASSERT_DOUBLE_EQ(2.0, sqrt(4.0));
546 ASSERT_FLOAT_EQ(2.0f, sqrtf(4.0f));
550 ASSERT_DOUBLE_EQ(2.0L, sqrtl(4.0L));
554 ASSERT_DOUBLE_EQ(1.0, exp(0.0));
555 ASSERT_DOUBLE_EQ(M_E, exp(1.0));
559 ASSERT_FLOAT_EQ(1.0f, expf(0.0f));
560 ASSERT_FLOAT_EQ(static_cast<float>(M_E), expf(1.0f));
564 ASSERT_DOUBLE_EQ(1.0L, expl(0.0L));
565 ASSERT_DOUBLE_EQ(M_E, expl(1.0L));
569 ASSERT_DOUBLE_EQ(8.0, exp2(3.0));
573 ASSERT_FLOAT_EQ(8.0f, exp2f(3.0f));
577 ASSERT_DOUBLE_EQ(8.0L, exp2l(3.0L));
581 ASSERT_DOUBLE_EQ(M_E - 1.0, expm1(1.0));
585 ASSERT_FLOAT_EQ(static_cast<float>(M_E) - 1.0f, expm1f(1.0f));
589 ASSERT_DOUBLE_EQ(M_E - 1.0L, expm1l(1.0L));
593 ASSERT_TRUE(isnan(pow(nan(""), 3.0)));
594 ASSERT_DOUBLE_EQ(1.0, (pow(1.0, nan(""))));
595 ASSERT_TRUE(isnan(pow(2.0, nan(""))));
596 ASSERT_DOUBLE_EQ(8.0, pow(2.0, 3.0));
600 ASSERT_TRUE(isnanf(powf(nanf(""), 3.0f)));
601 ASSERT_FLOAT_EQ(1.0f, (powf(1.0f, nanf(""))));
602 ASSERT_TRUE(isnanf(powf(2.0f, nanf(""))));
603 ASSERT_FLOAT_EQ(8.0f, powf(2.0f, 3.0f));
607 ASSERT_TRUE(__isnanl(powl(nanl(""), 3.0L)));
608 ASSERT_DOUBLE_EQ(1.0L, (powl(1.0L, nanl(""))));
609 ASSERT_TRUE(__isnanl(powl(2.0L, nanl(""))));
610 ASSERT_DOUBLE_EQ(8.0L, powl(2.0L, 3.0L));
614 ASSERT_DOUBLE_EQ(1.0, ceil(0.9));
618 ASSERT_FLOAT_EQ(1.0f, ceilf(0.9f));
622 ASSERT_DOUBLE_EQ(1.0L, ceill(0.9L));
626 ASSERT_DOUBLE_EQ(1.0, floor(1.1));
630 ASSERT_FLOAT_EQ(1.0f, floorf(1.1f));
634 ASSERT_DOUBLE_EQ(1.0L, floorl(1.1L));
638 ASSERT_DOUBLE_EQ(1.0, fabs(-1.0));
642 ASSERT_FLOAT_EQ(1.0f, fabsf(-1.0f));
646 ASSERT_DOUBLE_EQ(1.0L, fabsl(-1.0L));
650 ASSERT_DOUBLE_EQ(16.0, ldexp(2.0, 3.0));
654 ASSERT_FLOAT_EQ(16.0f, ldexpf(2.0f, 3.0f));
658 ASSERT_DOUBLE_EQ(16.0L, ldexpl(2.0L, 3.0));
662 ASSERT_DOUBLE_EQ(2.0, fmod(12.0, 10.0));
666 ASSERT_FLOAT_EQ(2.0f, fmodf(12.0f, 10.0f));
670 ASSERT_DOUBLE_EQ(2.0L, fmodl(12.0L, 10.0L));
673 TEST(math, remainder) {
674 ASSERT_DOUBLE_EQ(2.0, remainder(12.0, 10.0));
677 TEST(math, remainderf) {
678 ASSERT_FLOAT_EQ(2.0f, remainderf(12.0f, 10.0f));
681 TEST(math, remainderl) {
682 ASSERT_DOUBLE_EQ(2.0L, remainderl(12.0L, 10.0L));
686 ASSERT_DOUBLE_EQ(2.0, drem(12.0, 10.0));
690 ASSERT_FLOAT_EQ(2.0f, dremf(12.0f, 10.0f));
694 ASSERT_DOUBLE_EQ(12.0, fmax(12.0, 10.0));
695 ASSERT_DOUBLE_EQ(12.0, fmax(12.0, nan("")));
696 ASSERT_DOUBLE_EQ(12.0, fmax(nan(""), 12.0));
700 ASSERT_FLOAT_EQ(12.0f, fmaxf(12.0f, 10.0f));
701 ASSERT_FLOAT_EQ(12.0f, fmaxf(12.0f, nanf("")));
702 ASSERT_FLOAT_EQ(12.0f, fmaxf(nanf(""), 12.0f));
706 ASSERT_DOUBLE_EQ(12.0L, fmaxl(12.0L, 10.0L));
707 ASSERT_DOUBLE_EQ(12.0L, fmaxl(12.0L, nanl("")));
708 ASSERT_DOUBLE_EQ(12.0L, fmaxl(nanl(""), 12.0L));
712 ASSERT_DOUBLE_EQ(10.0, fmin(12.0, 10.0));
713 ASSERT_DOUBLE_EQ(12.0, fmin(12.0, nan("")));
714 ASSERT_DOUBLE_EQ(12.0, fmin(nan(""), 12.0));
718 ASSERT_FLOAT_EQ(10.0f, fminf(12.0f, 10.0f));
719 ASSERT_FLOAT_EQ(12.0f, fminf(12.0f, nanf("")));
720 ASSERT_FLOAT_EQ(12.0f, fminf(nanf(""), 12.0f));
724 ASSERT_DOUBLE_EQ(10.0L, fminl(12.0L, 10.0L));
725 ASSERT_DOUBLE_EQ(12.0L, fminl(12.0L, nanl("")));
726 ASSERT_DOUBLE_EQ(12.0L, fminl(nanl(""), 12.0L));
730 ASSERT_DOUBLE_EQ(10.0, fma(2.0, 3.0, 4.0));
734 ASSERT_FLOAT_EQ(10.0f, fmaf(2.0f, 3.0f, 4.0f));
738 ASSERT_DOUBLE_EQ(10.0L, fmal(2.0L, 3.0L, 4.0L));
742 ASSERT_DOUBLE_EQ(5.0, hypot(3.0, 4.0));
746 ASSERT_FLOAT_EQ(5.0f, hypotf(3.0f, 4.0f));
750 ASSERT_DOUBLE_EQ(5.0L, hypotl(3.0L, 4.0L));
754 ASSERT_DOUBLE_EQ(0.84270079294971489, erf(1.0));
758 ASSERT_FLOAT_EQ(0.84270078f, erff(1.0f));
762 ASSERT_DOUBLE_EQ(0.84270079294971489L, erfl(1.0L));
766 ASSERT_DOUBLE_EQ(0.15729920705028513, erfc(1.0));
770 ASSERT_FLOAT_EQ(0.15729921f, erfcf(1.0f));
774 ASSERT_DOUBLE_EQ(0.15729920705028513l, erfcl(1.0L));
778 auto guard = make_scope_guard([]() {
779 fesetenv(FE_DFL_ENV);
782 fesetround(FE_UPWARD); // lrint/lrintf/lrintl obey the rounding mode.
783 ASSERT_EQ(1235, lrint(1234.01));
784 ASSERT_EQ(1235, lrintf(1234.01f));
785 ASSERT_EQ(1235, lrintl(1234.01L));
786 fesetround(FE_TOWARDZERO); // lrint/lrintf/lrintl obey the rounding mode.
787 ASSERT_EQ(1234, lrint(1234.01));
788 ASSERT_EQ(1234, lrintf(1234.01f));
789 ASSERT_EQ(1234, lrintl(1234.01L));
791 fesetround(FE_UPWARD); // llrint/llrintf/llrintl obey the rounding mode.
792 ASSERT_EQ(1235L, llrint(1234.01));
793 ASSERT_EQ(1235L, llrintf(1234.01f));
794 ASSERT_EQ(1235L, llrintl(1234.01L));
795 fesetround(FE_TOWARDZERO); // llrint/llrintf/llrintl obey the rounding mode.
796 ASSERT_EQ(1234L, llrint(1234.01));
797 ASSERT_EQ(1234L, llrintf(1234.01f));
798 ASSERT_EQ(1234L, llrintl(1234.01L));
802 auto guard = make_scope_guard([]() {
803 fesetenv(FE_DFL_ENV);
806 fesetround(FE_UPWARD); // rint/rintf/rintl obey the rounding mode.
807 feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
808 ASSERT_EQ(1234.0, rint(1234.0));
809 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
810 ASSERT_EQ(1235.0, rint(1234.01));
811 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
813 feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
814 ASSERT_EQ(1234.0f, rintf(1234.0f));
815 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
816 ASSERT_EQ(1235.0f, rintf(1234.01f));
817 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
819 feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
820 ASSERT_EQ(1234.0, rintl(1234.0L));
821 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
822 ASSERT_EQ(1235.0, rintl(1234.01L));
823 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
825 fesetround(FE_TOWARDZERO); // rint/rintf obey the rounding mode.
826 ASSERT_EQ(1234.0, rint(1234.01));
827 ASSERT_EQ(1234.0f, rintf(1234.01f));
828 ASSERT_EQ(1234.0, rintl(1234.01L));
831 TEST(math, nearbyint) {
832 auto guard = make_scope_guard([]() {
833 fesetenv(FE_DFL_ENV);
835 fesetround(FE_UPWARD); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
836 feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
837 ASSERT_EQ(1234.0, nearbyint(1234.0));
838 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
839 ASSERT_EQ(1235.0, nearbyint(1234.01));
840 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
842 feclearexcept(FE_ALL_EXCEPT);
843 ASSERT_EQ(1234.0f, nearbyintf(1234.0f));
844 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
845 ASSERT_EQ(1235.0f, nearbyintf(1234.01f));
846 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
848 feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
849 ASSERT_EQ(1234.0, nearbyintl(1234.0L));
850 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
851 ASSERT_EQ(1235.0, nearbyintl(1234.01L));
852 ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
854 fesetround(FE_TOWARDZERO); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
855 ASSERT_EQ(1234.0, nearbyint(1234.01));
856 ASSERT_EQ(1234.0f, nearbyintf(1234.01f));
857 ASSERT_EQ(1234.0, nearbyintl(1234.01L));
861 auto guard = make_scope_guard([]() {
862 fesetenv(FE_DFL_ENV);
864 fesetround(FE_UPWARD); // lround ignores the rounding mode.
865 ASSERT_EQ(1234, lround(1234.01));
866 ASSERT_EQ(1234, lroundf(1234.01f));
867 ASSERT_EQ(1234, lroundl(1234.01L));
870 TEST(math, llround) {
871 auto guard = make_scope_guard([]() {
872 fesetenv(FE_DFL_ENV);
874 fesetround(FE_UPWARD); // llround ignores the rounding mode.
875 ASSERT_EQ(1234L, llround(1234.01));
876 ASSERT_EQ(1234L, llroundf(1234.01f));
877 ASSERT_EQ(1234L, llroundl(1234.01L));
881 ASSERT_EQ(FP_ILOGB0, ilogb(0.0));
882 ASSERT_EQ(FP_ILOGBNAN, ilogb(nan("")));
883 ASSERT_EQ(INT_MAX, ilogb(HUGE_VAL));
884 ASSERT_EQ(0, ilogb(1.0));
885 ASSERT_EQ(3, ilogb(10.0));
889 ASSERT_EQ(FP_ILOGB0, ilogbf(0.0f));
890 ASSERT_EQ(FP_ILOGBNAN, ilogbf(nanf("")));
891 ASSERT_EQ(INT_MAX, ilogbf(HUGE_VALF));
892 ASSERT_EQ(0, ilogbf(1.0f));
893 ASSERT_EQ(3, ilogbf(10.0f));
897 ASSERT_EQ(FP_ILOGB0, ilogbl(0.0L));
898 ASSERT_EQ(FP_ILOGBNAN, ilogbl(nanl("")));
899 ASSERT_EQ(INT_MAX, ilogbl(HUGE_VALL));
900 ASSERT_EQ(0L, ilogbl(1.0L));
901 ASSERT_EQ(3L, ilogbl(10.0L));
905 ASSERT_EQ(-HUGE_VAL, logb(0.0));
906 ASSERT_TRUE(isnan(logb(nan(""))));
907 ASSERT_TRUE(isinf(logb(HUGE_VAL)));
908 ASSERT_EQ(0.0, logb(1.0));
909 ASSERT_EQ(3.0, logb(10.0));
913 ASSERT_EQ(-HUGE_VALF, logbf(0.0f));
914 ASSERT_TRUE(isnanf(logbf(nanf(""))));
915 ASSERT_TRUE(__isinff(logbf(HUGE_VALF)));
916 ASSERT_EQ(0.0f, logbf(1.0f));
917 ASSERT_EQ(3.0f, logbf(10.0f));
921 ASSERT_EQ(-HUGE_VAL, logbl(0.0L));
922 ASSERT_TRUE(isnan(logbl(nanl(""))));
923 ASSERT_TRUE(isinf(logbl(HUGE_VALL)));
924 ASSERT_EQ(0.0L, logbl(1.0L));
925 ASSERT_EQ(3.0L, logbl(10.0L));
929 ASSERT_EQ(-HUGE_VAL, log1p(-1.0));
930 ASSERT_TRUE(isnan(log1p(nan(""))));
931 ASSERT_TRUE(isinf(log1p(HUGE_VAL)));
932 ASSERT_DOUBLE_EQ(1.0, log1p(M_E - 1.0));
936 ASSERT_EQ(-HUGE_VALF, log1pf(-1.0f));
937 ASSERT_TRUE(isnanf(log1pf(nanf(""))));
938 ASSERT_TRUE(__isinff(log1pf(HUGE_VALF)));
939 ASSERT_FLOAT_EQ(1.0f, log1pf(static_cast<float>(M_E) - 1.0f));
943 ASSERT_EQ(-HUGE_VALL, log1pl(-1.0L));
944 ASSERT_TRUE(isnan(log1pl(nanl(""))));
945 ASSERT_TRUE(isinf(log1pl(HUGE_VALL)));
946 ASSERT_DOUBLE_EQ(1.0L, log1pl(M_E - 1.0L));
950 ASSERT_DOUBLE_EQ(0.0, fdim(1.0, 1.0));
951 ASSERT_DOUBLE_EQ(1.0, fdim(2.0, 1.0));
952 ASSERT_DOUBLE_EQ(0.0, fdim(1.0, 2.0));
956 ASSERT_FLOAT_EQ(0.0f, fdimf(1.0f, 1.0f));
957 ASSERT_FLOAT_EQ(1.0f, fdimf(2.0f, 1.0f));
958 ASSERT_FLOAT_EQ(0.0f, fdimf(1.0f, 2.0f));
962 ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 1.0L));
963 ASSERT_DOUBLE_EQ(1.0L, fdiml(2.0L, 1.0L));
964 ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 2.0L));
968 auto guard = make_scope_guard([]() {
969 fesetenv(FE_DFL_ENV);
971 fesetround(FE_TOWARDZERO); // round ignores the rounding mode and always rounds away from zero.
972 ASSERT_DOUBLE_EQ(1.0, round(0.5));
973 ASSERT_DOUBLE_EQ(-1.0, round(-0.5));
974 ASSERT_DOUBLE_EQ(0.0, round(0.0));
975 ASSERT_DOUBLE_EQ(-0.0, round(-0.0));
976 ASSERT_TRUE(isnan(round(nan(""))));
977 ASSERT_DOUBLE_EQ(HUGE_VAL, round(HUGE_VAL));
981 auto guard = make_scope_guard([]() {
982 fesetenv(FE_DFL_ENV);
984 fesetround(FE_TOWARDZERO); // roundf ignores the rounding mode and always rounds away from zero.
985 ASSERT_FLOAT_EQ(1.0f, roundf(0.5f));
986 ASSERT_FLOAT_EQ(-1.0f, roundf(-0.5f));
987 ASSERT_FLOAT_EQ(0.0f, roundf(0.0f));
988 ASSERT_FLOAT_EQ(-0.0f, roundf(-0.0f));
989 ASSERT_TRUE(isnanf(roundf(nanf(""))));
990 ASSERT_FLOAT_EQ(HUGE_VALF, roundf(HUGE_VALF));
994 auto guard = make_scope_guard([]() {
995 fesetenv(FE_DFL_ENV);
997 fesetround(FE_TOWARDZERO); // roundl ignores the rounding mode and always rounds away from zero.
998 ASSERT_DOUBLE_EQ(1.0L, roundl(0.5L));
999 ASSERT_DOUBLE_EQ(-1.0L, roundl(-0.5L));
1000 ASSERT_DOUBLE_EQ(0.0L, roundl(0.0L));
1001 ASSERT_DOUBLE_EQ(-0.0L, roundl(-0.0L));
1002 ASSERT_TRUE(isnan(roundl(nanl(""))));
1003 ASSERT_DOUBLE_EQ(HUGE_VALL, roundl(HUGE_VALL));
1007 auto guard = make_scope_guard([]() {
1008 fesetenv(FE_DFL_ENV);
1010 fesetround(FE_UPWARD); // trunc ignores the rounding mode and always rounds toward zero.
1011 ASSERT_DOUBLE_EQ(1.0, trunc(1.5));
1012 ASSERT_DOUBLE_EQ(-1.0, trunc(-1.5));
1013 ASSERT_DOUBLE_EQ(0.0, trunc(0.0));
1014 ASSERT_DOUBLE_EQ(-0.0, trunc(-0.0));
1015 ASSERT_TRUE(isnan(trunc(nan(""))));
1016 ASSERT_DOUBLE_EQ(HUGE_VAL, trunc(HUGE_VAL));
1019 TEST(math, truncf) {
1020 auto guard = make_scope_guard([]() {
1021 fesetenv(FE_DFL_ENV);
1023 fesetround(FE_UPWARD); // truncf ignores the rounding mode and always rounds toward zero.
1024 ASSERT_FLOAT_EQ(1.0f, truncf(1.5f));
1025 ASSERT_FLOAT_EQ(-1.0f, truncf(-1.5f));
1026 ASSERT_FLOAT_EQ(0.0f, truncf(0.0f));
1027 ASSERT_FLOAT_EQ(-0.0f, truncf(-0.0f));
1028 ASSERT_TRUE(isnan(truncf(nanf(""))));
1029 ASSERT_FLOAT_EQ(HUGE_VALF, truncf(HUGE_VALF));
1032 TEST(math, truncl) {
1033 auto guard = make_scope_guard([]() {
1034 fesetenv(FE_DFL_ENV);
1036 fesetround(FE_UPWARD); // truncl ignores the rounding mode and always rounds toward zero.
1037 ASSERT_DOUBLE_EQ(1.0L, truncl(1.5L));
1038 ASSERT_DOUBLE_EQ(-1.0L, truncl(-1.5L));
1039 ASSERT_DOUBLE_EQ(0.0L, truncl(0.0L));
1040 ASSERT_DOUBLE_EQ(-0.0L, truncl(-0.0L));
1041 ASSERT_TRUE(isnan(truncl(nan(""))));
1042 ASSERT_DOUBLE_EQ(HUGE_VALL, truncl(HUGE_VALL));
1045 TEST(math, nextafter) {
1046 ASSERT_DOUBLE_EQ(0.0, nextafter(0.0, 0.0));
1047 ASSERT_DOUBLE_EQ(4.9406564584124654e-324, nextafter(0.0, 1.0));
1048 ASSERT_DOUBLE_EQ(-4.9406564584124654e-324, nextafter(0.0, -1.0));
1051 TEST(math, nextafterf) {
1052 ASSERT_FLOAT_EQ(0.0f, nextafterf(0.0f, 0.0f));
1053 ASSERT_FLOAT_EQ(1.4012985e-45f, nextafterf(0.0f, 1.0f));
1054 ASSERT_FLOAT_EQ(-1.4012985e-45f, nextafterf(0.0f, -1.0f));
1057 TEST(math, nextafterl) {
1058 ASSERT_DOUBLE_EQ(0.0L, nextafterl(0.0L, 0.0L));
1059 // Use a runtime value to accomodate the case when
1060 // sizeof(double) == sizeof(long double)
1061 long double smallest_positive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG);
1062 ASSERT_DOUBLE_EQ(smallest_positive, nextafterl(0.0L, 1.0L));
1063 ASSERT_DOUBLE_EQ(-smallest_positive, nextafterl(0.0L, -1.0L));
1066 TEST(math, nexttoward) {
1067 ASSERT_DOUBLE_EQ(0.0, nexttoward(0.0, 0.0L));
1068 ASSERT_DOUBLE_EQ(4.9406564584124654e-324, nexttoward(0.0, 1.0L));
1069 ASSERT_DOUBLE_EQ(-4.9406564584124654e-324, nexttoward(0.0, -1.0L));
1072 TEST(math, nexttowardf) {
1073 ASSERT_FLOAT_EQ(0.0f, nexttowardf(0.0f, 0.0L));
1074 ASSERT_FLOAT_EQ(1.4012985e-45f, nexttowardf(0.0f, 1.0L));
1075 ASSERT_FLOAT_EQ(-1.4012985e-45f, nexttowardf(0.0f, -1.0L));
1078 TEST(math, nexttowardl) {
1079 ASSERT_DOUBLE_EQ(0.0L, nexttowardl(0.0L, 0.0L));
1080 // Use a runtime value to accomodate the case when
1081 // sizeof(double) == sizeof(long double)
1082 long double smallest_positive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG);
1083 ASSERT_DOUBLE_EQ(smallest_positive, nexttowardl(0.0L, 1.0L));
1084 ASSERT_DOUBLE_EQ(-smallest_positive, nexttowardl(0.0L, -1.0L));
1087 TEST(math, copysign) {
1088 ASSERT_DOUBLE_EQ(0.0, copysign(0.0, 1.0));
1089 ASSERT_DOUBLE_EQ(-0.0, copysign(0.0, -1.0));
1090 ASSERT_DOUBLE_EQ(2.0, copysign(2.0, 1.0));
1091 ASSERT_DOUBLE_EQ(-2.0, copysign(2.0, -1.0));
1094 TEST(math, copysignf) {
1095 ASSERT_FLOAT_EQ(0.0f, copysignf(0.0f, 1.0f));
1096 ASSERT_FLOAT_EQ(-0.0f, copysignf(0.0f, -1.0f));
1097 ASSERT_FLOAT_EQ(2.0f, copysignf(2.0f, 1.0f));
1098 ASSERT_FLOAT_EQ(-2.0f, copysignf(2.0f, -1.0f));
1101 TEST(math, copysignl) {
1102 ASSERT_DOUBLE_EQ(0.0L, copysignl(0.0L, 1.0L));
1103 ASSERT_DOUBLE_EQ(-0.0L, copysignl(0.0L, -1.0L));
1104 ASSERT_DOUBLE_EQ(2.0L, copysignl(2.0L, 1.0L));
1105 ASSERT_DOUBLE_EQ(-2.0L, copysignl(2.0L, -1.0L));
1108 TEST(math, significand) {
1109 ASSERT_DOUBLE_EQ(0.0, significand(0.0));
1110 ASSERT_DOUBLE_EQ(1.2, significand(1.2));
1111 ASSERT_DOUBLE_EQ(1.53125, significand(12.25));
1114 TEST(math, significandf) {
1115 ASSERT_FLOAT_EQ(0.0f, significandf(0.0f));
1116 ASSERT_FLOAT_EQ(1.2f, significandf(1.2f));
1117 ASSERT_FLOAT_EQ(1.53125f, significandf(12.25f));
1120 TEST(math, significandl) {
1121 ASSERT_DOUBLE_EQ(0.0L, significandl(0.0L));
1122 ASSERT_DOUBLE_EQ(1.2L, significandl(1.2L));
1123 ASSERT_DOUBLE_EQ(1.53125L, significandl(12.25L));
1127 ASSERT_DOUBLE_EQ(12.0, scalb(3.0, 2.0));
1130 TEST(math, scalbf) {
1131 ASSERT_FLOAT_EQ(12.0f, scalbf(3.0f, 2.0f));
1134 TEST(math, scalbln) {
1135 ASSERT_DOUBLE_EQ(12.0, scalbln(3.0, 2L));
1138 TEST(math, scalblnf) {
1139 ASSERT_FLOAT_EQ(12.0f, scalblnf(3.0f, 2L));
1142 TEST(math, scalblnl) {
1143 ASSERT_DOUBLE_EQ(12.0L, scalblnl(3.0L, 2L));
1146 TEST(math, scalbn) {
1147 ASSERT_DOUBLE_EQ(12.0, scalbn(3.0, 2));
1150 TEST(math, scalbnf) {
1151 ASSERT_FLOAT_EQ(12.0f, scalbnf(3.0f, 2));
1154 TEST(math, scalbnl) {
1155 ASSERT_DOUBLE_EQ(12.0L, scalbnl(3.0L, 2));
1159 ASSERT_DOUBLE_EQ(log(24.0), gamma(5.0));
1162 TEST(math, gammaf) {
1163 ASSERT_FLOAT_EQ(logf(24.0f), gammaf(5.0f));
1166 TEST(math, gamma_r) {
1167 #if defined(__BIONIC__)
1169 ASSERT_DOUBLE_EQ(log(24.0), gamma_r(5.0, &sign));
1172 GTEST_LOG_(INFO) << "glibc doesn't have gamma_r.\n";
1173 #endif // __BIONIC__
1176 TEST(math, gammaf_r) {
1177 #if defined(__BIONIC__)
1179 ASSERT_FLOAT_EQ(logf(24.0f), gammaf_r(5.0f, &sign));
1182 GTEST_LOG_(INFO) << "glibc doesn't have gammaf_r.\n";
1183 #endif // __BIONIC__
1186 TEST(math, lgamma) {
1187 ASSERT_DOUBLE_EQ(log(24.0), lgamma(5.0));
1190 TEST(math, lgammaf) {
1191 ASSERT_FLOAT_EQ(logf(24.0f), lgammaf(5.0f));
1194 TEST(math, lgammal) {
1195 ASSERT_DOUBLE_EQ(logl(24.0L), lgammal(5.0L));
1198 TEST(math, lgamma_r) {
1200 ASSERT_DOUBLE_EQ(log(24.0), lgamma_r(5.0, &sign));
1204 TEST(math, lgamma_r_17471883) {
1208 ASSERT_DOUBLE_EQ(HUGE_VAL, lgamma_r(0.0, &sign));
1211 ASSERT_DOUBLE_EQ(HUGE_VAL, lgamma_r(-0.0, &sign));
1212 ASSERT_EQ(-1, sign);
1215 TEST(math, lgammaf_r) {
1217 ASSERT_FLOAT_EQ(logf(24.0f), lgammaf_r(5.0f, &sign));
1221 TEST(math, lgammaf_r_17471883) {
1225 ASSERT_FLOAT_EQ(HUGE_VALF, lgammaf_r(0.0f, &sign));
1228 ASSERT_FLOAT_EQ(HUGE_VALF, lgammaf_r(-0.0f, &sign));
1229 ASSERT_EQ(-1, sign);
1232 TEST(math, lgammal_r) {
1234 ASSERT_DOUBLE_EQ(log(24.0L), lgamma_r(5.0L, &sign));
1238 TEST(math, lgammal_r_17471883) {
1242 ASSERT_DOUBLE_EQ(HUGE_VAL, lgammal_r(0.0L, &sign));
1245 ASSERT_DOUBLE_EQ(HUGE_VAL, lgammal_r(-0.0L, &sign));
1246 ASSERT_EQ(-1, sign);
1249 TEST(math, tgamma) {
1250 ASSERT_DOUBLE_EQ(24.0, tgamma(5.0));
1253 TEST(math, tgammaf) {
1254 ASSERT_FLOAT_EQ(24.0f, tgammaf(5.0f));
1257 TEST(math, tgammal) {
1258 ASSERT_DOUBLE_EQ(24.0L, tgammal(5.0L));
1262 ASSERT_DOUBLE_EQ(1.0, j0(0.0));
1263 ASSERT_DOUBLE_EQ(0.76519768655796661, j0(1.0));
1267 ASSERT_FLOAT_EQ(1.0f, j0f(0.0f));
1268 ASSERT_FLOAT_EQ(0.76519769f, j0f(1.0f));
1272 ASSERT_DOUBLE_EQ(0.0, j1(0.0));
1273 ASSERT_DOUBLE_EQ(0.44005058574493355, j1(1.0));
1277 ASSERT_FLOAT_EQ(0.0f, j1f(0.0f));
1278 ASSERT_FLOAT_EQ(0.44005057f, j1f(1.0f));
1282 ASSERT_DOUBLE_EQ(0.0, jn(4, 0.0));
1283 ASSERT_DOUBLE_EQ(0.0024766389641099553, jn(4, 1.0));
1287 ASSERT_FLOAT_EQ(0.0f, jnf(4, 0.0f));
1288 ASSERT_FLOAT_EQ(0.0024766389f, jnf(4, 1.0f));
1292 ASSERT_DOUBLE_EQ(-HUGE_VAL, y0(0.0));
1293 ASSERT_DOUBLE_EQ(0.08825696421567697, y0(1.0));
1297 ASSERT_FLOAT_EQ(-HUGE_VALF, y0f(0.0f));
1298 ASSERT_FLOAT_EQ(0.088256963f, y0f(1.0f));
1302 ASSERT_DOUBLE_EQ(-HUGE_VAL, y1(0.0));
1303 ASSERT_DOUBLE_EQ(-0.78121282130028868, y1(1.0));
1307 ASSERT_FLOAT_EQ(-HUGE_VALF, y1f(0.0f));
1308 ASSERT_FLOAT_EQ(-0.78121281f, y1f(1.0f));
1312 ASSERT_DOUBLE_EQ(-HUGE_VAL, yn(4, 0.0));
1313 ASSERT_DOUBLE_EQ(-33.278423028972114, yn(4, 1.0));
1317 ASSERT_FLOAT_EQ(-HUGE_VALF, ynf(4, 0.0f));
1318 ASSERT_FLOAT_EQ(-33.278423f, ynf(4, 1.0f));
1323 double dr = frexp(1024.0, &exp);
1324 ASSERT_DOUBLE_EQ(1024.0, scalbn(dr, exp));
1327 TEST(math, frexpf) {
1329 float fr = frexpf(1024.0f, &exp);
1330 ASSERT_FLOAT_EQ(1024.0f, scalbnf(fr, exp));
1333 TEST(math, frexpl) {
1335 long double ldr = frexpl(1024.0L, &exp);
1336 ASSERT_DOUBLE_EQ(1024.0L, scalbnl(ldr, exp));
1341 double df = modf(123.75, &di);
1342 ASSERT_DOUBLE_EQ(123.0, di);
1343 ASSERT_DOUBLE_EQ(0.75, df);
1348 float ff = modff(123.75f, &fi);
1349 ASSERT_FLOAT_EQ(123.0f, fi);
1350 ASSERT_FLOAT_EQ(0.75f, ff);
1355 long double ldf = modfl(123.75L, &ldi);
1356 ASSERT_DOUBLE_EQ(123.0L, ldi);
1357 ASSERT_DOUBLE_EQ(0.75L, ldf);
1360 TEST(math, remquo) {
1362 double d = remquo(13.0, 4.0, &q);
1364 ASSERT_DOUBLE_EQ(1.0, d);
1367 TEST(math, remquof) {
1369 float f = remquof(13.0f, 4.0f, &q);
1371 ASSERT_FLOAT_EQ(1.0, f);
1374 TEST(math, remquol) {
1376 long double ld = remquol(13.0L, 4.0L, &q);
1377 ASSERT_DOUBLE_EQ(3L, q);
1378 ASSERT_DOUBLE_EQ(1.0L, ld);
1381 // https://code.google.com/p/android/issues/detail?id=6697
1382 TEST(math, frexpf_public_bug_6697) {
1384 float fr = frexpf(14.1f, &exp);
1385 ASSERT_FLOAT_EQ(14.1f, scalbnf(fr, exp));
1388 TEST(math, exp2_STRICT_ALIGN_OpenBSD_bug) {
1389 // OpenBSD/x86's libm had a bug here, but it was already fixed in FreeBSD:
1390 // http://svnweb.FreeBSD.org/base/head/lib/msun/src/math_private.h?revision=240827&view=markup
1391 ASSERT_DOUBLE_EQ(5.0, exp2(log2(5)));
1392 ASSERT_FLOAT_EQ(5.0f, exp2f(log2f(5)));
1393 ASSERT_DOUBLE_EQ(5.0L, exp2l(log2l(5)));
1396 TEST(math, nextafterl_OpenBSD_bug) {
1397 // OpenBSD/x86's libm had a bug here.
1398 ASSERT_TRUE(nextafter(1.0, 0.0) - 1.0 < 0.0);
1399 ASSERT_TRUE(nextafterf(1.0f, 0.0f) - 1.0f < 0.0f);
1400 ASSERT_TRUE(nextafterl(1.0L, 0.0L) - 1.0L < 0.0L);
1403 #include "math_data/acos_intel_data.h"
1404 TEST(math, acos_intel) {
1405 DoMathDataTest<1>(g_acos_intel_data, acos);
1408 #include "math_data/acosf_intel_data.h"
1409 TEST(math, acosf_intel) {
1410 DoMathDataTest<1>(g_acosf_intel_data, acosf);
1413 #include "math_data/acosh_intel_data.h"
1414 TEST(math, acosh_intel) {
1415 DoMathDataTest<2>(g_acosh_intel_data, acosh);
1418 #include "math_data/acoshf_intel_data.h"
1419 TEST(math, acoshf_intel) {
1420 DoMathDataTest<2>(g_acoshf_intel_data, acoshf);
1423 #include "math_data/asin_intel_data.h"
1424 TEST(math, asin_intel) {
1425 DoMathDataTest<1>(g_asin_intel_data, asin);
1428 #include "math_data/asinf_intel_data.h"
1429 TEST(math, asinf_intel) {
1430 DoMathDataTest<1>(g_asinf_intel_data, asinf);
1433 #include "math_data/asinh_intel_data.h"
1434 TEST(math, asinh_intel) {
1435 DoMathDataTest<2>(g_asinh_intel_data, asinh);
1438 #include "math_data/asinhf_intel_data.h"
1439 TEST(math, asinhf_intel) {
1440 DoMathDataTest<2>(g_asinhf_intel_data, asinhf);
1443 #include "math_data/atan2_intel_data.h"
1444 TEST(math, atan2_intel) {
1445 DoMathDataTest<2>(g_atan2_intel_data, atan2);
1448 #include "math_data/atan2f_intel_data.h"
1449 TEST(math, atan2f_intel) {
1450 DoMathDataTest<2>(g_atan2f_intel_data, atan2f);
1453 #include "math_data/atan_intel_data.h"
1454 TEST(math, atan_intel) {
1455 DoMathDataTest<1>(g_atan_intel_data, atan);
1458 #include "math_data/atanf_intel_data.h"
1459 TEST(math, atanf_intel) {
1460 DoMathDataTest<1>(g_atanf_intel_data, atanf);
1463 #include "math_data/atanh_intel_data.h"
1464 TEST(math, atanh_intel) {
1465 DoMathDataTest<2>(g_atanh_intel_data, atanh);
1468 #include "math_data/atanhf_intel_data.h"
1469 TEST(math, atanhf_intel) {
1470 DoMathDataTest<2>(g_atanhf_intel_data, atanhf);
1473 #include "math_data/cbrt_intel_data.h"
1474 TEST(math, cbrt_intel) {
1475 DoMathDataTest<1>(g_cbrt_intel_data, cbrt);
1478 #include "math_data/cbrtf_intel_data.h"
1479 TEST(math, cbrtf_intel) {
1480 DoMathDataTest<1>(g_cbrtf_intel_data, cbrtf);
1483 #include "math_data/ceil_intel_data.h"
1484 TEST(math, ceil_intel) {
1485 DoMathDataTest<1>(g_ceil_intel_data, ceil);
1488 #include "math_data/ceilf_intel_data.h"
1489 TEST(math, ceilf_intel) {
1490 DoMathDataTest<1>(g_ceilf_intel_data, ceilf);
1493 #include "math_data/copysign_intel_data.h"
1494 TEST(math, copysign_intel) {
1495 DoMathDataTest<1>(g_copysign_intel_data, copysign);
1498 #include "math_data/copysignf_intel_data.h"
1499 TEST(math, copysignf_intel) {
1500 DoMathDataTest<1>(g_copysignf_intel_data, copysignf);
1503 #include "math_data/cos_intel_data.h"
1504 TEST(math, cos_intel) {
1505 DoMathDataTest<1>(g_cos_intel_data, cos);
1508 #include "math_data/cosf_intel_data.h"
1509 TEST(math, cosf_intel) {
1510 DoMathDataTest<1>(g_cosf_intel_data, cosf);
1513 #include "math_data/cosh_intel_data.h"
1514 TEST(math, cosh_intel) {
1515 DoMathDataTest<2>(g_cosh_intel_data, cosh);
1518 #include "math_data/coshf_intel_data.h"
1519 TEST(math, coshf_intel) {
1520 DoMathDataTest<2>(g_coshf_intel_data, coshf);
1523 #include "math_data/exp_intel_data.h"
1524 TEST(math, exp_intel) {
1525 DoMathDataTest<1>(g_exp_intel_data, exp);
1528 #include "math_data/expf_intel_data.h"
1529 TEST(math, expf_intel) {
1530 DoMathDataTest<1>(g_expf_intel_data, expf);
1533 #include "math_data/exp2_intel_data.h"
1534 TEST(math, exp2_intel) {
1535 DoMathDataTest<1>(g_exp2_intel_data, exp2);
1538 #include "math_data/exp2f_intel_data.h"
1539 TEST(math, exp2f_intel) {
1540 DoMathDataTest<1>(g_exp2f_intel_data, exp2f);
1543 #include "math_data/expm1_intel_data.h"
1544 TEST(math, expm1_intel) {
1545 DoMathDataTest<1>(g_expm1_intel_data, expm1);
1548 #include "math_data/expm1f_intel_data.h"
1549 TEST(math, expm1f_intel) {
1550 DoMathDataTest<1>(g_expm1f_intel_data, expm1f);
1553 #include "math_data/fabs_intel_data.h"
1554 TEST(math, fabs_intel) {
1555 DoMathDataTest<1>(g_fabs_intel_data, fabs);
1558 #include "math_data/fabsf_intel_data.h"
1559 TEST(math, fabsf_intel) {
1560 DoMathDataTest<1>(g_fabsf_intel_data, fabsf);
1563 #include "math_data/fdim_intel_data.h"
1564 TEST(math, fdim_intel) {
1565 DoMathDataTest<1>(g_fdim_intel_data, fdim);
1568 #include "math_data/fdimf_intel_data.h"
1569 TEST(math, fdimf_intel) {
1570 DoMathDataTest<1>(g_fdimf_intel_data, fdimf);
1573 #include "math_data/floor_intel_data.h"
1574 TEST(math, floor_intel) {
1575 DoMathDataTest<1>(g_floor_intel_data, floor);
1578 #include "math_data/floorf_intel_data.h"
1579 TEST(math, floorf_intel) {
1580 DoMathDataTest<1>(g_floorf_intel_data, floorf);
1583 #include "math_data/fma_intel_data.h"
1584 TEST(math, fma_intel) {
1585 DoMathDataTest<1>(g_fma_intel_data, fma);
1588 #include "math_data/fmaf_intel_data.h"
1589 TEST(math, fmaf_intel) {
1590 DoMathDataTest<1>(g_fmaf_intel_data, fmaf);
1593 #include "math_data/fmax_intel_data.h"
1594 TEST(math, fmax_intel) {
1595 DoMathDataTest<1>(g_fmax_intel_data, fmax);
1598 #include "math_data/fmaxf_intel_data.h"
1599 TEST(math, fmaxf_intel) {
1600 DoMathDataTest<1>(g_fmaxf_intel_data, fmaxf);
1603 #include "math_data/fmin_intel_data.h"
1604 TEST(math, fmin_intel) {
1605 DoMathDataTest<1>(g_fmin_intel_data, fmin);
1608 #include "math_data/fminf_intel_data.h"
1609 TEST(math, fminf_intel) {
1610 DoMathDataTest<1>(g_fminf_intel_data, fminf);
1613 #include "math_data/fmod_intel_data.h"
1614 TEST(math, fmod_intel) {
1615 DoMathDataTest<1>(g_fmod_intel_data, fmod);
1618 #include "math_data/fmodf_intel_data.h"
1619 TEST(math, fmodf_intel) {
1620 DoMathDataTest<1>(g_fmodf_intel_data, fmodf);
1623 #include "math_data/frexp_intel_data.h"
1624 TEST(math, frexp_intel) {
1625 DoMathDataTest<1>(g_frexp_intel_data, frexp);
1628 #include "math_data/frexpf_intel_data.h"
1629 TEST(math, frexpf_intel) {
1630 DoMathDataTest<1>(g_frexpf_intel_data, frexpf);
1633 #include "math_data/hypot_intel_data.h"
1634 TEST(math, hypot_intel) {
1635 DoMathDataTest<1>(g_hypot_intel_data, hypot);
1638 #include "math_data/hypotf_intel_data.h"
1639 TEST(math, hypotf_intel) {
1640 DoMathDataTest<1>(g_hypotf_intel_data, hypotf);
1643 #include "math_data/ilogb_intel_data.h"
1644 TEST(math, ilogb_intel) {
1645 DoMathDataTest<1>(g_ilogb_intel_data, ilogb);
1648 #include "math_data/ilogbf_intel_data.h"
1649 TEST(math, ilogbf_intel) {
1650 DoMathDataTest<1>(g_ilogbf_intel_data, ilogbf);
1653 #include "math_data/ldexp_intel_data.h"
1654 TEST(math, ldexp_intel) {
1655 DoMathDataTest<1>(g_ldexp_intel_data, ldexp);
1658 #include "math_data/ldexpf_intel_data.h"
1659 TEST(math, ldexpf_intel) {
1660 DoMathDataTest<1>(g_ldexpf_intel_data, ldexpf);
1663 #include "math_data/llrint_intel_data.h"
1664 TEST(math, llrint_intel) {
1665 DoMathDataTest<1>(g_llrint_intel_data, llrint);
1668 #include "math_data/llrintf_intel_data.h"
1669 TEST(math, llrintf_intel) {
1670 DoMathDataTest<1>(g_llrintf_intel_data, llrintf);
1673 #include "math_data/log_intel_data.h"
1674 TEST(math, log_intel) {
1675 DoMathDataTest<1>(g_log_intel_data, log);
1678 #include "math_data/logf_intel_data.h"
1679 TEST(math, logf_intel) {
1680 DoMathDataTest<1>(g_logf_intel_data, logf);
1683 #include "math_data/log10_intel_data.h"
1684 TEST(math, log10_intel) {
1685 DoMathDataTest<1>(g_log10_intel_data, log10);
1688 #include "math_data/log10f_intel_data.h"
1689 TEST(math, log10f_intel) {
1690 DoMathDataTest<1>(g_log10f_intel_data, log10f);
1693 #include "math_data/log1p_intel_data.h"
1694 TEST(math, log1p_intel) {
1695 DoMathDataTest<1>(g_log1p_intel_data, log1p);
1698 #include "math_data/log1pf_intel_data.h"
1699 TEST(math, log1pf_intel) {
1700 DoMathDataTest<1>(g_log1pf_intel_data, log1pf);
1703 #include "math_data/log2_intel_data.h"
1704 TEST(math, log2_intel) {
1705 DoMathDataTest<1>(g_log2_intel_data, log2);
1708 #include "math_data/log2f_intel_data.h"
1709 TEST(math, log2f_intel) {
1710 DoMathDataTest<1>(g_log2f_intel_data, log2f);
1713 #include "math_data/logb_intel_data.h"
1714 TEST(math, logb_intel) {
1715 DoMathDataTest<1>(g_logb_intel_data, logb);
1718 #include "math_data/logbf_intel_data.h"
1719 TEST(math, logbf_intel) {
1720 DoMathDataTest<1>(g_logbf_intel_data, logbf);
1723 #include "math_data/lrint_intel_data.h"
1724 TEST(math, lrint_intel) {
1725 DoMathDataTest<1>(g_lrint_intel_data, lrint);
1728 #include "math_data/lrintf_intel_data.h"
1729 TEST(math, lrintf_intel) {
1730 DoMathDataTest<1>(g_lrintf_intel_data, lrintf);
1733 #include "math_data/modf_intel_data.h"
1734 TEST(math, modf_intel) {
1735 DoMathDataTest<1>(g_modf_intel_data, modf);
1738 #include "math_data/modff_intel_data.h"
1739 TEST(math, modff_intel) {
1740 DoMathDataTest<1>(g_modff_intel_data, modff);
1743 #include "math_data/nearbyint_intel_data.h"
1744 TEST(math, nearbyint_intel) {
1745 DoMathDataTest<1>(g_nearbyint_intel_data, nearbyint);
1748 #include "math_data/nearbyintf_intel_data.h"
1749 TEST(math, nearbyintf_intel) {
1750 DoMathDataTest<1>(g_nearbyintf_intel_data, nearbyintf);
1753 #include "math_data/nextafter_intel_data.h"
1754 TEST(math, nextafter_intel) {
1755 DoMathDataTest<1>(g_nextafter_intel_data, nextafter);
1758 #include "math_data/nextafterf_intel_data.h"
1759 TEST(math, nextafterf_intel) {
1760 DoMathDataTest<1>(g_nextafterf_intel_data, nextafterf);
1763 #include "math_data/pow_intel_data.h"
1764 TEST(math, pow_intel) {
1765 DoMathDataTest<1>(g_pow_intel_data, pow);
1768 #include "math_data/powf_intel_data.h"
1769 TEST(math, powf_intel) {
1770 DoMathDataTest<1>(g_powf_intel_data, powf);
1773 #include "math_data/remainder_intel_data.h"
1774 TEST(math, remainder_intel) {
1775 DoMathDataTest<1>(g_remainder_intel_data, remainder);
1778 #include "math_data/remainderf_intel_data.h"
1779 TEST(math, remainderf_intel) {
1780 DoMathDataTest<1>(g_remainderf_intel_data, remainderf);
1783 #include "math_data/remquo_intel_data.h"
1784 TEST(math, remquo_intel) {
1785 DoMathDataTest<1>(g_remquo_intel_data, remquo);
1788 #include "math_data/remquof_intel_data.h"
1789 TEST(math, remquof_intel) {
1790 DoMathDataTest<1>(g_remquof_intel_data, remquof);
1793 #include "math_data/rint_intel_data.h"
1794 TEST(math, rint_intel) {
1795 DoMathDataTest<1>(g_rint_intel_data, rint);
1798 #include "math_data/rintf_intel_data.h"
1799 TEST(math, rintf_intel) {
1800 DoMathDataTest<1>(g_rintf_intel_data, rintf);
1803 #include "math_data/round_intel_data.h"
1804 TEST(math, round_intel) {
1805 DoMathDataTest<1>(g_round_intel_data, round);
1808 #include "math_data/roundf_intel_data.h"
1809 TEST(math, roundf_intel) {
1810 DoMathDataTest<1>(g_roundf_intel_data, roundf);
1813 #include "math_data/scalb_intel_data.h"
1814 TEST(math, scalb_intel) {
1815 DoMathDataTest<1>(g_scalb_intel_data, scalb);
1818 #include "math_data/scalbf_intel_data.h"
1819 TEST(math, scalbf_intel) {
1820 DoMathDataTest<1>(g_scalbf_intel_data, scalbf);
1823 #include "math_data/scalbn_intel_data.h"
1824 TEST(math, scalbn_intel) {
1825 DoMathDataTest<1>(g_scalbn_intel_data, scalbn);
1828 #include "math_data/scalbnf_intel_data.h"
1829 TEST(math, scalbnf_intel) {
1830 DoMathDataTest<1>(g_scalbnf_intel_data, scalbnf);
1833 #include "math_data/significand_intel_data.h"
1834 TEST(math, significand_intel) {
1835 DoMathDataTest<1>(g_significand_intel_data, significand);
1838 #include "math_data/significandf_intel_data.h"
1839 TEST(math, significandf_intel) {
1840 DoMathDataTest<1>(g_significandf_intel_data, significandf);
1843 #include "math_data/sin_intel_data.h"
1844 TEST(math, sin_intel) {
1845 DoMathDataTest<1>(g_sin_intel_data, sin);
1848 #include "math_data/sinf_intel_data.h"
1849 TEST(math, sinf_intel) {
1850 DoMathDataTest<1>(g_sinf_intel_data, sinf);
1853 #include "math_data/sinh_intel_data.h"
1854 TEST(math, sinh_intel) {
1855 DoMathDataTest<2>(g_sinh_intel_data, sinh);
1858 #include "math_data/sinhf_intel_data.h"
1859 TEST(math, sinhf_intel) {
1860 DoMathDataTest<2>(g_sinhf_intel_data, sinhf);
1863 #include "math_data/sincos_intel_data.h"
1864 TEST(math, sincos_intel) {
1865 DoMathDataTest<1>(g_sincos_intel_data, sincos);
1868 #include "math_data/sincosf_intel_data.h"
1869 TEST(math, sincosf_intel) {
1870 DoMathDataTest<1>(g_sincosf_intel_data, sincosf);
1873 #include "math_data/sqrt_intel_data.h"
1874 TEST(math, sqrt_intel) {
1875 DoMathDataTest<1>(g_sqrt_intel_data, sqrt);
1878 #include "math_data/sqrtf_intel_data.h"
1879 TEST(math, sqrtf_intel) {
1880 DoMathDataTest<1>(g_sqrtf_intel_data, sqrtf);
1883 #include "math_data/tan_intel_data.h"
1884 TEST(math, tan_intel) {
1885 DoMathDataTest<1>(g_tan_intel_data, tan);
1888 #include "math_data/tanf_intel_data.h"
1889 TEST(math, tanf_intel) {
1890 DoMathDataTest<1>(g_tanf_intel_data, tanf);
1893 #include "math_data/tanh_intel_data.h"
1894 TEST(math, tanh_intel) {
1895 DoMathDataTest<2>(g_tanh_intel_data, tanh);
1898 #include "math_data/tanhf_intel_data.h"
1899 TEST(math, tanhf_intel) {
1900 DoMathDataTest<2>(g_tanhf_intel_data, tanhf);
1903 #include "math_data/trunc_intel_data.h"
1904 TEST(math, trunc_intel) {
1905 DoMathDataTest<1>(g_trunc_intel_data, trunc);
1908 #include "math_data/truncf_intel_data.h"
1909 TEST(math, truncf_intel) {
1910 DoMathDataTest<1>(g_truncf_intel_data, truncf);