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