tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libm / t_exp.c
bloba0daa1edcee6ffee7e3f0135f1d78cd399423dd3
1 /* $NetBSD: t_exp.c,v 1.3 2013/04/09 11:42:56 isaki Exp $ */
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <atf-c.h>
33 #include <math.h>
35 /* y = exp(x) */
36 static const struct {
37 double x;
38 double y;
39 double e;
40 } exp_values[] = {
41 { -10, 0.4539992976248485e-4, 1e-4, },
42 { -5, 0.6737946999085467e-2, 1e-2, },
43 { -1, 0.3678794411714423, 1e-1, },
44 { -0.1, 0.9048374180359595, 1e-1, },
45 { 0, 1.0000000000000000, 1, },
46 { 0.1, 1.1051709180756477, 1, },
47 { 1, 2.7182818284590452, 1, },
48 { 5, 148.41315910257660, 1e2, },
49 { 10, 22026.465794806718, 1e4, },
53 * exp2(3)
55 ATF_TC(exp2_nan);
56 ATF_TC_HEAD(exp2_nan, tc)
58 atf_tc_set_md_var(tc, "descr", "Test exp2(NaN) == NaN");
61 ATF_TC_BODY(exp2_nan, tc)
63 #ifndef __vax__
64 const double x = 0.0L / 0.0L;
66 if (isnan(exp2(x)) == 0)
67 atf_tc_fail_nonfatal("exp2(NaN) != NaN");
68 #endif
71 ATF_TC(exp2_inf_neg);
72 ATF_TC_HEAD(exp2_inf_neg, tc)
74 atf_tc_set_md_var(tc, "descr", "Test exp2(-Inf) == +0.0");
77 ATF_TC_BODY(exp2_inf_neg, tc)
79 #ifndef __vax__
80 const double x = -1.0L / 0.0L;
81 double y = exp2(x);
83 if (fabs(y) > 0.0 || signbit(y) != 0)
84 atf_tc_fail_nonfatal("exp2(-Inf) != +0.0");
85 #endif
88 ATF_TC(exp2_inf_pos);
89 ATF_TC_HEAD(exp2_inf_pos, tc)
91 atf_tc_set_md_var(tc, "descr", "Test exp2(+Inf) == +Inf");
94 ATF_TC_BODY(exp2_inf_pos, tc)
96 #ifndef __vax__
97 const double x = 1.0L / 0.0L;
98 double y = exp2(x);
100 if (isinf(y) == 0 || signbit(y) != 0)
101 atf_tc_fail_nonfatal("exp2(+Inf) != +Inf");
102 #endif
105 ATF_TC(exp2_product);
106 ATF_TC_HEAD(exp2_product, tc)
108 atf_tc_set_md_var(tc, "descr", "Test exp2(x + y) == exp2(x) * exp2(y)");
111 ATF_TC_BODY(exp2_product, tc)
113 #ifndef __vax__
114 const double x[] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 };
115 const double y[] = { 8.8, 7.7, 6.6, 5.5, 4.4, 3.3, 2.2, 1.1, 0.0 };
116 const double eps = 1.0e-11;
117 size_t i;
119 for (i = 0; i < __arraycount(x); i++) {
121 if (fabs(exp2(x[i] + y[i]) - (exp2(x[i]) * exp2(y[i]))) > eps)
122 atf_tc_fail_nonfatal("exp2(%0.01f + %0.01f) != exp2("
123 "%0.01f) * exp2(%0.01f)", x[i], y[i], x[i], y[i]);
125 #endif
128 ATF_TC(exp2_zero_neg);
129 ATF_TC_HEAD(exp2_zero_neg, tc)
131 atf_tc_set_md_var(tc, "descr", "Test exp2(-0.0) == 1.0");
134 ATF_TC_BODY(exp2_zero_neg, tc)
136 #ifndef __vax__
137 const double x = -0.0L;
139 if (fabs(exp2(x) - 1.0) > 0.0)
140 atf_tc_fail_nonfatal("exp2(-0.0) != 1.0");
141 #endif
144 ATF_TC(exp2_zero_pos);
145 ATF_TC_HEAD(exp2_zero_pos, tc)
147 atf_tc_set_md_var(tc, "descr", "Test exp2(+0.0) == 1.0");
150 ATF_TC_BODY(exp2_zero_pos, tc)
152 #ifndef __vax__
153 const double x = 0.0L;
155 if (fabs(exp2(x) - 1.0) > 0.0)
156 atf_tc_fail_nonfatal("exp2(+0.0) != 1.0");
157 #endif
161 * exp2f(3)
163 ATF_TC(exp2f_nan);
164 ATF_TC_HEAD(exp2f_nan, tc)
166 atf_tc_set_md_var(tc, "descr", "Test exp2f(NaN) == NaN");
169 ATF_TC_BODY(exp2f_nan, tc)
171 #ifndef __vax__
172 const float x = 0.0L / 0.0L;
174 if (isnan(exp2f(x)) == 0)
175 atf_tc_fail_nonfatal("exp2f(NaN) != NaN");
176 #endif
179 ATF_TC(exp2f_inf_neg);
180 ATF_TC_HEAD(exp2f_inf_neg, tc)
182 atf_tc_set_md_var(tc, "descr", "Test exp2f(-Inf) == +0.0");
185 ATF_TC_BODY(exp2f_inf_neg, tc)
187 #ifndef __vax__
188 const float x = -1.0L / 0.0L;
189 float y = exp2f(x);
191 if (fabsf(y) > 0.0 || signbit(y) != 0)
192 atf_tc_fail_nonfatal("exp2f(-Inf) != +0.0");
193 #endif
196 ATF_TC(exp2f_inf_pos);
197 ATF_TC_HEAD(exp2f_inf_pos, tc)
199 atf_tc_set_md_var(tc, "descr", "Test exp2f(+Inf) == +Inf");
202 ATF_TC_BODY(exp2f_inf_pos, tc)
204 #ifndef __vax__
205 const float x = 1.0L / 0.0L;
206 float y = exp2f(x);
208 if (isinf(y) == 0 || signbit(y) != 0)
209 atf_tc_fail_nonfatal("exp2f(+Inf) != +Inf");
210 #endif
213 ATF_TC(exp2f_product);
214 ATF_TC_HEAD(exp2f_product, tc)
216 atf_tc_set_md_var(tc, "descr", "Test exp2f(x+y) == exp2f(x) * exp2f(y)");
219 ATF_TC_BODY(exp2f_product, tc)
221 #ifndef __vax__
222 const float x[] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 };
223 const float y[] = { 8.8, 7.7, 6.6, 5.5, 4.4, 3.3, 2.2, 1.1, 0.0 };
224 const float eps = 1.0e-2;
225 size_t i;
227 for (i = 0; i < __arraycount(x); i++) {
229 if (fabsf(exp2f(x[i] + y[i]) -
230 (exp2f(x[i]) * exp2f(y[i]))) > eps)
231 atf_tc_fail_nonfatal("exp2f(%0.01f + %0.01f) != exp2f("
232 "%0.01f) * exp2f(%0.01f)", x[i], y[i], x[i], y[i]);
234 #endif
237 ATF_TC(exp2f_zero_neg);
238 ATF_TC_HEAD(exp2f_zero_neg, tc)
240 atf_tc_set_md_var(tc, "descr", "Test exp2f(-0.0) == 1.0");
243 ATF_TC_BODY(exp2f_zero_neg, tc)
245 #ifndef __vax__
246 const float x = -0.0L;
248 if (fabsf(exp2f(x) - 1.0) > 0.0)
249 atf_tc_fail_nonfatal("exp2f(-0.0) != 1.0");
250 #endif
253 ATF_TC(exp2f_zero_pos);
254 ATF_TC_HEAD(exp2f_zero_pos, tc)
256 atf_tc_set_md_var(tc, "descr", "Test exp2f(+0.0) == 1.0");
259 ATF_TC_BODY(exp2f_zero_pos, tc)
261 #ifndef __vax__
262 const float x = 0.0L;
264 if (fabsf(exp2f(x) - 1.0) > 0.0)
265 atf_tc_fail_nonfatal("exp2f(+0.0) != 1.0");
266 #endif
270 * exp(3)
272 ATF_TC(exp_nan);
273 ATF_TC_HEAD(exp_nan, tc)
275 atf_tc_set_md_var(tc, "descr", "Test exp(NaN) == NaN");
278 ATF_TC_BODY(exp_nan, tc)
280 #ifndef __vax__
281 const double x = 0.0L / 0.0L;
283 if (isnan(exp(x)) == 0)
284 atf_tc_fail_nonfatal("exp(NaN) != NaN");
285 #endif
288 ATF_TC(exp_inf_neg);
289 ATF_TC_HEAD(exp_inf_neg, tc)
291 atf_tc_set_md_var(tc, "descr", "Test exp(-Inf) == +0.0");
294 ATF_TC_BODY(exp_inf_neg, tc)
296 #ifndef __vax__
297 const double x = -1.0L / 0.0L;
298 double y = exp(x);
300 if (fabs(y) > 0.0 || signbit(y) != 0)
301 atf_tc_fail_nonfatal("exp(-Inf) != +0.0");
302 #endif
305 ATF_TC(exp_inf_pos);
306 ATF_TC_HEAD(exp_inf_pos, tc)
308 atf_tc_set_md_var(tc, "descr", "Test exp(+Inf) == +Inf");
311 ATF_TC_BODY(exp_inf_pos, tc)
313 #ifndef __vax__
314 const double x = 1.0L / 0.0L;
315 double y = exp(x);
317 if (isinf(y) == 0 || signbit(y) != 0)
318 atf_tc_fail_nonfatal("exp(+Inf) != +Inf");
319 #endif
322 ATF_TC(exp_product);
323 ATF_TC_HEAD(exp_product, tc)
325 atf_tc_set_md_var(tc, "descr", "Test some selected exp(x)");
328 ATF_TC_BODY(exp_product, tc)
330 #ifndef __vax__
331 double eps;
332 double x;
333 double y;
334 size_t i;
336 for (i = 0; i < __arraycount(exp_values); i++) {
337 x = exp_values[i].x;
338 y = exp_values[i].y;
339 eps = 1e-15 * exp_values[i].e;
341 if (fabs(exp(x) - y) > eps)
342 atf_tc_fail_nonfatal("exp(%0.01f) != %18.18e", x, y);
344 #endif
347 ATF_TC(exp_zero_neg);
348 ATF_TC_HEAD(exp_zero_neg, tc)
350 atf_tc_set_md_var(tc, "descr", "Test exp(-0.0) == 1.0");
353 ATF_TC_BODY(exp_zero_neg, tc)
355 #ifndef __vax__
356 const double x = -0.0L;
358 if (fabs(exp(x) - 1.0) > 0.0)
359 atf_tc_fail_nonfatal("exp(-0.0) != 1.0");
360 #endif
363 ATF_TC(exp_zero_pos);
364 ATF_TC_HEAD(exp_zero_pos, tc)
366 atf_tc_set_md_var(tc, "descr", "Test exp(+0.0) == 1.0");
369 ATF_TC_BODY(exp_zero_pos, tc)
371 #ifndef __vax__
372 const double x = 0.0L;
374 if (fabs(exp(x) - 1.0) > 0.0)
375 atf_tc_fail_nonfatal("exp(+0.0) != 1.0");
376 #endif
380 * expf(3)
382 ATF_TC(expf_nan);
383 ATF_TC_HEAD(expf_nan, tc)
385 atf_tc_set_md_var(tc, "descr", "Test expf(NaN) == NaN");
388 ATF_TC_BODY(expf_nan, tc)
390 #ifndef __vax__
391 const float x = 0.0L / 0.0L;
393 if (isnan(expf(x)) == 0)
394 atf_tc_fail_nonfatal("expf(NaN) != NaN");
395 #endif
398 ATF_TC(expf_inf_neg);
399 ATF_TC_HEAD(expf_inf_neg, tc)
401 atf_tc_set_md_var(tc, "descr", "Test expf(-Inf) == +0.0");
404 ATF_TC_BODY(expf_inf_neg, tc)
406 #ifndef __vax__
407 const float x = -1.0L / 0.0L;
408 float y = expf(x);
410 if (fabsf(y) > 0.0 || signbit(y) != 0)
411 atf_tc_fail_nonfatal("expf(-Inf) != +0.0");
412 #endif
415 ATF_TC(expf_inf_pos);
416 ATF_TC_HEAD(expf_inf_pos, tc)
418 atf_tc_set_md_var(tc, "descr", "Test expf(+Inf) == +Inf");
421 ATF_TC_BODY(expf_inf_pos, tc)
423 #ifndef __vax__
424 const float x = 1.0L / 0.0L;
425 float y = expf(x);
427 if (isinf(y) == 0 || signbit(y) != 0)
428 atf_tc_fail_nonfatal("expf(+Inf) != +Inf");
429 #endif
432 ATF_TC(expf_product);
433 ATF_TC_HEAD(expf_product, tc)
435 atf_tc_set_md_var(tc, "descr", "Test some selected expf(x)");
438 ATF_TC_BODY(expf_product, tc)
440 #ifndef __vax__
441 float eps;
442 float x;
443 float y;
444 size_t i;
446 for (i = 0; i < __arraycount(exp_values); i++) {
447 x = exp_values[i].x;
448 y = exp_values[i].y;
449 eps = 1e-6 * exp_values[i].e;
451 if (fabsf(expf(x) - y) > eps)
452 atf_tc_fail_nonfatal("expf(%0.01f) != %18.18e", x, y);
454 #endif
457 ATF_TC(expf_zero_neg);
458 ATF_TC_HEAD(expf_zero_neg, tc)
460 atf_tc_set_md_var(tc, "descr", "Test expf(-0.0) == 1.0");
463 ATF_TC_BODY(expf_zero_neg, tc)
465 #ifndef __vax__
466 const float x = -0.0L;
468 if (fabsf(expf(x) - 1.0) > 0.0)
469 atf_tc_fail_nonfatal("expf(-0.0) != 1.0");
470 #endif
473 ATF_TC(expf_zero_pos);
474 ATF_TC_HEAD(expf_zero_pos, tc)
476 atf_tc_set_md_var(tc, "descr", "Test expf(+0.0) == 1.0");
479 ATF_TC_BODY(expf_zero_pos, tc)
481 #ifndef __vax__
482 const float x = 0.0L;
484 if (fabsf(expf(x) - 1.0) > 0.0)
485 atf_tc_fail_nonfatal("expf(+0.0) != 1.0");
486 #endif
490 * expm1(3)
492 ATF_TC(expm1_nan);
493 ATF_TC_HEAD(expm1_nan, tc)
495 atf_tc_set_md_var(tc, "descr", "Test expm1(NaN) == NaN");
498 ATF_TC_BODY(expm1_nan, tc)
500 #ifndef __vax__
501 const double x = 0.0L / 0.0L;
503 if (isnan(expm1(x)) == 0)
504 atf_tc_fail_nonfatal("expm1(NaN) != NaN");
505 #endif
508 ATF_TC(expm1_inf_neg);
509 ATF_TC_HEAD(expm1_inf_neg, tc)
511 atf_tc_set_md_var(tc, "descr", "Test expm1(-Inf) == -1");
514 ATF_TC_BODY(expm1_inf_neg, tc)
516 #ifndef __vax__
517 const double x = -1.0L / 0.0L;
519 if (expm1(x) != -1.0)
520 atf_tc_fail_nonfatal("expm1(-Inf) != -1.0");
521 #endif
524 ATF_TC(expm1_inf_pos);
525 ATF_TC_HEAD(expm1_inf_pos, tc)
527 atf_tc_set_md_var(tc, "descr", "Test expm1(+Inf) == +Inf");
530 ATF_TC_BODY(expm1_inf_pos, tc)
532 #ifndef __vax__
533 const double x = 1.0L / 0.0L;
534 double y = expm1(x);
536 if (isinf(y) == 0 || signbit(y) != 0)
537 atf_tc_fail_nonfatal("expm1(+Inf) != +Inf");
538 #endif
541 ATF_TC(expm1_zero_neg);
542 ATF_TC_HEAD(expm1_zero_neg, tc)
544 atf_tc_set_md_var(tc, "descr", "Test expm1(-0.0) == -0.0");
547 ATF_TC_BODY(expm1_zero_neg, tc)
549 #ifndef __vax__
550 const double x = -0.0L;
551 double y = expm1(x);
553 if (fabs(y) > 0.0 || signbit(y) == 0)
554 atf_tc_fail_nonfatal("expm1(-0.0) != -0.0");
555 #endif
558 ATF_TC(expm1_zero_pos);
559 ATF_TC_HEAD(expm1_zero_pos, tc)
561 atf_tc_set_md_var(tc, "descr", "Test expm1(+0.0) == 1.0");
564 ATF_TC_BODY(expm1_zero_pos, tc)
566 #ifndef __vax__
567 const double x = 0.0L;
568 double y = expm1(x);
570 if (fabs(y) > 0.0 || signbit(y) != 0)
571 atf_tc_fail_nonfatal("expm1(+0.0) != +0.0");
572 #endif
576 * expm1f(3)
578 ATF_TC(expm1f_nan);
579 ATF_TC_HEAD(expm1f_nan, tc)
581 atf_tc_set_md_var(tc, "descr", "Test expm1f(NaN) == NaN");
584 ATF_TC_BODY(expm1f_nan, tc)
586 #ifndef __vax__
587 const float x = 0.0L / 0.0L;
589 if (isnan(expm1f(x)) == 0)
590 atf_tc_fail_nonfatal("expm1f(NaN) != NaN");
591 #endif
594 ATF_TC(expm1f_inf_neg);
595 ATF_TC_HEAD(expm1f_inf_neg, tc)
597 atf_tc_set_md_var(tc, "descr", "Test expm1f(-Inf) == -1");
600 ATF_TC_BODY(expm1f_inf_neg, tc)
602 #ifndef __vax__
603 const float x = -1.0L / 0.0L;
605 if (expm1f(x) != -1.0)
606 atf_tc_fail_nonfatal("expm1f(-Inf) != -1.0");
607 #endif
610 ATF_TC(expm1f_inf_pos);
611 ATF_TC_HEAD(expm1f_inf_pos, tc)
613 atf_tc_set_md_var(tc, "descr", "Test expm1f(+Inf) == +Inf");
616 ATF_TC_BODY(expm1f_inf_pos, tc)
618 #ifndef __vax__
619 const float x = 1.0L / 0.0L;
620 float y = expm1f(x);
622 if (isinf(y) == 0 || signbit(y) != 0)
623 atf_tc_fail_nonfatal("expm1f(+Inf) != +Inf");
624 #endif
627 ATF_TC(expm1f_zero_neg);
628 ATF_TC_HEAD(expm1f_zero_neg, tc)
630 atf_tc_set_md_var(tc, "descr", "Test expm1f(-0.0) == -0.0");
633 ATF_TC_BODY(expm1f_zero_neg, tc)
635 #ifndef __vax__
636 const float x = -0.0L;
637 float y = expm1f(x);
639 if (fabsf(y) > 0.0 || signbit(y) == 0)
640 atf_tc_fail_nonfatal("expm1f(-0.0) != -0.0");
641 #endif
644 ATF_TC(expm1f_zero_pos);
645 ATF_TC_HEAD(expm1f_zero_pos, tc)
647 atf_tc_set_md_var(tc, "descr", "Test expm1f(+0.0) == 1.0");
650 ATF_TC_BODY(expm1f_zero_pos, tc)
652 #ifndef __vax__
653 const float x = 0.0L;
654 float y = expm1f(x);
656 if (fabsf(y) > 0.0 || signbit(y) != 0)
657 atf_tc_fail_nonfatal("expm1f(+0.0) != +0.0");
658 #endif
661 ATF_TP_ADD_TCS(tp)
664 ATF_TP_ADD_TC(tp, exp2_nan);
665 ATF_TP_ADD_TC(tp, exp2_inf_neg);
666 ATF_TP_ADD_TC(tp, exp2_inf_pos);
667 ATF_TP_ADD_TC(tp, exp2_product);
668 ATF_TP_ADD_TC(tp, exp2_zero_neg);
669 ATF_TP_ADD_TC(tp, exp2_zero_pos);
671 ATF_TP_ADD_TC(tp, exp2f_nan);
672 ATF_TP_ADD_TC(tp, exp2f_inf_neg);
673 ATF_TP_ADD_TC(tp, exp2f_inf_pos);
674 ATF_TP_ADD_TC(tp, exp2f_product);
675 ATF_TP_ADD_TC(tp, exp2f_zero_neg);
676 ATF_TP_ADD_TC(tp, exp2f_zero_pos);
678 ATF_TP_ADD_TC(tp, exp_nan);
679 ATF_TP_ADD_TC(tp, exp_inf_neg);
680 ATF_TP_ADD_TC(tp, exp_inf_pos);
681 ATF_TP_ADD_TC(tp, exp_product);
682 ATF_TP_ADD_TC(tp, exp_zero_neg);
683 ATF_TP_ADD_TC(tp, exp_zero_pos);
685 ATF_TP_ADD_TC(tp, expf_nan);
686 ATF_TP_ADD_TC(tp, expf_inf_neg);
687 ATF_TP_ADD_TC(tp, expf_inf_pos);
688 ATF_TP_ADD_TC(tp, expf_product);
689 ATF_TP_ADD_TC(tp, expf_zero_neg);
690 ATF_TP_ADD_TC(tp, expf_zero_pos);
692 ATF_TP_ADD_TC(tp, expm1_nan);
693 ATF_TP_ADD_TC(tp, expm1_inf_neg);
694 ATF_TP_ADD_TC(tp, expm1_inf_pos);
695 ATF_TP_ADD_TC(tp, expm1_zero_neg);
696 ATF_TP_ADD_TC(tp, expm1_zero_pos);
698 ATF_TP_ADD_TC(tp, expm1f_nan);
699 ATF_TP_ADD_TC(tp, expm1f_inf_neg);
700 ATF_TP_ADD_TC(tp, expm1f_inf_pos);
701 ATF_TP_ADD_TC(tp, expm1f_zero_neg);
702 ATF_TP_ADD_TC(tp, expm1f_zero_pos);
704 return atf_no_error();