• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 // This include (and the associated definition of __test_capture_signbit)
18 // must be placed before any files that include <cmath> (gtest.h in this case).
19 //
20 // <math.h> is required to define generic macros signbit, isfinite and
21 // several other such functions.
22 //
23 // <cmath> is required to undef declarations of these macros in the global
24 // namespace and make equivalent functions available in namespace std. Our
25 // stlport implementation does this only for signbit, isfinite, isinf and
26 // isnan.
27 //
28 // NOTE: We don't write our test using std::signbit because we want to be
29 // sure that we're testing the bionic version of signbit. The C++ libraries
30 // are free to reimplement signbit or delegate to compiler builtins if they
31 // please.
32 #include <math.h>
33 
34 namespace {
test_capture_signbit(const T in)35 template<typename T> inline int test_capture_signbit(const T in) {
36   return signbit(in);
37 }
test_capture_isfinite(const T in)38 template<typename T> inline int test_capture_isfinite(const T in) {
39   return isfinite(in);
40 }
test_capture_isnan(const T in)41 template<typename T> inline int test_capture_isnan(const T in) {
42   return isnan(in);
43 }
test_capture_isinf(const T in)44 template<typename T> inline int test_capture_isinf(const T in) {
45   return isinf(in);
46 }
47 }
48 
49 #include <gtest/gtest.h>
50 
51 #include <fenv.h>
52 #include <float.h>
53 #include <limits.h>
54 #include <stdint.h>
55 
float_subnormal()56 float float_subnormal() {
57   union {
58     float f;
59     uint32_t i;
60   } u;
61   u.i = 0x007fffff;
62   return u.f;
63 }
64 
double_subnormal()65 double double_subnormal() {
66   union {
67     double d;
68     uint64_t i;
69   } u;
70   u.i = 0x000fffffffffffffLL;
71   return u.d;
72 }
73 
ldouble_subnormal()74 long double ldouble_subnormal() {
75   union {
76     long double e;
77     unsigned char c[sizeof(long double)];
78   } u;
79 
80   // Subnormals must have a zero exponent and non zero significand.
81   // On all supported representation the 17 bit (counting from either sides)
82   // is part of the significand so it should be enough to set that.
83   // It also applies for the case sizeof(double) = sizeof(long double)
84   for (unsigned int i = 0; i < sizeof(long double); i++) {
85     u.c[i] = 0x00;
86   }
87   u.c[sizeof(long double) - 3] = 0x80;
88   u.c[2] = 0x80;
89 
90   return u.e;
91 }
92 
TEST(math,fpclassify)93 TEST(math, fpclassify) {
94   ASSERT_EQ(FP_INFINITE, fpclassify(INFINITY));
95   ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VALF));
96   ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VAL));
97   ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VALL));
98 
99   ASSERT_EQ(FP_NAN, fpclassify(nanf("")));
100   ASSERT_EQ(FP_NAN, fpclassify(nan("")));
101   ASSERT_EQ(FP_NAN, fpclassify(nanl("")));
102 
103   ASSERT_EQ(FP_NORMAL, fpclassify(1.0f));
104   ASSERT_EQ(FP_NORMAL, fpclassify(1.0));
105   ASSERT_EQ(FP_NORMAL, fpclassify(1.0L));
106 
107   ASSERT_EQ(FP_SUBNORMAL, fpclassify(float_subnormal()));
108   ASSERT_EQ(FP_SUBNORMAL, fpclassify(double_subnormal()));
109   ASSERT_EQ(FP_SUBNORMAL, fpclassify(ldouble_subnormal()));
110 
111   ASSERT_EQ(FP_ZERO, fpclassify(0.0f));
112   ASSERT_EQ(FP_ZERO, fpclassify(0.0));
113   ASSERT_EQ(FP_ZERO, fpclassify(0.0L));
114 }
115 
TEST(math,isfinite)116 TEST(math, isfinite) {
117   ASSERT_TRUE(test_capture_isfinite(123.0f));
118   ASSERT_TRUE(test_capture_isfinite(123.0));
119   ASSERT_TRUE(test_capture_isfinite(123.0L));
120   ASSERT_FALSE(test_capture_isfinite(HUGE_VALF));
121   ASSERT_FALSE(test_capture_isfinite(HUGE_VAL));
122   ASSERT_FALSE(test_capture_isfinite(HUGE_VALL));
123 }
124 
TEST(math,isinf)125 TEST(math, isinf) {
126   ASSERT_FALSE(test_capture_isinf(123.0f));
127   ASSERT_FALSE(test_capture_isinf(123.0));
128   ASSERT_FALSE(test_capture_isinf(123.0L));
129   ASSERT_TRUE(test_capture_isinf(HUGE_VALF));
130   ASSERT_TRUE(test_capture_isinf(HUGE_VAL));
131   ASSERT_TRUE(test_capture_isinf(HUGE_VALL));
132 }
133 
TEST(math,isnan)134 TEST(math, isnan) {
135   ASSERT_FALSE(test_capture_isnan(123.0f));
136   ASSERT_FALSE(test_capture_isnan(123.0));
137   ASSERT_FALSE(test_capture_isnan(123.0L));
138   ASSERT_TRUE(test_capture_isnan(nanf("")));
139   ASSERT_TRUE(test_capture_isnan(nan("")));
140   ASSERT_TRUE(test_capture_isnan(nanl("")));
141 }
142 
TEST(math,isnormal)143 TEST(math, isnormal) {
144   ASSERT_TRUE(isnormal(123.0f));
145   ASSERT_TRUE(isnormal(123.0));
146   ASSERT_TRUE(isnormal(123.0L));
147   ASSERT_FALSE(isnormal(float_subnormal()));
148   ASSERT_FALSE(isnormal(double_subnormal()));
149   ASSERT_FALSE(isnormal(ldouble_subnormal()));
150 }
151 
152 // TODO: isgreater, isgreaterequals, isless, islessequal, islessgreater, isunordered
TEST(math,signbit)153 TEST(math, signbit) {
154   ASSERT_EQ(0, test_capture_signbit(0.0f));
155   ASSERT_EQ(0, test_capture_signbit(0.0));
156   ASSERT_EQ(0, test_capture_signbit(0.0L));
157 
158   ASSERT_EQ(0, test_capture_signbit(1.0f));
159   ASSERT_EQ(0, test_capture_signbit(1.0));
160   ASSERT_EQ(0, test_capture_signbit(1.0L));
161 
162   ASSERT_NE(0, test_capture_signbit(-1.0f));
163   ASSERT_NE(0, test_capture_signbit(-1.0));
164   ASSERT_NE(0, test_capture_signbit(-1.0L));
165 }
166 
TEST(math,__fpclassifyd)167 TEST(math, __fpclassifyd) {
168 #if defined(__BIONIC__)
169   ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL));
170   ASSERT_EQ(FP_NAN, __fpclassifyd(nan("")));
171   ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0));
172   ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal()));
173   ASSERT_EQ(FP_ZERO, __fpclassifyd(0.0));
174 #else // __BIONIC__
175   GTEST_LOG_(INFO) << "This test does nothing.\n";
176 #endif // __BIONIC__
177 }
178 
TEST(math,__fpclassifyf)179 TEST(math, __fpclassifyf) {
180 #if defined(__BIONIC__)
181   ASSERT_EQ(FP_INFINITE, __fpclassifyf(HUGE_VALF));
182   ASSERT_EQ(FP_NAN, __fpclassifyf(nanf("")));
183   ASSERT_EQ(FP_NORMAL, __fpclassifyf(1.0f));
184   ASSERT_EQ(FP_SUBNORMAL, __fpclassifyf(float_subnormal()));
185   ASSERT_EQ(FP_ZERO, __fpclassifyf(0.0f));
186 #else // __BIONIC__
187   GTEST_LOG_(INFO) << "This test does nothing.\n";
188 #endif // __BIONIC__
189 }
190 
TEST(math,__fpclassifyl)191 TEST(math, __fpclassifyl) {
192 #if defined(__BIONIC__)
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));
198 #else // __BIONIC__
199   GTEST_LOG_(INFO) << "This test does nothing.\n";
200 #endif // __BIONIC__
201 }
202 
TEST(math,finitef)203 TEST(math, finitef) {
204   ASSERT_TRUE(finitef(123.0f));
205   ASSERT_FALSE(finitef(HUGE_VALF));
206 }
207 
TEST(math,__isfinite)208 TEST(math, __isfinite) {
209 #if defined(__BIONIC__)
210   ASSERT_TRUE(__isfinite(123.0));
211   ASSERT_FALSE(__isfinite(HUGE_VAL));
212 #else // __BIONIC__
213   GTEST_LOG_(INFO) << "This test does nothing.\n";
214 #endif // __BIONIC__
215 }
216 
TEST(math,__isfinitef)217 TEST(math, __isfinitef) {
218 #if defined(__BIONIC__)
219   ASSERT_TRUE(__isfinitef(123.0f));
220   ASSERT_FALSE(__isfinitef(HUGE_VALF));
221 #else // __BIONIC__
222   GTEST_LOG_(INFO) << "This test does nothing.\n";
223 #endif // __BIONIC__
224 }
225 
TEST(math,__isfinitel)226 TEST(math, __isfinitel) {
227 #if defined(__BIONIC__)
228   ASSERT_TRUE(__isfinitel(123.0L));
229   ASSERT_FALSE(__isfinitel(HUGE_VALL));
230 #else // __BIONIC__
231   GTEST_LOG_(INFO) << "This test does nothing.\n";
232 #endif // __BIONIC__
233 }
234 
TEST(math,finite)235 TEST(math, finite) {
236   ASSERT_TRUE(finite(123.0));
237   ASSERT_FALSE(finite(HUGE_VAL));
238 }
239 
TEST(math,isinf_function)240 TEST(math, isinf_function) {
241   // The isinf macro deals with all three types; the isinf function is for doubles.
242   ASSERT_FALSE((isinf)(123.0));
243   ASSERT_TRUE((isinf)(HUGE_VAL));
244 }
245 
TEST(math,__isinff)246 TEST(math, __isinff) {
247   ASSERT_FALSE(__isinff(123.0f));
248   ASSERT_TRUE(__isinff(HUGE_VALF));
249 }
250 
TEST(math,__isinfl)251 TEST(math, __isinfl) {
252   ASSERT_FALSE(__isinfl(123.0L));
253   ASSERT_TRUE(__isinfl(HUGE_VALL));
254 }
255 
TEST(math,isnan_function)256 TEST(math, isnan_function) {
257   // The isnan macro deals with all three types; the isnan function is for doubles.
258   ASSERT_FALSE((isnan)(123.0));
259   ASSERT_TRUE((isnan)(nan("")));
260 }
261 
TEST(math,__isnanf)262 TEST(math, __isnanf) {
263   ASSERT_FALSE(__isnanf(123.0f));
264   ASSERT_TRUE(__isnanf(nanf("")));
265 }
266 
TEST(math,__isnanl)267 TEST(math, __isnanl) {
268   ASSERT_FALSE(__isnanl(123.0L));
269   ASSERT_TRUE(__isnanl(nanl("")));
270 }
271 
TEST(math,isnanf)272 TEST(math, isnanf) {
273   ASSERT_FALSE(isnanf(123.0f));
274   ASSERT_TRUE(isnanf(nanf("")));
275 }
276 
TEST(math,__isnormal)277 TEST(math, __isnormal) {
278 #if defined(__BIONIC__)
279   ASSERT_TRUE(__isnormal(123.0));
280   ASSERT_FALSE(__isnormal(double_subnormal()));
281 #else // __BIONIC__
282   GTEST_LOG_(INFO) << "This test does nothing.\n";
283 #endif // __BIONIC__
284 }
285 
TEST(math,__isnormalf)286 TEST(math, __isnormalf) {
287 #if defined(__BIONIC__)
288   ASSERT_TRUE(__isnormalf(123.0f));
289   ASSERT_FALSE(__isnormalf(float_subnormal()));
290 #else // __BIONIC__
291   GTEST_LOG_(INFO) << "This test does nothing.\n";
292 #endif // __BIONIC__
293 }
294 
TEST(math,__isnormall)295 TEST(math, __isnormall) {
296 #if defined(__BIONIC__)
297   ASSERT_TRUE(__isnormall(123.0L));
298   ASSERT_FALSE(__isnormall(ldouble_subnormal()));
299 #else // __BIONIC__
300   GTEST_LOG_(INFO) << "This test does nothing.\n";
301 #endif // __BIONIC__
302 }
303 
TEST(math,__signbit)304 TEST(math, __signbit) {
305   ASSERT_EQ(0, __signbit(0.0));
306   ASSERT_EQ(0, __signbit(1.0));
307   ASSERT_NE(0, __signbit(-1.0));
308 }
309 
TEST(math,__signbitf)310 TEST(math, __signbitf) {
311   ASSERT_EQ(0, __signbitf(0.0f));
312   ASSERT_EQ(0, __signbitf(1.0f));
313   ASSERT_NE(0, __signbitf(-1.0f));
314 }
315 
TEST(math,__signbitl)316 TEST(math, __signbitl) {
317   ASSERT_EQ(0L, __signbitl(0.0L));
318   ASSERT_EQ(0L, __signbitl(1.0L));
319   ASSERT_NE(0L, __signbitl(-1.0L));
320 }
321 
TEST(math,acos)322 TEST(math, acos) {
323   ASSERT_DOUBLE_EQ(M_PI/2.0, acos(0.0));
324 }
325 
TEST(math,acosf)326 TEST(math, acosf) {
327   ASSERT_FLOAT_EQ(static_cast<float>(M_PI)/2.0f, acosf(0.0f));
328 }
329 
TEST(math,acosl)330 TEST(math, acosl) {
331   ASSERT_DOUBLE_EQ(M_PI/2.0L, acosl(0.0L));
332 }
333 
TEST(math,asin)334 TEST(math, asin) {
335   ASSERT_DOUBLE_EQ(0.0, asin(0.0));
336 }
337 
TEST(math,asinf)338 TEST(math, asinf) {
339   ASSERT_FLOAT_EQ(0.0f, asinf(0.0f));
340 }
341 
TEST(math,asinl)342 TEST(math, asinl) {
343   ASSERT_DOUBLE_EQ(0.0L, asinl(0.0L));
344 }
345 
TEST(math,atan)346 TEST(math, atan) {
347   ASSERT_DOUBLE_EQ(0.0, atan(0.0));
348 }
349 
TEST(math,atanf)350 TEST(math, atanf) {
351   ASSERT_FLOAT_EQ(0.0f, atanf(0.0f));
352 }
353 
TEST(math,atanl)354 TEST(math, atanl) {
355   ASSERT_DOUBLE_EQ(0.0L, atanl(0.0L));
356 }
357 
TEST(math,atan2)358 TEST(math, atan2) {
359   ASSERT_DOUBLE_EQ(0.0, atan2(0.0, 0.0));
360 }
361 
TEST(math,atan2f)362 TEST(math, atan2f) {
363   ASSERT_FLOAT_EQ(0.0f, atan2f(0.0f, 0.0f));
364 }
365 
TEST(math,atan2l)366 TEST(math, atan2l) {
367   ASSERT_DOUBLE_EQ(0.0L, atan2l(0.0L, 0.0L));
368 }
369 
TEST(math,cos)370 TEST(math, cos) {
371   ASSERT_DOUBLE_EQ(1.0, cos(0.0));
372 }
373 
TEST(math,cosf)374 TEST(math, cosf) {
375   ASSERT_FLOAT_EQ(1.0f, cosf(0.0f));
376 }
377 
TEST(math,cosl)378 TEST(math, cosl) {
379   ASSERT_DOUBLE_EQ(1.0L, cosl(0.0L));
380 }
381 
TEST(math,sin)382 TEST(math, sin) {
383   ASSERT_DOUBLE_EQ(0.0, sin(0.0));
384 }
385 
TEST(math,sinf)386 TEST(math, sinf) {
387   ASSERT_FLOAT_EQ(0.0f, sinf(0.0f));
388 }
389 
TEST(math,sinl)390 TEST(math, sinl) {
391   ASSERT_DOUBLE_EQ(0.0L, sinl(0.0L));
392 }
393 
TEST(math,tan)394 TEST(math, tan) {
395   ASSERT_DOUBLE_EQ(0.0, tan(0.0));
396 }
397 
TEST(math,tanf)398 TEST(math, tanf) {
399   ASSERT_FLOAT_EQ(0.0f, tanf(0.0f));
400 }
401 
TEST(math,tanl)402 TEST(math, tanl) {
403   ASSERT_DOUBLE_EQ(0.0L, tanl(0.0L));
404 }
405 
TEST(math,acosh)406 TEST(math, acosh) {
407   ASSERT_DOUBLE_EQ(0.0, acosh(1.0));
408 }
409 
TEST(math,acoshf)410 TEST(math, acoshf) {
411   ASSERT_FLOAT_EQ(0.0f, acoshf(1.0f));
412 }
413 
TEST(math,acoshl)414 TEST(math, acoshl) {
415   ASSERT_DOUBLE_EQ(0.0L, acoshl(1.0L));
416 }
417 
TEST(math,asinh)418 TEST(math, asinh) {
419   ASSERT_DOUBLE_EQ(0.0, asinh(0.0));
420 }
421 
TEST(math,asinhf)422 TEST(math, asinhf) {
423   ASSERT_FLOAT_EQ(0.0f, asinhf(0.0f));
424 }
425 
TEST(math,asinhl)426 TEST(math, asinhl) {
427   ASSERT_DOUBLE_EQ(0.0L, asinhl(0.0L));
428 }
429 
TEST(math,atanh)430 TEST(math, atanh) {
431   ASSERT_DOUBLE_EQ(0.0, atanh(0.0));
432 }
433 
TEST(math,atanhf)434 TEST(math, atanhf) {
435   ASSERT_FLOAT_EQ(0.0f, atanhf(0.0f));
436 }
437 
TEST(math,atanhl)438 TEST(math, atanhl) {
439   ASSERT_DOUBLE_EQ(0.0L, atanhl(0.0L));
440 }
441 
TEST(math,cosh)442 TEST(math, cosh) {
443   ASSERT_DOUBLE_EQ(1.0, cosh(0.0));
444 }
445 
TEST(math,coshf)446 TEST(math, coshf) {
447   ASSERT_FLOAT_EQ(1.0f, coshf(0.0f));
448 }
449 
TEST(math,coshl)450 TEST(math, coshl) {
451   ASSERT_DOUBLE_EQ(1.0L, coshl(0.0L));
452 }
453 
TEST(math,sinh)454 TEST(math, sinh) {
455   ASSERT_DOUBLE_EQ(0.0, sinh(0.0));
456 }
457 
TEST(math,sinhf)458 TEST(math, sinhf) {
459   ASSERT_FLOAT_EQ(0.0f, sinhf(0.0f));
460 }
461 
TEST(math,sinhl)462 TEST(math, sinhl) {
463   ASSERT_DOUBLE_EQ(0.0L, sinhl(0.0L));
464 }
465 
TEST(math,tanh)466 TEST(math, tanh) {
467   ASSERT_DOUBLE_EQ(0.0, tanh(0.0));
468 }
469 
TEST(math,tanhf)470 TEST(math, tanhf) {
471   ASSERT_FLOAT_EQ(0.0f, tanhf(0.0f));
472 }
473 
TEST(math,tanhl)474 TEST(math, tanhl) {
475   ASSERT_DOUBLE_EQ(0.0L, tanhl(0.0L));
476 }
477 
TEST(math,log)478 TEST(math, log) {
479   ASSERT_DOUBLE_EQ(1.0, log(M_E));
480 }
481 
TEST(math,logf)482 TEST(math, logf) {
483   ASSERT_FLOAT_EQ(1.0f, logf(static_cast<float>(M_E)));
484 }
485 
TEST(math,logl)486 TEST(math, logl) {
487   ASSERT_DOUBLE_EQ(1.0L, logl(M_E));
488 }
489 
TEST(math,log2)490 TEST(math, log2) {
491   ASSERT_DOUBLE_EQ(12.0, log2(4096.0));
492 }
493 
TEST(math,log2f)494 TEST(math, log2f) {
495   ASSERT_FLOAT_EQ(12.0f, log2f(4096.0f));
496 }
497 
TEST(math,log2l)498 TEST(math, log2l) {
499   ASSERT_DOUBLE_EQ(12.0L, log2l(4096.0L));
500 }
501 
TEST(math,log10)502 TEST(math, log10) {
503   ASSERT_DOUBLE_EQ(3.0, log10(1000.0));
504 }
505 
TEST(math,log10f)506 TEST(math, log10f) {
507   ASSERT_FLOAT_EQ(3.0f, log10f(1000.0f));
508 }
509 
TEST(math,log10l)510 TEST(math, log10l) {
511   ASSERT_DOUBLE_EQ(3.0L, log10l(1000.0L));
512 }
513 
TEST(math,cbrt)514 TEST(math, cbrt) {
515   ASSERT_DOUBLE_EQ(3.0, cbrt(27.0));
516 }
517 
TEST(math,cbrtf)518 TEST(math, cbrtf) {
519   ASSERT_FLOAT_EQ(3.0f, cbrtf(27.0f));
520 }
521 
TEST(math,cbrtl)522 TEST(math, cbrtl) {
523   ASSERT_DOUBLE_EQ(3.0L, cbrtl(27.0L));
524 }
525 
TEST(math,sqrt)526 TEST(math, sqrt) {
527   ASSERT_DOUBLE_EQ(2.0, sqrt(4.0));
528 }
529 
TEST(math,sqrtf)530 TEST(math, sqrtf) {
531   ASSERT_FLOAT_EQ(2.0f, sqrtf(4.0f));
532 }
533 
TEST(math,sqrtl)534 TEST(math, sqrtl) {
535   ASSERT_DOUBLE_EQ(2.0L, sqrtl(4.0L));
536 }
537 
TEST(math,exp)538 TEST(math, exp) {
539   ASSERT_DOUBLE_EQ(1.0, exp(0.0));
540   ASSERT_DOUBLE_EQ(M_E, exp(1.0));
541 }
542 
TEST(math,expf)543 TEST(math, expf) {
544   ASSERT_FLOAT_EQ(1.0f, expf(0.0f));
545   ASSERT_FLOAT_EQ(static_cast<float>(M_E), expf(1.0f));
546 }
547 
TEST(math,expl)548 TEST(math, expl) {
549   ASSERT_DOUBLE_EQ(1.0L, expl(0.0L));
550   ASSERT_DOUBLE_EQ(M_E, expl(1.0L));
551 }
552 
TEST(math,exp2)553 TEST(math, exp2) {
554   ASSERT_DOUBLE_EQ(8.0, exp2(3.0));
555 }
556 
TEST(math,exp2f)557 TEST(math, exp2f) {
558   ASSERT_FLOAT_EQ(8.0f, exp2f(3.0f));
559 }
560 
TEST(math,exp2l)561 TEST(math, exp2l) {
562   ASSERT_DOUBLE_EQ(8.0L, exp2l(3.0L));
563 }
564 
TEST(math,expm1)565 TEST(math, expm1) {
566   ASSERT_DOUBLE_EQ(M_E - 1.0, expm1(1.0));
567 }
568 
TEST(math,expm1f)569 TEST(math, expm1f) {
570   ASSERT_FLOAT_EQ(static_cast<float>(M_E) - 1.0f, expm1f(1.0f));
571 }
572 
TEST(math,expm1l)573 TEST(math, expm1l) {
574   ASSERT_DOUBLE_EQ(M_E - 1.0L, expm1l(1.0L));
575 }
576 
TEST(math,pow)577 TEST(math, pow) {
578   ASSERT_TRUE(isnan(pow(nan(""), 3.0)));
579   ASSERT_DOUBLE_EQ(1.0, (pow(1.0, nan(""))));
580   ASSERT_TRUE(isnan(pow(2.0, nan(""))));
581   ASSERT_DOUBLE_EQ(8.0, pow(2.0, 3.0));
582 }
583 
TEST(math,powf)584 TEST(math, powf) {
585   ASSERT_TRUE(isnanf(powf(nanf(""), 3.0f)));
586   ASSERT_FLOAT_EQ(1.0f, (powf(1.0f, nanf(""))));
587   ASSERT_TRUE(isnanf(powf(2.0f, nanf(""))));
588   ASSERT_FLOAT_EQ(8.0f, powf(2.0f, 3.0f));
589 }
590 
TEST(math,powl)591 TEST(math, powl) {
592   ASSERT_TRUE(__isnanl(powl(nanl(""), 3.0L)));
593   ASSERT_DOUBLE_EQ(1.0L, (powl(1.0L, nanl(""))));
594   ASSERT_TRUE(__isnanl(powl(2.0L, nanl(""))));
595   ASSERT_DOUBLE_EQ(8.0L, powl(2.0L, 3.0L));
596 }
597 
TEST(math,ceil)598 TEST(math, ceil) {
599   ASSERT_DOUBLE_EQ(1.0, ceil(0.9));
600 }
601 
TEST(math,ceilf)602 TEST(math, ceilf) {
603   ASSERT_FLOAT_EQ(1.0f, ceilf(0.9f));
604 }
605 
TEST(math,ceill)606 TEST(math, ceill) {
607   ASSERT_DOUBLE_EQ(1.0L, ceill(0.9L));
608 }
609 
TEST(math,floor)610 TEST(math, floor) {
611   ASSERT_DOUBLE_EQ(1.0, floor(1.1));
612 }
613 
TEST(math,floorf)614 TEST(math, floorf) {
615   ASSERT_FLOAT_EQ(1.0f, floorf(1.1f));
616 }
617 
TEST(math,floorl)618 TEST(math, floorl) {
619   ASSERT_DOUBLE_EQ(1.0L, floorl(1.1L));
620 }
621 
TEST(math,fabs)622 TEST(math, fabs) {
623   ASSERT_DOUBLE_EQ(1.0, fabs(-1.0));
624 }
625 
TEST(math,fabsf)626 TEST(math, fabsf) {
627   ASSERT_FLOAT_EQ(1.0f, fabsf(-1.0f));
628 }
629 
TEST(math,fabsl)630 TEST(math, fabsl) {
631   ASSERT_DOUBLE_EQ(1.0L, fabsl(-1.0L));
632 }
633 
TEST(math,ldexp)634 TEST(math, ldexp) {
635   ASSERT_DOUBLE_EQ(16.0, ldexp(2.0, 3.0));
636 }
637 
TEST(math,ldexpf)638 TEST(math, ldexpf) {
639   ASSERT_FLOAT_EQ(16.0f, ldexpf(2.0f, 3.0f));
640 }
641 
TEST(math,ldexpl)642 TEST(math, ldexpl) {
643   ASSERT_DOUBLE_EQ(16.0L, ldexpl(2.0L, 3.0));
644 }
645 
TEST(math,fmod)646 TEST(math, fmod) {
647   ASSERT_DOUBLE_EQ(2.0, fmod(12.0, 10.0));
648 }
649 
TEST(math,fmodf)650 TEST(math, fmodf) {
651   ASSERT_FLOAT_EQ(2.0f, fmodf(12.0f, 10.0f));
652 }
653 
TEST(math,fmodl)654 TEST(math, fmodl) {
655   ASSERT_DOUBLE_EQ(2.0L, fmodl(12.0L, 10.0L));
656 }
657 
TEST(math,remainder)658 TEST(math, remainder) {
659   ASSERT_DOUBLE_EQ(2.0, remainder(12.0, 10.0));
660 }
661 
TEST(math,remainderf)662 TEST(math, remainderf) {
663   ASSERT_FLOAT_EQ(2.0f, remainderf(12.0f, 10.0f));
664 }
665 
TEST(math,remainderl)666 TEST(math, remainderl) {
667   ASSERT_DOUBLE_EQ(2.0L, remainderl(12.0L, 10.0L));
668 }
669 
TEST(math,drem)670 TEST(math, drem) {
671   ASSERT_DOUBLE_EQ(2.0, drem(12.0, 10.0));
672 }
673 
TEST(math,dremf)674 TEST(math, dremf) {
675   ASSERT_FLOAT_EQ(2.0f, dremf(12.0f, 10.0f));
676 }
677 
TEST(math,fmax)678 TEST(math, fmax) {
679   ASSERT_DOUBLE_EQ(12.0, fmax(12.0, 10.0));
680   ASSERT_DOUBLE_EQ(12.0, fmax(12.0, nan("")));
681   ASSERT_DOUBLE_EQ(12.0, fmax(nan(""), 12.0));
682 }
683 
TEST(math,fmaxf)684 TEST(math, fmaxf) {
685   ASSERT_FLOAT_EQ(12.0f, fmaxf(12.0f, 10.0f));
686   ASSERT_FLOAT_EQ(12.0f, fmaxf(12.0f, nanf("")));
687   ASSERT_FLOAT_EQ(12.0f, fmaxf(nanf(""), 12.0f));
688 }
689 
TEST(math,fmaxl)690 TEST(math, fmaxl) {
691   ASSERT_DOUBLE_EQ(12.0L, fmaxl(12.0L, 10.0L));
692   ASSERT_DOUBLE_EQ(12.0L, fmaxl(12.0L, nanl("")));
693   ASSERT_DOUBLE_EQ(12.0L, fmaxl(nanl(""), 12.0L));
694 }
695 
TEST(math,fmin)696 TEST(math, fmin) {
697   ASSERT_DOUBLE_EQ(10.0, fmin(12.0, 10.0));
698   ASSERT_DOUBLE_EQ(12.0, fmin(12.0, nan("")));
699   ASSERT_DOUBLE_EQ(12.0, fmin(nan(""), 12.0));
700 }
701 
TEST(math,fminf)702 TEST(math, fminf) {
703   ASSERT_FLOAT_EQ(10.0f, fminf(12.0f, 10.0f));
704   ASSERT_FLOAT_EQ(12.0f, fminf(12.0f, nanf("")));
705   ASSERT_FLOAT_EQ(12.0f, fminf(nanf(""), 12.0f));
706 }
707 
TEST(math,fminl)708 TEST(math, fminl) {
709   ASSERT_DOUBLE_EQ(10.0L, fminl(12.0L, 10.0L));
710   ASSERT_DOUBLE_EQ(12.0L, fminl(12.0L, nanl("")));
711   ASSERT_DOUBLE_EQ(12.0L, fminl(nanl(""), 12.0L));
712 }
713 
TEST(math,fma)714 TEST(math, fma) {
715   ASSERT_DOUBLE_EQ(10.0, fma(2.0, 3.0, 4.0));
716 }
717 
TEST(math,fmaf)718 TEST(math, fmaf) {
719   ASSERT_FLOAT_EQ(10.0f, fmaf(2.0f, 3.0f, 4.0f));
720 }
721 
TEST(math,fmal)722 TEST(math, fmal) {
723   ASSERT_DOUBLE_EQ(10.0L, fmal(2.0L, 3.0L, 4.0L));
724 }
725 
TEST(math,hypot)726 TEST(math, hypot) {
727   ASSERT_DOUBLE_EQ(5.0, hypot(3.0, 4.0));
728 }
729 
TEST(math,hypotf)730 TEST(math, hypotf) {
731   ASSERT_FLOAT_EQ(5.0f, hypotf(3.0f, 4.0f));
732 }
733 
TEST(math,hypotl)734 TEST(math, hypotl) {
735   ASSERT_DOUBLE_EQ(5.0L, hypotl(3.0L, 4.0L));
736 }
737 
TEST(math,erf)738 TEST(math, erf) {
739   ASSERT_DOUBLE_EQ(0.84270079294971489, erf(1.0));
740 }
741 
TEST(math,erff)742 TEST(math, erff) {
743   ASSERT_FLOAT_EQ(0.84270078f, erff(1.0f));
744 }
745 
TEST(math,erfl)746 TEST(math, erfl) {
747   ASSERT_DOUBLE_EQ(0.84270079294971489L, erfl(1.0L));
748 }
749 
TEST(math,erfc)750 TEST(math, erfc) {
751   ASSERT_DOUBLE_EQ(0.15729920705028513, erfc(1.0));
752 }
753 
TEST(math,erfcf)754 TEST(math, erfcf) {
755   ASSERT_FLOAT_EQ(0.15729921f, erfcf(1.0f));
756 }
757 
TEST(math,erfcl)758 TEST(math, erfcl) {
759   ASSERT_DOUBLE_EQ(0.15729920705028513l, erfcl(1.0L));
760 }
761 
TEST(math,lrint)762 TEST(math, lrint) {
763   fesetround(FE_UPWARD); // lrint/lrintf/lrintl obey the rounding mode.
764   ASSERT_EQ(1235, lrint(1234.01));
765   ASSERT_EQ(1235, lrintf(1234.01f));
766   ASSERT_EQ(1235, lrintl(1234.01L));
767   fesetround(FE_TOWARDZERO); // lrint/lrintf/lrintl obey the rounding mode.
768   ASSERT_EQ(1234, lrint(1234.01));
769   ASSERT_EQ(1234, lrintf(1234.01f));
770   ASSERT_EQ(1234, lrintl(1234.01L));
771 
772   fesetround(FE_UPWARD); // llrint/llrintf/llrintl obey the rounding mode.
773   ASSERT_EQ(1235L, llrint(1234.01));
774   ASSERT_EQ(1235L, llrintf(1234.01f));
775   ASSERT_EQ(1235L, llrintl(1234.01L));
776   fesetround(FE_TOWARDZERO); // llrint/llrintf/llrintl obey the rounding mode.
777   ASSERT_EQ(1234L, llrint(1234.01));
778   ASSERT_EQ(1234L, llrintf(1234.01f));
779   ASSERT_EQ(1234L, llrintl(1234.01L));
780 }
781 
TEST(math,rint)782 TEST(math, rint) {
783   fesetround(FE_UPWARD); // rint/rintf/rintl obey the rounding mode.
784   feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
785   ASSERT_EQ(1234.0, rint(1234.0));
786   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
787   ASSERT_EQ(1235.0, rint(1234.01));
788   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
789 
790   feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
791   ASSERT_EQ(1234.0f, rintf(1234.0f));
792   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
793   ASSERT_EQ(1235.0f, rintf(1234.01f));
794   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
795 
796   feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
797   ASSERT_EQ(1234.0, rintl(1234.0L));
798   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
799   ASSERT_EQ(1235.0, rintl(1234.01L));
800   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
801 
802   fesetround(FE_TOWARDZERO); // rint/rintf obey the rounding mode.
803   ASSERT_EQ(1234.0, rint(1234.01));
804   ASSERT_EQ(1234.0f, rintf(1234.01f));
805   ASSERT_EQ(1234.0, rintl(1234.01L));
806 }
807 
TEST(math,nearbyint)808 TEST(math, nearbyint) {
809   fesetround(FE_UPWARD); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
810   feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
811   ASSERT_EQ(1234.0, nearbyint(1234.0));
812   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
813   ASSERT_EQ(1235.0, nearbyint(1234.01));
814   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
815 
816   feclearexcept(FE_ALL_EXCEPT);
817   ASSERT_EQ(1234.0f, nearbyintf(1234.0f));
818   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
819   ASSERT_EQ(1235.0f, nearbyintf(1234.01f));
820   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
821 
822   feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
823   ASSERT_EQ(1234.0, nearbyintl(1234.0L));
824   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
825   ASSERT_EQ(1235.0, nearbyintl(1234.01L));
826   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
827 
828   fesetround(FE_TOWARDZERO); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
829   ASSERT_EQ(1234.0, nearbyint(1234.01));
830   ASSERT_EQ(1234.0f, nearbyintf(1234.01f));
831   ASSERT_EQ(1234.0, nearbyintl(1234.01L));
832 }
833 
TEST(math,lround)834 TEST(math, lround) {
835   fesetround(FE_UPWARD); // lround ignores the rounding mode.
836   ASSERT_EQ(1234, lround(1234.01));
837   ASSERT_EQ(1234, lroundf(1234.01f));
838   ASSERT_EQ(1234, lroundl(1234.01L));
839 }
840 
TEST(math,llround)841 TEST(math, llround) {
842   fesetround(FE_UPWARD); // llround ignores the rounding mode.
843   ASSERT_EQ(1234L, llround(1234.01));
844   ASSERT_EQ(1234L, llroundf(1234.01f));
845   ASSERT_EQ(1234L, llroundl(1234.01L));
846 }
847 
TEST(math,ilogb)848 TEST(math, ilogb) {
849   ASSERT_EQ(FP_ILOGB0, ilogb(0.0));
850   ASSERT_EQ(FP_ILOGBNAN, ilogb(nan("")));
851   ASSERT_EQ(INT_MAX, ilogb(HUGE_VAL));
852   ASSERT_EQ(0, ilogb(1.0));
853   ASSERT_EQ(3, ilogb(10.0));
854 }
855 
TEST(math,ilogbf)856 TEST(math, ilogbf) {
857   ASSERT_EQ(FP_ILOGB0, ilogbf(0.0f));
858   ASSERT_EQ(FP_ILOGBNAN, ilogbf(nanf("")));
859   ASSERT_EQ(INT_MAX, ilogbf(HUGE_VALF));
860   ASSERT_EQ(0, ilogbf(1.0f));
861   ASSERT_EQ(3, ilogbf(10.0f));
862 }
863 
TEST(math,ilogbl)864 TEST(math, ilogbl) {
865   ASSERT_EQ(FP_ILOGB0, ilogbl(0.0L));
866   ASSERT_EQ(FP_ILOGBNAN, ilogbl(nanl("")));
867   ASSERT_EQ(INT_MAX, ilogbl(HUGE_VALL));
868   ASSERT_EQ(0L, ilogbl(1.0L));
869   ASSERT_EQ(3L, ilogbl(10.0L));
870 }
871 
TEST(math,logb)872 TEST(math, logb) {
873   ASSERT_EQ(-HUGE_VAL, logb(0.0));
874   ASSERT_TRUE(isnan(logb(nan(""))));
875   ASSERT_TRUE(isinf(logb(HUGE_VAL)));
876   ASSERT_EQ(0.0, logb(1.0));
877   ASSERT_EQ(3.0, logb(10.0));
878 }
879 
TEST(math,logbf)880 TEST(math, logbf) {
881   ASSERT_EQ(-HUGE_VALF, logbf(0.0f));
882   ASSERT_TRUE(isnanf(logbf(nanf(""))));
883   ASSERT_TRUE(__isinff(logbf(HUGE_VALF)));
884   ASSERT_EQ(0.0f, logbf(1.0f));
885   ASSERT_EQ(3.0f, logbf(10.0f));
886 }
887 
TEST(math,logbl)888 TEST(math, logbl) {
889   ASSERT_EQ(-HUGE_VAL, logbl(0.0L));
890   ASSERT_TRUE(isnan(logbl(nanl(""))));
891   ASSERT_TRUE(isinf(logbl(HUGE_VALL)));
892   ASSERT_EQ(0.0L, logbl(1.0L));
893   ASSERT_EQ(3.0L, logbl(10.0L));
894 }
895 
TEST(math,log1p)896 TEST(math, log1p) {
897   ASSERT_EQ(-HUGE_VAL, log1p(-1.0));
898   ASSERT_TRUE(isnan(log1p(nan(""))));
899   ASSERT_TRUE(isinf(log1p(HUGE_VAL)));
900   ASSERT_DOUBLE_EQ(1.0, log1p(M_E - 1.0));
901 }
902 
TEST(math,log1pf)903 TEST(math, log1pf) {
904   ASSERT_EQ(-HUGE_VALF, log1pf(-1.0f));
905   ASSERT_TRUE(isnanf(log1pf(nanf(""))));
906   ASSERT_TRUE(__isinff(log1pf(HUGE_VALF)));
907   ASSERT_FLOAT_EQ(1.0f, log1pf(static_cast<float>(M_E) - 1.0f));
908 }
909 
TEST(math,log1pl)910 TEST(math, log1pl) {
911   ASSERT_EQ(-HUGE_VALL, log1pl(-1.0L));
912   ASSERT_TRUE(isnan(log1pl(nanl(""))));
913   ASSERT_TRUE(isinf(log1pl(HUGE_VALL)));
914   ASSERT_DOUBLE_EQ(1.0L, log1pl(M_E - 1.0L));
915 }
916 
TEST(math,fdim)917 TEST(math, fdim) {
918   ASSERT_DOUBLE_EQ(0.0, fdim(1.0, 1.0));
919   ASSERT_DOUBLE_EQ(1.0, fdim(2.0, 1.0));
920   ASSERT_DOUBLE_EQ(0.0, fdim(1.0, 2.0));
921 }
922 
TEST(math,fdimf)923 TEST(math, fdimf) {
924   ASSERT_FLOAT_EQ(0.0f, fdimf(1.0f, 1.0f));
925   ASSERT_FLOAT_EQ(1.0f, fdimf(2.0f, 1.0f));
926   ASSERT_FLOAT_EQ(0.0f, fdimf(1.0f, 2.0f));
927 }
928 
TEST(math,fdiml)929 TEST(math, fdiml) {
930   ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 1.0L));
931   ASSERT_DOUBLE_EQ(1.0L, fdiml(2.0L, 1.0L));
932   ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 2.0L));
933 }
934 
TEST(math,round)935 TEST(math, round) {
936   fesetround(FE_TOWARDZERO); // round ignores the rounding mode and always rounds away from zero.
937   ASSERT_DOUBLE_EQ(1.0, round(0.5));
938   ASSERT_DOUBLE_EQ(-1.0, round(-0.5));
939   ASSERT_DOUBLE_EQ(0.0, round(0.0));
940   ASSERT_DOUBLE_EQ(-0.0, round(-0.0));
941   ASSERT_TRUE(isnan(round(nan(""))));
942   ASSERT_DOUBLE_EQ(HUGE_VAL, round(HUGE_VAL));
943 }
944 
TEST(math,roundf)945 TEST(math, roundf) {
946   fesetround(FE_TOWARDZERO); // roundf ignores the rounding mode and always rounds away from zero.
947   ASSERT_FLOAT_EQ(1.0f, roundf(0.5f));
948   ASSERT_FLOAT_EQ(-1.0f, roundf(-0.5f));
949   ASSERT_FLOAT_EQ(0.0f, roundf(0.0f));
950   ASSERT_FLOAT_EQ(-0.0f, roundf(-0.0f));
951   ASSERT_TRUE(isnanf(roundf(nanf(""))));
952   ASSERT_FLOAT_EQ(HUGE_VALF, roundf(HUGE_VALF));
953 }
954 
TEST(math,roundl)955 TEST(math, roundl) {
956   fesetround(FE_TOWARDZERO); // roundl ignores the rounding mode and always rounds away from zero.
957   ASSERT_DOUBLE_EQ(1.0L, roundl(0.5L));
958   ASSERT_DOUBLE_EQ(-1.0L, roundl(-0.5L));
959   ASSERT_DOUBLE_EQ(0.0L, roundl(0.0L));
960   ASSERT_DOUBLE_EQ(-0.0L, roundl(-0.0L));
961   ASSERT_TRUE(isnan(roundl(nanl(""))));
962   ASSERT_DOUBLE_EQ(HUGE_VALL, roundl(HUGE_VALL));
963 }
964 
TEST(math,trunc)965 TEST(math, trunc) {
966   fesetround(FE_UPWARD); // trunc ignores the rounding mode and always rounds toward zero.
967   ASSERT_DOUBLE_EQ(1.0, trunc(1.5));
968   ASSERT_DOUBLE_EQ(-1.0, trunc(-1.5));
969   ASSERT_DOUBLE_EQ(0.0, trunc(0.0));
970   ASSERT_DOUBLE_EQ(-0.0, trunc(-0.0));
971   ASSERT_TRUE(isnan(trunc(nan(""))));
972   ASSERT_DOUBLE_EQ(HUGE_VAL, trunc(HUGE_VAL));
973 }
974 
TEST(math,truncf)975 TEST(math, truncf) {
976   fesetround(FE_UPWARD); // truncf ignores the rounding mode and always rounds toward zero.
977   ASSERT_FLOAT_EQ(1.0f, truncf(1.5f));
978   ASSERT_FLOAT_EQ(-1.0f, truncf(-1.5f));
979   ASSERT_FLOAT_EQ(0.0f, truncf(0.0f));
980   ASSERT_FLOAT_EQ(-0.0f, truncf(-0.0f));
981   ASSERT_TRUE(isnan(truncf(nanf(""))));
982   ASSERT_FLOAT_EQ(HUGE_VALF, truncf(HUGE_VALF));
983 }
984 
TEST(math,truncl)985 TEST(math, truncl) {
986   fesetround(FE_UPWARD); // truncl ignores the rounding mode and always rounds toward zero.
987   ASSERT_DOUBLE_EQ(1.0L, truncl(1.5L));
988   ASSERT_DOUBLE_EQ(-1.0L, truncl(-1.5L));
989   ASSERT_DOUBLE_EQ(0.0L, truncl(0.0L));
990   ASSERT_DOUBLE_EQ(-0.0L, truncl(-0.0L));
991   ASSERT_TRUE(isnan(truncl(nan(""))));
992   ASSERT_DOUBLE_EQ(HUGE_VALL, truncl(HUGE_VALL));
993 }
994 
TEST(math,nextafter)995 TEST(math, nextafter) {
996   ASSERT_DOUBLE_EQ(0.0, nextafter(0.0, 0.0));
997   ASSERT_DOUBLE_EQ(4.9406564584124654e-324, nextafter(0.0, 1.0));
998   ASSERT_DOUBLE_EQ(0.0, nextafter(0.0, -1.0));
999 }
1000 
TEST(math,nextafterf)1001 TEST(math, nextafterf) {
1002   ASSERT_FLOAT_EQ(0.0f, nextafterf(0.0f, 0.0f));
1003   ASSERT_FLOAT_EQ(1.4012985e-45f, nextafterf(0.0f, 1.0f));
1004   ASSERT_FLOAT_EQ(0.0f, nextafterf(0.0f, -1.0f));
1005 }
1006 
TEST(math,nextafterl)1007 TEST(math, nextafterl) {
1008   ASSERT_DOUBLE_EQ(0.0L, nextafterl(0.0L, 0.0L));
1009   // Use a runtime value to accomodate the case when
1010   // sizeof(double) == sizeof(long double)
1011   long double smallest_positive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG);
1012   ASSERT_DOUBLE_EQ(smallest_positive, nextafterl(0.0L, 1.0L));
1013   ASSERT_DOUBLE_EQ(0.0L, nextafterl(0.0L, -1.0L));
1014 }
1015 
TEST(math,nexttoward)1016 TEST(math, nexttoward) {
1017   ASSERT_DOUBLE_EQ(0.0, nexttoward(0.0, 0.0L));
1018   ASSERT_DOUBLE_EQ(4.9406564584124654e-324, nexttoward(0.0, 1.0L));
1019   ASSERT_DOUBLE_EQ(0.0, nexttoward(0.0, -1.0L));
1020 }
1021 
TEST(math,nexttowardf)1022 TEST(math, nexttowardf) {
1023   ASSERT_FLOAT_EQ(0.0f, nexttowardf(0.0f, 0.0L));
1024   ASSERT_FLOAT_EQ(1.4012985e-45f, nexttowardf(0.0f, 1.0L));
1025   ASSERT_FLOAT_EQ(0.0f, nexttowardf(0.0f, -1.0L));
1026 }
1027 
TEST(math,nexttowardl)1028 TEST(math, nexttowardl) {
1029   ASSERT_DOUBLE_EQ(0.0L, nexttowardl(0.0L, 0.0L));
1030   // Use a runtime value to accomodate the case when
1031   // sizeof(double) == sizeof(long double)
1032   long double smallest_positive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG);
1033   ASSERT_DOUBLE_EQ(smallest_positive, nexttowardl(0.0L, 1.0L));
1034   ASSERT_DOUBLE_EQ(0.0L, nexttowardl(0.0L, -1.0L));
1035 }
1036 
TEST(math,copysign)1037 TEST(math, copysign) {
1038   ASSERT_DOUBLE_EQ(0.0, copysign(0.0, 1.0));
1039   ASSERT_DOUBLE_EQ(-0.0, copysign(0.0, -1.0));
1040   ASSERT_DOUBLE_EQ(2.0, copysign(2.0, 1.0));
1041   ASSERT_DOUBLE_EQ(-2.0, copysign(2.0, -1.0));
1042 }
1043 
TEST(math,copysignf)1044 TEST(math, copysignf) {
1045   ASSERT_FLOAT_EQ(0.0f, copysignf(0.0f, 1.0f));
1046   ASSERT_FLOAT_EQ(-0.0f, copysignf(0.0f, -1.0f));
1047   ASSERT_FLOAT_EQ(2.0f, copysignf(2.0f, 1.0f));
1048   ASSERT_FLOAT_EQ(-2.0f, copysignf(2.0f, -1.0f));
1049 }
1050 
TEST(math,copysignl)1051 TEST(math, copysignl) {
1052   ASSERT_DOUBLE_EQ(0.0L, copysignl(0.0L, 1.0L));
1053   ASSERT_DOUBLE_EQ(-0.0L, copysignl(0.0L, -1.0L));
1054   ASSERT_DOUBLE_EQ(2.0L, copysignl(2.0L, 1.0L));
1055   ASSERT_DOUBLE_EQ(-2.0L, copysignl(2.0L, -1.0L));
1056 }
1057 
TEST(math,significand)1058 TEST(math, significand) {
1059   ASSERT_DOUBLE_EQ(0.0, significand(0.0));
1060   ASSERT_DOUBLE_EQ(1.2, significand(1.2));
1061   ASSERT_DOUBLE_EQ(1.5375, significand(12.3));
1062 }
1063 
TEST(math,significandf)1064 TEST(math, significandf) {
1065   ASSERT_FLOAT_EQ(0.0f, significandf(0.0f));
1066   ASSERT_FLOAT_EQ(1.2f, significandf(1.2f));
1067   ASSERT_FLOAT_EQ(1.5375f, significandf(12.3f));
1068 }
1069 
TEST(math,significandl)1070 TEST(math, significandl) {
1071   ASSERT_DOUBLE_EQ(0.0L, significandl(0.0L));
1072   ASSERT_DOUBLE_EQ(1.2L, significandl(1.2L));
1073   ASSERT_DOUBLE_EQ(1.5375L, significandl(12.3L));
1074 }
1075 
TEST(math,scalb)1076 TEST(math, scalb) {
1077   ASSERT_DOUBLE_EQ(12.0, scalb(3.0, 2.0));
1078 }
1079 
TEST(math,scalbf)1080 TEST(math, scalbf) {
1081   ASSERT_FLOAT_EQ(12.0f, scalbf(3.0f, 2.0f));
1082 }
1083 
TEST(math,scalbln)1084 TEST(math, scalbln) {
1085   ASSERT_DOUBLE_EQ(12.0, scalbln(3.0, 2L));
1086 }
1087 
TEST(math,scalblnf)1088 TEST(math, scalblnf) {
1089   ASSERT_FLOAT_EQ(12.0f, scalblnf(3.0f, 2L));
1090 }
1091 
TEST(math,scalblnl)1092 TEST(math, scalblnl) {
1093   ASSERT_DOUBLE_EQ(12.0L, scalblnl(3.0L, 2L));
1094 }
1095 
TEST(math,scalbn)1096 TEST(math, scalbn) {
1097   ASSERT_DOUBLE_EQ(12.0, scalbn(3.0, 2));
1098 }
1099 
TEST(math,scalbnf)1100 TEST(math, scalbnf) {
1101   ASSERT_FLOAT_EQ(12.0f, scalbnf(3.0f, 2));
1102 }
1103 
TEST(math,scalbnl)1104 TEST(math, scalbnl) {
1105   ASSERT_DOUBLE_EQ(12.0L, scalbnl(3.0L, 2));
1106 }
1107 
TEST(math,gamma)1108 TEST(math, gamma) {
1109   ASSERT_DOUBLE_EQ(log(24.0), gamma(5.0));
1110 }
1111 
TEST(math,gammaf)1112 TEST(math, gammaf) {
1113   ASSERT_FLOAT_EQ(logf(24.0f), gammaf(5.0f));
1114 }
1115 
TEST(math,gamma_r)1116 TEST(math, gamma_r) {
1117 #if defined(__BIONIC__)
1118   int sign;
1119   ASSERT_DOUBLE_EQ(log(24.0), gamma_r(5.0, &sign));
1120   ASSERT_EQ(1, sign);
1121 #else // __BIONIC__
1122   GTEST_LOG_(INFO) << "This test does nothing.\n";
1123 #endif // __BIONIC__
1124 }
1125 
TEST(math,gammaf_r)1126 TEST(math, gammaf_r) {
1127 #if defined(__BIONIC__)
1128   int sign;
1129   ASSERT_FLOAT_EQ(logf(24.0f), gammaf_r(5.0f, &sign));
1130   ASSERT_EQ(1, sign);
1131 #else // __BIONIC__
1132   GTEST_LOG_(INFO) << "This test does nothing.\n";
1133 #endif // __BIONIC__
1134 }
1135 
TEST(math,lgamma)1136 TEST(math, lgamma) {
1137   ASSERT_DOUBLE_EQ(log(24.0), lgamma(5.0));
1138 }
1139 
TEST(math,lgammaf)1140 TEST(math, lgammaf) {
1141   ASSERT_FLOAT_EQ(logf(24.0f), lgammaf(5.0f));
1142 }
1143 
TEST(math,lgammal)1144 TEST(math, lgammal) {
1145   ASSERT_DOUBLE_EQ(logl(24.0L), lgammal(5.0L));
1146 }
1147 
TEST(math,lgamma_r)1148 TEST(math, lgamma_r) {
1149   int sign;
1150   ASSERT_DOUBLE_EQ(log(24.0), lgamma_r(5.0, &sign));
1151   ASSERT_EQ(1, sign);
1152 }
1153 
TEST(math,lgammaf_r)1154 TEST(math, lgammaf_r) {
1155   int sign;
1156   ASSERT_FLOAT_EQ(logf(24.0f), lgammaf_r(5.0f, &sign));
1157   ASSERT_EQ(1, sign);
1158 }
1159 
TEST(math,tgamma)1160 TEST(math, tgamma) {
1161   ASSERT_DOUBLE_EQ(24.0, tgamma(5.0));
1162 }
1163 
TEST(math,tgammaf)1164 TEST(math, tgammaf) {
1165   ASSERT_FLOAT_EQ(24.0f, tgammaf(5.0f));
1166 }
1167 
TEST(math,tgammal)1168 TEST(math, tgammal) {
1169   ASSERT_DOUBLE_EQ(24.0L, tgammal(5.0L));
1170 }
1171 
TEST(math,j0)1172 TEST(math, j0) {
1173   ASSERT_DOUBLE_EQ(1.0, j0(0.0));
1174   ASSERT_DOUBLE_EQ(0.76519768655796661, j0(1.0));
1175 }
1176 
TEST(math,j0f)1177 TEST(math, j0f) {
1178   ASSERT_FLOAT_EQ(1.0f, j0f(0.0f));
1179   ASSERT_FLOAT_EQ(0.76519769f, j0f(1.0f));
1180 }
1181 
TEST(math,j1)1182 TEST(math, j1) {
1183   ASSERT_DOUBLE_EQ(0.0, j1(0.0));
1184   ASSERT_DOUBLE_EQ(0.44005058574493355, j1(1.0));
1185 }
1186 
TEST(math,j1f)1187 TEST(math, j1f) {
1188   ASSERT_FLOAT_EQ(0.0f, j1f(0.0f));
1189   ASSERT_FLOAT_EQ(0.44005057f, j1f(1.0f));
1190 }
1191 
TEST(math,jn)1192 TEST(math, jn) {
1193   ASSERT_DOUBLE_EQ(0.0, jn(4, 0.0));
1194   ASSERT_DOUBLE_EQ(0.0024766389641099553, jn(4, 1.0));
1195 }
1196 
TEST(math,jnf)1197 TEST(math, jnf) {
1198   ASSERT_FLOAT_EQ(0.0f, jnf(4, 0.0f));
1199   ASSERT_FLOAT_EQ(0.0024766389f, jnf(4, 1.0f));
1200 }
1201 
TEST(math,y0)1202 TEST(math, y0) {
1203   ASSERT_DOUBLE_EQ(-HUGE_VAL, y0(0.0));
1204   ASSERT_DOUBLE_EQ(0.08825696421567697, y0(1.0));
1205 }
1206 
TEST(math,y0f)1207 TEST(math, y0f) {
1208   ASSERT_FLOAT_EQ(-HUGE_VALF, y0f(0.0f));
1209   ASSERT_FLOAT_EQ(0.088256963f, y0f(1.0f));
1210 }
1211 
TEST(math,y1)1212 TEST(math, y1) {
1213   ASSERT_DOUBLE_EQ(-HUGE_VAL, y1(0.0));
1214   ASSERT_DOUBLE_EQ(-0.78121282130028868, y1(1.0));
1215 }
1216 
TEST(math,y1f)1217 TEST(math, y1f) {
1218   ASSERT_FLOAT_EQ(-HUGE_VALF, y1f(0.0f));
1219   ASSERT_FLOAT_EQ(-0.78121281f, y1f(1.0f));
1220 }
1221 
TEST(math,yn)1222 TEST(math, yn) {
1223   ASSERT_DOUBLE_EQ(-HUGE_VAL, yn(4, 0.0));
1224   ASSERT_DOUBLE_EQ(-33.278423028972114, yn(4, 1.0));
1225 }
1226 
TEST(math,ynf)1227 TEST(math, ynf) {
1228   ASSERT_FLOAT_EQ(-HUGE_VALF, ynf(4, 0.0f));
1229   ASSERT_FLOAT_EQ(-33.278423f, ynf(4, 1.0f));
1230 }
1231 
TEST(math,frexp)1232 TEST(math, frexp) {
1233   int exp;
1234   double dr = frexp(1024.0, &exp);
1235   ASSERT_DOUBLE_EQ(1024.0, scalbn(dr, exp));
1236 }
1237 
TEST(math,frexpf)1238 TEST(math, frexpf) {
1239   int exp;
1240   float fr = frexpf(1024.0f, &exp);
1241   ASSERT_FLOAT_EQ(1024.0f, scalbnf(fr, exp));
1242 }
1243 
TEST(math,frexpl)1244 TEST(math, frexpl) {
1245   int exp;
1246   long double ldr = frexpl(1024.0L, &exp);
1247   ASSERT_DOUBLE_EQ(1024.0L, scalbnl(ldr, exp));
1248 }
1249 
TEST(math,modf)1250 TEST(math, modf) {
1251   double di;
1252   double df = modf(123.75, &di);
1253   ASSERT_DOUBLE_EQ(123.0, di);
1254   ASSERT_DOUBLE_EQ(0.75, df);
1255 }
1256 
TEST(math,modff)1257 TEST(math, modff) {
1258   float fi;
1259   float ff = modff(123.75f, &fi);
1260   ASSERT_FLOAT_EQ(123.0f, fi);
1261   ASSERT_FLOAT_EQ(0.75f, ff);
1262 }
1263 
TEST(math,modfl)1264 TEST(math, modfl) {
1265   long double ldi;
1266   long double ldf = modfl(123.75L, &ldi);
1267   ASSERT_DOUBLE_EQ(123.0L, ldi);
1268   ASSERT_DOUBLE_EQ(0.75L, ldf);
1269 }
1270 
TEST(math,remquo)1271 TEST(math, remquo) {
1272   int q;
1273   double d = remquo(13.0, 4.0, &q);
1274   ASSERT_EQ(3, q);
1275   ASSERT_DOUBLE_EQ(1.0, d);
1276 }
1277 
TEST(math,remquof)1278 TEST(math, remquof) {
1279   int q;
1280   float f = remquof(13.0f, 4.0f, &q);
1281   ASSERT_EQ(3, q);
1282   ASSERT_FLOAT_EQ(1.0, f);
1283 }
1284 
TEST(math,remquol)1285 TEST(math, remquol) {
1286   int q;
1287   long double ld = remquol(13.0L, 4.0L, &q);
1288   ASSERT_DOUBLE_EQ(3L, q);
1289   ASSERT_DOUBLE_EQ(1.0L, ld);
1290 }
1291 
1292 // https://code.google.com/p/android/issues/detail?id=6697
TEST(math,frexpf_public_bug_6697)1293 TEST(math, frexpf_public_bug_6697) {
1294   int exp;
1295   float fr = frexpf(14.1f, &exp);
1296   ASSERT_FLOAT_EQ(14.1f, scalbnf(fr, exp));
1297 }
1298 
TEST(math,exp2_STRICT_ALIGN_OpenBSD_bug)1299 TEST(math, exp2_STRICT_ALIGN_OpenBSD_bug) {
1300   // OpenBSD/x86's libm had a bug here, but it was already fixed in FreeBSD:
1301   // http://svnweb.FreeBSD.org/base/head/lib/msun/src/math_private.h?revision=240827&view=markup
1302   ASSERT_DOUBLE_EQ(5.0, exp2(log2(5)));
1303   ASSERT_FLOAT_EQ(5.0f, exp2f(log2f(5)));
1304   ASSERT_DOUBLE_EQ(5.0L, exp2l(log2l(5)));
1305 }
1306 
TEST(math,nextafterl_OpenBSD_bug)1307 TEST(math, nextafterl_OpenBSD_bug) {
1308   // OpenBSD/x86's libm had a bug here.
1309   ASSERT_TRUE(nextafter(1.0, 0.0) - 1.0 < 0.0);
1310   ASSERT_TRUE(nextafterf(1.0f, 0.0f) - 1.0f < 0.0f);
1311   ASSERT_TRUE(nextafterl(1.0L, 0.0L) - 1.0L < 0.0L);
1312 }
1313