comparison tests/test-ldexpl.c @ 8590:ebe4e154c5db

Tests for module 'ldexpl'.
author Bruno Haible <bruno@clisp.org>
date Fri, 30 Mar 2007 00:21:34 +0000
parents
children a2bc90a7b7aa
comparison
equal deleted inserted replaced
8589:3334000e84a6 8590:ebe4e154c5db
1 /* Test of multiplying a 'long double' by a power of 2.
2 Copyright (C) 2007 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19
20 #include <config.h>
21
22 #include <math.h>
23
24 #include <float.h>
25 #include <stdlib.h>
26
27 #include "fpucw.h"
28 #include "isnanl-nolibm.h"
29
30 #define ASSERT(expr) if (!(expr)) abort ();
31
32 int
33 main ()
34 {
35 int i;
36 long double x;
37 long double y;
38 DECL_LONG_DOUBLE_ROUNDING
39
40 BEGIN_LONG_DOUBLE_ROUNDING ();
41
42 { /* NaN. */
43 x = 0.0L / 0.0L;
44 y = ldexpl (x, 0); ASSERT (isnanl (y));
45 y = ldexpl (x, 5); ASSERT (isnanl (y));
46 y = ldexpl (x, -5); ASSERT (isnanl (y));
47 }
48
49 { /* Positive infinity. */
50 x = 1.0L / 0.0L;
51 y = ldexpl (x, 0); ASSERT (y == x);
52 y = ldexpl (x, 5); ASSERT (y == x);
53 y = ldexpl (x, -5); ASSERT (y == x);
54 }
55
56 { /* Negative infinity. */
57 x = -1.0L / 0.0L;
58 y = ldexpl (x, 0); ASSERT (y == x);
59 y = ldexpl (x, 5); ASSERT (y == x);
60 y = ldexpl (x, -5); ASSERT (y == x);
61 }
62
63 { /* Positive zero. */
64 x = 0.0L;
65 y = ldexpl (x, 0); ASSERT (y == x);
66 y = ldexpl (x, 5); ASSERT (y == x);
67 y = ldexpl (x, -5); ASSERT (y == x);
68 }
69
70 { /* Negative zero. */
71 x = -0.0L;
72 y = ldexpl (x, 0); ASSERT (y == x);
73 y = ldexpl (x, 5); ASSERT (y == x);
74 y = ldexpl (x, -5); ASSERT (y == x);
75 }
76
77 { /* Positive finite number. */
78 x = 1.73205L;
79 y = ldexpl (x, 0); ASSERT (y == x);
80 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
81 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
82 }
83
84 { /* Negative finite number. */
85 x = -20.085536923187667742L;
86 y = ldexpl (x, 0); ASSERT (y == x);
87 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
88 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
89 }
90
91 for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
92 {
93 y = ldexpl (x, 0); ASSERT (y == x);
94 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
95 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
96 }
97 for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
98 {
99 y = ldexpl (x, 0); ASSERT (y == x);
100 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
101 if (i - 5 >= LDBL_MIN_EXP)
102 {
103 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
104 }
105 }
106 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
107 {
108 y = ldexpl (x, 0); ASSERT (y == x);
109 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
110 }
111
112 return 0;
113 }