1 /* $NetBSD: ldexp.c,v 1.3 2006/05/10 19:07:22 mrg Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
39 #define FORMAT "%23.23lg\n"
43 printf(FORMAT
, ldexp(v
, e
));
45 printf(FORMAT
, ldexp(v
, e
));
46 v
= ldexp(1.0, 1023); e
= -1;
47 printf(FORMAT
, ldexp(v
, e
));
49 printf(FORMAT
, ldexp(v
, e
));
50 v
= ldexp(1.0, 1022); e
= 1;
51 printf(FORMAT
, ldexp(v
, e
));
52 v
= ldexp(1.0, -1022); e
= 2045;
53 printf(FORMAT
, ldexp(v
, e
));
55 printf(FORMAT
, ldexp(v
, e
));
57 printf(FORMAT
, ldexp(v
, e
));
58 v
= ldexp(1.0, -1022); e
= 1;
59 printf(FORMAT
, ldexp(v
, e
));
61 printf(FORMAT
, ldexp(v
, e
));
62 v
= ldexp(1.0, -1021); e
= -1;
63 printf(FORMAT
, ldexp(v
, e
));
64 v
= ldexp(1.0, 1023); e
= -2045;
65 printf(FORMAT
, ldexp(v
, e
));
66 v
= ldexp(1.0, 1023); e
= -1023;
67 printf(FORMAT
, ldexp(v
, e
));
68 v
= ldexp(1.0, -1022); e
= 1022;
69 printf(FORMAT
, ldexp(v
, e
));
74 printf(FORMAT
, ldexp(v
, e
));
76 printf(FORMAT
, ldexp(v
, e
));
78 printf(FORMAT
, ldexp(v
, e
));
80 printf(FORMAT
, ldexp(v
, e
));
82 printf(FORMAT
, ldexp(v
, e
));
84 printf(FORMAT
, ldexp(v
, e
));
86 printf(FORMAT
, ldexp(v
, e
));
89 printf("infinity:\n");
90 v
= ldexp(1.0, 1024); e
= -1;
91 printf(FORMAT
, ldexp(v
, e
));
92 v
= ldexp(1.0, 1024); e
= 0;
93 printf(FORMAT
, ldexp(v
, e
));
94 v
= ldexp(1.0, 1024); e
= 1;
95 printf(FORMAT
, ldexp(v
, e
));
96 v
= ldexp(-1.0, 1024); e
= -1;
97 printf(FORMAT
, ldexp(v
, e
));
98 v
= ldexp(-1.0, 1024); e
= 0;
99 printf(FORMAT
, ldexp(v
, e
));
100 v
= ldexp(-1.0, 1024); e
= 1;
101 printf(FORMAT
, ldexp(v
, e
));
104 printf("overflow:\n");
106 printf(FORMAT
, ldexp(v
, e
));
107 v
= ldexp(1.0, 1023); e
= 1;
108 printf(FORMAT
, ldexp(v
, e
));
109 v
= ldexp(1.0, -1022); e
= 2046;
110 printf(FORMAT
, ldexp(v
, e
));
112 printf(FORMAT
, ldexp(v
, e
));
114 printf(FORMAT
, ldexp(v
, e
));
115 v
= ldexp(-1.0, 1023); e
= 1;
116 printf(FORMAT
, ldexp(v
, e
));
117 v
= ldexp(-1.0, -1022); e
= 2046;
118 printf(FORMAT
, ldexp(v
, e
));
120 printf(FORMAT
, ldexp(v
, e
));
123 printf("denormal:\n");
125 printf(FORMAT
, ldexp(v
, e
));
126 v
= ldexp(1.0, -1022); e
= -1;
127 printf(FORMAT
, ldexp(v
, e
));
128 v
= ldexp(1.0, 1023); e
= -2046;
129 printf(FORMAT
, ldexp(v
, e
));
131 printf(FORMAT
, ldexp(v
, e
));
133 printf(FORMAT
, ldexp(v
, e
));
135 printf(FORMAT
, ldexp(v
, e
));
136 v
= ldexp(-1.0, -1022); e
= -1;
137 printf(FORMAT
, ldexp(v
, e
));
138 v
= ldexp(-1.0, 1023); e
= -2046;
139 printf(FORMAT
, ldexp(v
, e
));
141 printf(FORMAT
, ldexp(v
, e
));
143 printf(FORMAT
, ldexp(v
, e
));
146 printf("underflow:\n");
148 printf(FORMAT
, ldexp(v
, e
));
149 v
= ldexp(1.0, -1074); e
= -1;
150 printf(FORMAT
, ldexp(v
, e
));
151 v
= ldexp(1.0, 1023); e
= -2098;
152 printf(FORMAT
, ldexp(v
, e
));
154 printf(FORMAT
, ldexp(v
, e
));
156 printf(FORMAT
, ldexp(v
, e
));
157 v
= ldexp(-1.0, -1074); e
= -1;
158 printf(FORMAT
, ldexp(v
, e
));
159 v
= ldexp(-1.0, 1023); e
= -2098;
160 printf(FORMAT
, ldexp(v
, e
));
162 printf(FORMAT
, ldexp(v
, e
));
165 printf("denormal, large exponent:\n");
166 v
= ldexp(1.0, -1028); e
= 1024;
167 printf(FORMAT
, ldexp(v
, e
));
168 v
= ldexp(1.0, -1028); e
= 1025;
169 printf(FORMAT
, ldexp(v
, e
));
170 v
= ldexp(1.0, -1028); e
= 1026;
171 printf(FORMAT
, ldexp(v
, e
));
172 v
= ldexp(1.0, -1028); e
= 1027;
173 printf(FORMAT
, ldexp(v
, e
));
174 v
= ldexp(1.0, -1028); e
= 1028;
175 printf(FORMAT
, ldexp(v
, e
));
176 v
= ldexp(1.0, -1028); e
= 1029;
177 printf(FORMAT
, ldexp(v
, e
));
178 v
= ldexp(1.0, -1028); e
= 1030;
179 printf(FORMAT
, ldexp(v
, e
));
180 v
= ldexp(1.0, -1028); e
= 1040;
181 printf(FORMAT
, ldexp(v
, e
));
182 v
= ldexp(1.0, -1028); e
= 1050;
183 printf(FORMAT
, ldexp(v
, e
));
184 v
= ldexp(1.0, -1028); e
= 1060;
185 printf(FORMAT
, ldexp(v
, e
));
186 v
= ldexp(1.0, -1028); e
= 1100;
187 printf(FORMAT
, ldexp(v
, e
));
188 v
= ldexp(1.0, -1028); e
= 1200;
189 printf(FORMAT
, ldexp(v
, e
));
190 v
= ldexp(1.0, -1028); e
= 1300;
191 printf(FORMAT
, ldexp(v
, e
));
192 v
= ldexp(1.0, -1028); e
= 1400;
193 printf(FORMAT
, ldexp(v
, e
));
194 v
= ldexp(1.0, -1028); e
= 1500;
195 printf(FORMAT
, ldexp(v
, e
));
196 v
= ldexp(1.0, -1028); e
= 1600;
197 printf(FORMAT
, ldexp(v
, e
));
198 v
= ldexp(1.0, -1028); e
= 1700;
199 printf(FORMAT
, ldexp(v
, e
));
200 v
= ldexp(1.0, -1028); e
= 1800;
201 printf(FORMAT
, ldexp(v
, e
));
202 v
= ldexp(1.0, -1028); e
= 1900;
203 printf(FORMAT
, ldexp(v
, e
));
204 v
= ldexp(1.0, -1028); e
= 2000;
205 printf(FORMAT
, ldexp(v
, e
));
206 v
= ldexp(1.0, -1028); e
= 2046;
207 printf(FORMAT
, ldexp(v
, e
));
208 v
= ldexp(1.0, -1028); e
= 2047;
209 printf(FORMAT
, ldexp(v
, e
));
210 v
= ldexp(1.0, -1028); e
= 2048;
211 printf(FORMAT
, ldexp(v
, e
));
212 v
= ldexp(1.0, -1028); e
= 2049;
213 printf(FORMAT
, ldexp(v
, e
));
214 v
= ldexp(1.0, -1028); e
= 2050;
215 printf(FORMAT
, ldexp(v
, e
));
216 v
= ldexp(1.0, -1028); e
= 2051;
217 printf(FORMAT
, ldexp(v
, e
));