Print this page
11210 libm should be cstyle(1ONBLD) clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/C/_SVID_error.c
+++ new/usr/src/lib/libm/common/C/_SVID_error.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 +
21 22 /*
22 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23 24 */
25 +
24 26 /*
25 27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 28 * Use is subject to license terms.
27 29 */
28 30
29 31 #include "libm.h"
30 -#include "xpg6.h" /* __xpg6 */
32 +#include "xpg6.h" /* __xpg6 */
31 33 #include <stdio.h>
32 -#include <float.h> /* DBL_MAX, DBL_MIN */
33 -#include <unistd.h> /* write */
34 +#include <float.h> /* DBL_MAX, DBL_MIN */
35 +#include <unistd.h> /* write */
34 36 #if defined(__x86)
35 37 #include <ieeefp.h>
36 -#undef fp_class
38 +#undef fp_class
37 39 #define fp_class fpclass
38 40 #define fp_quiet FP_QNAN
39 41 #endif
40 42 #include <errno.h>
41 43 #undef fflush
42 44 #include <sys/isa_defs.h>
43 45
44 -/* INDENT OFF */
46 +
45 47 /*
46 48 * Report libm exception error according to System V Interface Definition
47 49 * (SVID).
48 50 * Error mapping:
49 51 * 1 -- acos(|x|>1)
50 52 * 2 -- asin(|x|>1)
51 53 * 3 -- atan2(+-0,+-0)
52 54 * 4 -- hypot overflow
53 55 * 5 -- cosh overflow
54 56 * 6 -- exp overflow
55 57 * 7 -- exp underflow
56 58 * 8 -- y0(0)
57 59 * 9 -- y0(-ve)
58 60 * 10-- y1(0)
59 61 * 11-- y1(-ve)
60 62 * 12-- yn(0)
61 63 * 13-- yn(-ve)
62 64 * 14-- lgamma(finite) overflow
63 65 * 15-- lgamma(-integer)
64 66 * 16-- log(0)
65 67 * 17-- log(x<0)
66 68 * 18-- log10(0)
67 69 * 19-- log10(x<0)
68 70 * 20-- pow(0.0,0.0)
69 71 * 21-- pow(x,y) overflow
70 72 * 22-- pow(x,y) underflow
71 73 * 23-- pow(0,negative)
72 74 * 24-- pow(neg,non-integral)
73 75 * 25-- sinh(finite) overflow
74 76 * 26-- sqrt(negative)
75 77 * 27-- fmod(x,0)
76 78 * 28-- remainder(x,0)
77 79 * 29-- acosh(x<1)
78 80 * 30-- atanh(|x|>1)
79 81 * 31-- atanh(|x|=1)
80 82 * 32-- scalb overflow
81 83 * 33-- scalb underflow
82 84 * 34-- j0(|x|>X_TLOSS)
83 85 * 35-- y0(x>X_TLOSS)
84 86 * 36-- j1(|x|>X_TLOSS)
85 87 * 37-- y1(x>X_TLOSS)
86 88 * 38-- jn(|x|>X_TLOSS, n)
↓ open down ↓ |
32 lines elided |
↑ open up ↑ |
87 89 * 39-- yn(x>X_TLOSS, n)
88 90 * 40-- gamma(finite) overflow
89 91 * 41-- gamma(-integer)
90 92 * 42-- pow(NaN,0.0) return NaN for SVID/XOPEN
91 93 * 43-- log1p(-1)
92 94 * 44-- log1p(x<-1)
93 95 * 45-- logb(0)
94 96 * 46-- nextafter overflow
95 97 * 47-- scalb(x,inf)
96 98 */
97 -/* INDENT ON */
98 99
99 100 static double setexception(int, double);
100 101
101 102 static const union {
102 - unsigned x[2];
103 - double d;
103 + unsigned x[2];
104 + double d;
104 105 } C[] = {
105 106 #ifdef _LITTLE_ENDIAN
106 107 { 0xffffffff, 0x7fffffff },
107 108 { 0x54442d18, 0x400921fb },
108 109 #else
109 110 { 0x7fffffff, 0xffffffff },
110 111 { 0x400921fb, 0x54442d18 },
111 112 #endif
112 113 };
113 114
114 -#define NaN C[0].d
115 -#define PI_RZ C[1].d
115 +#define NaN C[0].d
116 +#define PI_RZ C[1].d
116 117
117 -#define __HI(x) ((unsigned *)&x)[HIWORD]
118 -#define __LO(x) ((unsigned *)&x)[LOWORD]
119 -#undef Inf
120 -#define Inf HUGE_VAL
118 +#define __HI(x) ((unsigned *)&x)[HIWORD]
119 +#define __LO(x) ((unsigned *)&x)[LOWORD]
120 +#undef Inf
121 +#define Inf HUGE_VAL
121 122
122 123 double
123 -_SVID_libm_err(double x, double y, int type) {
124 - struct exception exc;
125 - double t, w, ieee_retval = 0;
126 - enum version lib_version = _lib_version;
127 - int iy;
124 +_SVID_libm_err(double x, double y, int type)
125 +{
126 + struct exception exc;
127 + double t, w, ieee_retval = 0;
128 + enum version lib_version = _lib_version;
129 + int iy;
128 130
129 131 /* force libm_ieee behavior in SUSv3 mode */
130 132 if ((__xpg6 & _C99SUSv3_math_errexcept) != 0)
131 133 lib_version = libm_ieee;
132 - if (lib_version == c_issue_4) {
134 +
135 + if (lib_version == c_issue_4)
133 136 (void) fflush(stdout);
134 - }
137 +
135 138 exc.arg1 = x;
136 139 exc.arg2 = y;
140 +
137 141 switch (type) {
138 142 case 1:
139 143 /* acos(|x|>1) */
140 144 exc.type = DOMAIN;
141 145 exc.name = "acos";
142 146 ieee_retval = setexception(3, 1.0);
143 147 exc.retval = 0.0;
148 +
144 149 if (lib_version == strict_ansi) {
145 150 errno = EDOM;
146 151 } else if (!matherr(&exc)) {
147 - if (lib_version == c_issue_4) {
152 + if (lib_version == c_issue_4)
148 153 (void) write(2, "acos: DOMAIN error\n", 19);
149 - }
154 +
150 155 errno = EDOM;
151 156 }
157 +
152 158 break;
153 159 case 2:
154 160 /* asin(|x|>1) */
155 161 exc.type = DOMAIN;
156 162 exc.name = "asin";
157 163 exc.retval = 0.0;
158 164 ieee_retval = setexception(3, 1.0);
165 +
159 166 if (lib_version == strict_ansi) {
160 167 errno = EDOM;
161 168 } else if (!matherr(&exc)) {
162 - if (lib_version == c_issue_4) {
169 + if (lib_version == c_issue_4)
163 170 (void) write(2, "asin: DOMAIN error\n", 19);
164 - }
171 +
165 172 errno = EDOM;
166 173 }
174 +
167 175 break;
168 176 case 3:
169 177 /* atan2(+-0,+-0) */
170 178 exc.arg1 = y;
171 179 exc.arg2 = x;
172 180 exc.type = DOMAIN;
173 181 exc.name = "atan2";
174 - ieee_retval = copysign(1.0, x) == 1.0 ? y :
175 - copysign(PI_RZ + DBL_MIN, y);
182 + ieee_retval = copysign(1.0, x) == 1.0 ? y : copysign(PI_RZ +
183 + DBL_MIN, y);
176 184 exc.retval = 0.0;
185 +
177 186 if (lib_version == strict_ansi) {
178 187 errno = EDOM;
179 188 } else if (!matherr(&exc)) {
180 - if (lib_version == c_issue_4) {
189 + if (lib_version == c_issue_4)
181 190 (void) write(2, "atan2: DOMAIN error\n", 20);
182 - }
191 +
183 192 errno = EDOM;
184 193 }
194 +
185 195 break;
186 196 case 4:
187 197 /* hypot(finite,finite) overflow */
188 198 exc.type = OVERFLOW;
189 199 exc.name = "hypot";
190 200 ieee_retval = Inf;
201 +
191 202 if (lib_version == c_issue_4)
192 203 exc.retval = HUGE;
193 204 else
194 205 exc.retval = HUGE_VAL;
206 +
195 207 if (lib_version == strict_ansi)
196 208 errno = ERANGE;
197 209 else if (!matherr(&exc))
198 210 errno = ERANGE;
211 +
199 212 break;
200 213 case 5:
201 214 /* cosh(finite) overflow */
202 215 exc.type = OVERFLOW;
203 216 exc.name = "cosh";
204 217 ieee_retval = setexception(2, 1.0);
218 +
205 219 if (lib_version == c_issue_4)
206 220 exc.retval = HUGE;
207 221 else
208 222 exc.retval = HUGE_VAL;
223 +
209 224 if (lib_version == strict_ansi)
210 225 errno = ERANGE;
211 226 else if (!matherr(&exc))
212 227 errno = ERANGE;
228 +
213 229 break;
214 230 case 6:
215 231 /* exp(finite) overflow */
216 232 exc.type = OVERFLOW;
217 233 exc.name = "exp";
218 234 ieee_retval = setexception(2, 1.0);
235 +
219 236 if (lib_version == c_issue_4)
220 237 exc.retval = HUGE;
221 238 else
222 239 exc.retval = HUGE_VAL;
240 +
223 241 if (lib_version == strict_ansi)
224 242 errno = ERANGE;
225 243 else if (!matherr(&exc))
226 244 errno = ERANGE;
245 +
227 246 break;
228 247 case 7:
229 248 /* exp(finite) underflow */
230 249 exc.type = UNDERFLOW;
231 250 exc.name = "exp";
232 251 ieee_retval = setexception(1, 1.0);
233 252 exc.retval = 0.0;
253 +
234 254 if (lib_version == strict_ansi)
235 255 errno = ERANGE;
236 256 else if (!matherr(&exc))
237 257 errno = ERANGE;
258 +
238 259 break;
239 260 case 8:
240 261 /* y0(0) = -inf */
241 262 exc.type = DOMAIN; /* should be SING for IEEE */
242 263 exc.name = "y0";
243 264 ieee_retval = setexception(0, -1.0);
265 +
244 266 if (lib_version == c_issue_4)
245 267 exc.retval = -HUGE;
246 268 else
247 269 exc.retval = -HUGE_VAL;
270 +
248 271 if (lib_version == strict_ansi) {
249 272 errno = EDOM;
250 273 } else if (!matherr(&exc)) {
251 - if (lib_version == c_issue_4) {
274 + if (lib_version == c_issue_4)
252 275 (void) write(2, "y0: DOMAIN error\n", 17);
253 - }
276 +
254 277 errno = EDOM;
255 278 }
279 +
256 280 break;
257 281 case 9:
258 282 /* y0(x<0) = NaN */
259 283 exc.type = DOMAIN;
260 284 exc.name = "y0";
261 285 ieee_retval = setexception(3, 1.0);
286 +
262 287 if (lib_version == c_issue_4)
263 288 exc.retval = -HUGE;
264 289 else
265 290 exc.retval = -HUGE_VAL;
291 +
266 292 if (lib_version == strict_ansi) {
267 293 errno = EDOM;
268 294 } else if (!matherr(&exc)) {
269 - if (lib_version == c_issue_4) {
295 + if (lib_version == c_issue_4)
270 296 (void) write(2, "y0: DOMAIN error\n", 17);
271 - }
297 +
272 298 errno = EDOM;
273 299 }
300 +
274 301 break;
275 302 case 10:
276 303 /* y1(0) = -inf */
277 304 exc.type = DOMAIN; /* should be SING for IEEE */
278 305 exc.name = "y1";
279 306 ieee_retval = setexception(0, -1.0);
307 +
280 308 if (lib_version == c_issue_4)
281 309 exc.retval = -HUGE;
282 310 else
283 311 exc.retval = -HUGE_VAL;
312 +
284 313 if (lib_version == strict_ansi) {
285 314 errno = EDOM;
286 315 } else if (!matherr(&exc)) {
287 - if (lib_version == c_issue_4) {
316 + if (lib_version == c_issue_4)
288 317 (void) write(2, "y1: DOMAIN error\n", 17);
289 - }
318 +
290 319 errno = EDOM;
291 320 }
321 +
292 322 break;
293 323 case 11:
294 324 /* y1(x<0) = NaN */
295 325 exc.type = DOMAIN;
296 326 exc.name = "y1";
297 327 ieee_retval = setexception(3, 1.0);
328 +
298 329 if (lib_version == c_issue_4)
299 330 exc.retval = -HUGE;
300 331 else
301 332 exc.retval = -HUGE_VAL;
333 +
302 334 if (lib_version == strict_ansi) {
303 335 errno = EDOM;
304 336 } else if (!matherr(&exc)) {
305 - if (lib_version == c_issue_4) {
337 + if (lib_version == c_issue_4)
306 338 (void) write(2, "y1: DOMAIN error\n", 17);
307 - }
339 +
308 340 errno = EDOM;
309 341 }
342 +
310 343 break;
311 344 case 12:
312 345 /* yn(n,0) = -inf */
313 346 exc.type = DOMAIN; /* should be SING for IEEE */
314 347 exc.name = "yn";
315 348 ieee_retval = setexception(0, -1.0);
349 +
316 350 if (lib_version == c_issue_4)
317 351 exc.retval = -HUGE;
318 352 else
319 353 exc.retval = -HUGE_VAL;
354 +
320 355 if (lib_version == strict_ansi) {
321 356 errno = EDOM;
322 357 } else if (!matherr(&exc)) {
323 - if (lib_version == c_issue_4) {
358 + if (lib_version == c_issue_4)
324 359 (void) write(2, "yn: DOMAIN error\n", 17);
325 - }
360 +
326 361 errno = EDOM;
327 362 }
363 +
328 364 break;
329 365 case 13:
330 366 /* yn(x<0) = NaN */
331 367 exc.type = DOMAIN;
332 368 exc.name = "yn";
333 369 ieee_retval = setexception(3, 1.0);
370 +
334 371 if (lib_version == c_issue_4)
335 372 exc.retval = -HUGE;
336 373 else
337 374 exc.retval = -HUGE_VAL;
375 +
338 376 if (lib_version == strict_ansi) {
339 377 errno = EDOM;
340 378 } else if (!matherr(&exc)) {
341 - if (lib_version == c_issue_4) {
379 + if (lib_version == c_issue_4)
342 380 (void) write(2, "yn: DOMAIN error\n", 17);
343 - }
381 +
344 382 errno = EDOM;
345 383 }
384 +
346 385 break;
347 386 case 14:
348 387 /* lgamma(finite) overflow */
349 388 exc.type = OVERFLOW;
350 389 exc.name = "lgamma";
351 390 ieee_retval = setexception(2, 1.0);
391 +
352 392 if (lib_version == c_issue_4)
353 393 exc.retval = HUGE;
354 394 else
355 395 exc.retval = HUGE_VAL;
396 +
356 397 if (lib_version == strict_ansi)
357 398 errno = ERANGE;
358 399 else if (!matherr(&exc))
359 400 errno = ERANGE;
401 +
360 402 break;
361 403 case 15:
362 404 /* lgamma(-integer) or lgamma(0) */
363 405 exc.type = SING;
364 406 exc.name = "lgamma";
365 407 ieee_retval = setexception(0, 1.0);
408 +
366 409 if (lib_version == c_issue_4)
367 410 exc.retval = HUGE;
368 411 else
369 412 exc.retval = HUGE_VAL;
413 +
370 414 if (lib_version == strict_ansi) {
371 415 errno = EDOM;
372 416 } else if (!matherr(&exc)) {
373 - if (lib_version == c_issue_4) {
417 + if (lib_version == c_issue_4)
374 418 (void) write(2, "lgamma: SING error\n", 19);
375 - }
419 +
376 420 errno = EDOM;
377 421 }
422 +
378 423 break;
379 424 case 16:
380 425 /* log(0) */
381 426 exc.type = SING;
382 427 exc.name = "log";
383 428 ieee_retval = setexception(0, -1.0);
429 +
384 430 if (lib_version == c_issue_4)
385 431 exc.retval = -HUGE;
386 432 else
387 433 exc.retval = -HUGE_VAL;
434 +
388 435 if (lib_version == strict_ansi) {
389 436 errno = ERANGE;
390 437 } else if (!matherr(&exc)) {
391 438 if (lib_version == c_issue_4) {
392 439 (void) write(2, "log: SING error\n", 16);
393 440 errno = EDOM;
394 441 } else {
395 442 errno = ERANGE;
396 443 }
397 444 }
445 +
398 446 break;
399 447 case 17:
400 448 /* log(x<0) */
401 449 exc.type = DOMAIN;
402 450 exc.name = "log";
403 451 ieee_retval = setexception(3, 1.0);
452 +
404 453 if (lib_version == c_issue_4)
405 454 exc.retval = -HUGE;
406 455 else
407 456 exc.retval = -HUGE_VAL;
457 +
408 458 if (lib_version == strict_ansi) {
409 459 errno = EDOM;
410 460 } else if (!matherr(&exc)) {
411 - if (lib_version == c_issue_4) {
461 + if (lib_version == c_issue_4)
412 462 (void) write(2, "log: DOMAIN error\n", 18);
413 - }
463 +
414 464 errno = EDOM;
415 465 }
466 +
416 467 break;
417 468 case 18:
418 469 /* log10(0) */
419 470 exc.type = SING;
420 471 exc.name = "log10";
421 472 ieee_retval = setexception(0, -1.0);
473 +
422 474 if (lib_version == c_issue_4)
423 475 exc.retval = -HUGE;
424 476 else
425 477 exc.retval = -HUGE_VAL;
478 +
426 479 if (lib_version == strict_ansi) {
427 480 errno = ERANGE;
428 481 } else if (!matherr(&exc)) {
429 482 if (lib_version == c_issue_4) {
430 483 (void) write(2, "log10: SING error\n", 18);
431 484 errno = EDOM;
432 485 } else {
433 486 errno = ERANGE;
434 487 }
435 488 }
489 +
436 490 break;
437 491 case 19:
438 492 /* log10(x<0) */
439 493 exc.type = DOMAIN;
440 494 exc.name = "log10";
441 495 ieee_retval = setexception(3, 1.0);
496 +
442 497 if (lib_version == c_issue_4)
443 498 exc.retval = -HUGE;
444 499 else
445 500 exc.retval = -HUGE_VAL;
501 +
446 502 if (lib_version == strict_ansi) {
447 503 errno = EDOM;
448 504 } else if (!matherr(&exc)) {
449 - if (lib_version == c_issue_4) {
505 + if (lib_version == c_issue_4)
450 506 (void) write(2, "log10: DOMAIN error\n", 20);
451 - }
507 +
452 508 errno = EDOM;
453 509 }
510 +
454 511 break;
455 512 case 20:
456 - /* pow(0.0,0.0) */
457 - /* error only if lib_version == c_issue_4 */
513 +
514 + /*
515 + * pow(0.0,0.0)
516 + * error only if lib_version == c_issue_4
517 + */
458 518 exc.type = DOMAIN;
459 519 exc.name = "pow";
460 520 exc.retval = 0.0;
461 521 ieee_retval = 1.0;
522 +
462 523 if (lib_version != c_issue_4) {
463 524 exc.retval = 1.0;
464 525 } else if (!matherr(&exc)) {
465 526 (void) write(2, "pow(0,0): DOMAIN error\n", 23);
466 527 errno = EDOM;
467 528 }
529 +
468 530 break;
469 531 case 21:
470 532 /* pow(x,y) overflow */
471 533 exc.type = OVERFLOW;
472 534 exc.name = "pow";
473 - exc.retval = (lib_version == c_issue_4)? HUGE : HUGE_VAL;
535 + exc.retval = (lib_version == c_issue_4) ? HUGE : HUGE_VAL;
536 +
474 537 if (signbit(x)) {
475 538 t = rint(y);
539 +
476 540 if (t == y) {
477 541 w = rint(0.5 * y);
478 - if (t != w + w) { /* y is odd */
542 +
543 + if (t != w + w) /* y is odd */
479 544 exc.retval = -exc.retval;
480 - }
481 545 }
482 546 }
547 +
483 548 ieee_retval = setexception(2, exc.retval);
549 +
484 550 if (lib_version == strict_ansi)
485 551 errno = ERANGE;
486 552 else if (!matherr(&exc))
487 553 errno = ERANGE;
554 +
488 555 break;
489 556 case 22:
490 557 /* pow(x,y) underflow */
491 558 exc.type = UNDERFLOW;
492 559 exc.name = "pow";
493 560 exc.retval = 0.0;
561 +
494 562 if (signbit(x)) {
495 563 t = rint(y);
564 +
496 565 if (t == y) {
497 566 w = rint(0.5 * y);
567 +
498 568 if (t != w + w) /* y is odd */
499 569 exc.retval = -exc.retval;
500 570 }
501 571 }
572 +
502 573 ieee_retval = setexception(1, exc.retval);
574 +
503 575 if (lib_version == strict_ansi)
504 576 errno = ERANGE;
505 577 else if (!matherr(&exc))
506 578 errno = ERANGE;
579 +
507 580 break;
508 581 case 23:
509 582 /* (+-0)**neg */
510 583 exc.type = DOMAIN;
511 584 exc.name = "pow";
512 585 ieee_retval = setexception(0, 1.0);
513 586 {
514 587 int ahy, k, j, yisint, ly, hx;
515 - /* INDENT OFF */
588 +
589 + /* BEGIN CSTYLED */
516 590 /*
517 591 * determine if y is an odd int when x = -0
518 592 * yisint = 0 ... y is not an integer
519 593 * yisint = 1 ... y is an odd int
520 594 * yisint = 2 ... y is an even int
521 595 */
522 - /* INDENT ON */
523 - hx = __HI(x);
524 - ahy = __HI(y)&0x7fffffff;
525 - ly = __LO(y);
596 + /* END CSTYLED */
597 + hx = __HI(x);
598 + ahy = __HI(y) & 0x7fffffff;
599 + ly = __LO(y);
526 600
527 601 yisint = 0;
602 +
528 603 if (ahy >= 0x43400000) {
529 - yisint = 2; /* even integer y */
604 + yisint = 2; /* even integer y */
530 605 } else if (ahy >= 0x3ff00000) {
531 606 k = (ahy >> 20) - 0x3ff; /* exponent */
607 +
532 608 if (k > 20) {
533 609 j = ly >> (52 - k);
610 +
534 611 if ((j << (52 - k)) == ly)
535 612 yisint = 2 - (j & 1);
536 613 } else if (ly == 0) {
537 614 j = ahy >> (20 - k);
615 +
538 616 if ((j << (20 - k)) == ahy)
539 617 yisint = 2 - (j & 1);
540 618 }
541 619 }
620 +
542 621 if (hx < 0 && yisint == 1)
543 622 ieee_retval = -ieee_retval;
544 623 }
624 +
545 625 if (lib_version == c_issue_4)
546 626 exc.retval = 0.0;
547 627 else
548 628 exc.retval = -HUGE_VAL;
629 +
549 630 if (lib_version == strict_ansi) {
550 631 errno = EDOM;
551 632 } else if (!matherr(&exc)) {
552 633 if (lib_version == c_issue_4) {
553 634 (void) write(2, "pow(0,neg): DOMAIN error\n",
554 635 25);
555 636 }
637 +
556 638 errno = EDOM;
557 639 }
640 +
558 641 break;
559 642 case 24:
560 643 /* neg**non-integral */
561 644 exc.type = DOMAIN;
562 645 exc.name = "pow";
563 646 ieee_retval = setexception(3, 1.0);
647 +
564 648 if (lib_version == c_issue_4)
565 649 exc.retval = 0.0;
566 650 else
567 651 exc.retval = ieee_retval; /* X/Open allow NaN */
652 +
568 653 if (lib_version == strict_ansi) {
569 654 errno = EDOM;
570 655 } else if (!matherr(&exc)) {
571 656 if (lib_version == c_issue_4) {
572 657 (void) write(2,
573 658 "neg**non-integral: DOMAIN error\n", 32);
574 659 }
660 +
575 661 errno = EDOM;
576 662 }
663 +
577 664 break;
578 665 case 25:
579 666 /* sinh(finite) overflow */
580 667 exc.type = OVERFLOW;
581 668 exc.name = "sinh";
582 669 ieee_retval = copysign(Inf, x);
670 +
583 671 if (lib_version == c_issue_4)
584 672 exc.retval = x > 0.0 ? HUGE : -HUGE;
585 673 else
586 674 exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL;
675 +
587 676 if (lib_version == strict_ansi)
588 677 errno = ERANGE;
589 678 else if (!matherr(&exc))
590 679 errno = ERANGE;
680 +
591 681 break;
592 682 case 26:
593 683 /* sqrt(x<0) */
594 684 exc.type = DOMAIN;
595 685 exc.name = "sqrt";
596 686 ieee_retval = setexception(3, 1.0);
687 +
597 688 if (lib_version == c_issue_4)
598 689 exc.retval = 0.0;
599 690 else
600 691 exc.retval = ieee_retval; /* quiet NaN */
692 +
601 693 if (lib_version == strict_ansi) {
602 694 errno = EDOM;
603 695 } else if (!matherr(&exc)) {
604 - if (lib_version == c_issue_4) {
696 + if (lib_version == c_issue_4)
605 697 (void) write(2, "sqrt: DOMAIN error\n", 19);
606 - }
698 +
607 699 errno = EDOM;
608 700 }
701 +
609 702 break;
610 703 case 27:
611 704 /* fmod(x,0) */
612 705 exc.type = DOMAIN;
613 706 exc.name = "fmod";
707 +
614 708 if (fp_class(x) == fp_quiet)
615 709 ieee_retval = NaN;
616 710 else
617 711 ieee_retval = setexception(3, 1.0);
712 +
618 713 if (lib_version == c_issue_4)
619 714 exc.retval = x;
620 715 else
621 716 exc.retval = ieee_retval;
717 +
622 718 if (lib_version == strict_ansi) {
623 719 errno = EDOM;
624 720 } else if (!matherr(&exc)) {
625 - if (lib_version == c_issue_4) {
721 + if (lib_version == c_issue_4)
626 722 (void) write(2, "fmod: DOMAIN error\n", 20);
627 - }
723 +
628 724 errno = EDOM;
629 725 }
726 +
630 727 break;
631 728 case 28:
632 729 /* remainder(x,0) */
633 730 exc.type = DOMAIN;
634 731 exc.name = "remainder";
732 +
635 733 if (fp_class(x) == fp_quiet)
636 734 ieee_retval = NaN;
637 735 else
638 736 ieee_retval = setexception(3, 1.0);
737 +
639 738 exc.retval = NaN;
739 +
640 740 if (lib_version == strict_ansi) {
641 741 errno = EDOM;
642 742 } else if (!matherr(&exc)) {
643 - if (lib_version == c_issue_4) {
743 + if (lib_version == c_issue_4)
644 744 (void) write(2, "remainder: DOMAIN error\n",
645 745 24);
646 - }
746 +
647 747 errno = EDOM;
648 748 }
749 +
649 750 break;
650 751 case 29:
651 752 /* acosh(x<1) */
652 753 exc.type = DOMAIN;
653 754 exc.name = "acosh";
654 755 ieee_retval = setexception(3, 1.0);
655 756 exc.retval = NaN;
757 +
656 758 if (lib_version == strict_ansi) {
657 759 errno = EDOM;
658 760 } else if (!matherr(&exc)) {
659 - if (lib_version == c_issue_4) {
761 + if (lib_version == c_issue_4)
660 762 (void) write(2, "acosh: DOMAIN error\n", 20);
661 - }
763 +
662 764 errno = EDOM;
663 765 }
766 +
664 767 break;
665 768 case 30:
666 769 /* atanh(|x|>1) */
667 770 exc.type = DOMAIN;
668 771 exc.name = "atanh";
669 772 ieee_retval = setexception(3, 1.0);
670 773 exc.retval = NaN;
774 +
671 775 if (lib_version == strict_ansi) {
672 776 errno = EDOM;
673 777 } else if (!matherr(&exc)) {
674 - if (lib_version == c_issue_4) {
778 + if (lib_version == c_issue_4)
675 779 (void) write(2, "atanh: DOMAIN error\n", 20);
676 - }
780 +
677 781 errno = EDOM;
678 782 }
783 +
679 784 break;
680 785 case 31:
681 786 /* atanh(|x|=1) */
682 787 exc.type = SING;
683 788 exc.name = "atanh";
684 789 ieee_retval = setexception(0, x);
685 790 exc.retval = ieee_retval;
791 +
686 792 if (lib_version == strict_ansi) {
687 793 errno = ERANGE;
688 794 } else if (!matherr(&exc)) {
689 795 if (lib_version == c_issue_4) {
690 796 (void) write(2, "atanh: SING error\n", 18);
691 797 errno = EDOM;
692 798 } else {
693 799 errno = ERANGE;
694 800 }
695 801 }
802 +
696 803 break;
697 804 case 32:
698 805 /* scalb overflow; SVID also returns +-HUGE_VAL */
699 806 exc.type = OVERFLOW;
700 807 exc.name = "scalb";
701 808 ieee_retval = setexception(2, x);
702 809 exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL;
810 +
703 811 if (lib_version == strict_ansi)
704 812 errno = ERANGE;
705 813 else if (!matherr(&exc))
706 814 errno = ERANGE;
815 +
707 816 break;
708 817 case 33:
709 818 /* scalb underflow */
710 819 exc.type = UNDERFLOW;
711 820 exc.name = "scalb";
712 821 ieee_retval = setexception(1, x);
713 822 exc.retval = ieee_retval; /* +-0.0 */
823 +
714 824 if (lib_version == strict_ansi)
715 825 errno = ERANGE;
716 826 else if (!matherr(&exc))
717 827 errno = ERANGE;
828 +
718 829 break;
719 830 case 34:
720 831 /* j0(|x|>X_TLOSS) */
721 832 exc.type = TLOSS;
722 833 exc.name = "j0";
723 834 exc.retval = 0.0;
724 835 ieee_retval = y;
836 +
725 837 if (lib_version == strict_ansi) {
726 838 errno = ERANGE;
727 839 } else if (!matherr(&exc)) {
728 840 if (lib_version == c_issue_4) {
729 841 (void) write(2, exc.name, 2);
730 842 (void) write(2, ": TLOSS error\n", 14);
731 843 }
844 +
732 845 errno = ERANGE;
733 846 }
847 +
734 848 break;
735 849 case 35:
736 850 /* y0(x>X_TLOSS) */
737 851 exc.type = TLOSS;
738 852 exc.name = "y0";
739 853 exc.retval = 0.0;
740 854 ieee_retval = y;
855 +
741 856 if (lib_version == strict_ansi) {
742 857 errno = ERANGE;
743 858 } else if (!matherr(&exc)) {
744 859 if (lib_version == c_issue_4) {
745 860 (void) write(2, exc.name, 2);
746 861 (void) write(2, ": TLOSS error\n", 14);
747 862 }
863 +
748 864 errno = ERANGE;
749 865 }
866 +
750 867 break;
751 868 case 36:
752 869 /* j1(|x|>X_TLOSS) */
753 870 exc.type = TLOSS;
754 871 exc.name = "j1";
755 872 exc.retval = 0.0;
756 873 ieee_retval = y;
874 +
757 875 if (lib_version == strict_ansi) {
758 876 errno = ERANGE;
759 877 } else if (!matherr(&exc)) {
760 878 if (lib_version == c_issue_4) {
761 879 (void) write(2, exc.name, 2);
762 880 (void) write(2, ": TLOSS error\n", 14);
763 881 }
882 +
764 883 errno = ERANGE;
765 884 }
885 +
766 886 break;
767 887 case 37:
768 888 /* y1(x>X_TLOSS) */
769 889 exc.type = TLOSS;
770 890 exc.name = "y1";
771 891 exc.retval = 0.0;
772 892 ieee_retval = y;
893 +
773 894 if (lib_version == strict_ansi) {
774 895 errno = ERANGE;
775 896 } else if (!matherr(&exc)) {
776 897 if (lib_version == c_issue_4) {
777 898 (void) write(2, exc.name, 2);
778 899 (void) write(2, ": TLOSS error\n", 14);
779 900 }
901 +
780 902 errno = ERANGE;
781 903 }
904 +
782 905 break;
783 906 case 38:
784 - /* jn(|x|>X_TLOSS) */
785 - /* incorrect ieee value: ieee should never be here */
907 +
908 + /*
909 + * jn(|x|>X_TLOSS)
910 + * incorrect ieee value: ieee should never be here
911 + */
786 912 exc.type = TLOSS;
787 913 exc.name = "jn";
788 914 exc.retval = 0.0;
789 915 ieee_retval = 0.0; /* shall not be used */
916 +
790 917 if (lib_version == strict_ansi) {
791 918 errno = ERANGE;
792 919 } else if (!matherr(&exc)) {
793 920 if (lib_version == c_issue_4) {
794 921 (void) write(2, exc.name, 2);
795 922 (void) write(2, ": TLOSS error\n", 14);
796 923 }
924 +
797 925 errno = ERANGE;
798 926 }
927 +
799 928 break;
800 929 case 39:
801 - /* yn(x>X_TLOSS) */
802 - /* incorrect ieee value: ieee should never be here */
930 +
931 + /*
932 + * yn(x>X_TLOSS)
933 + * incorrect ieee value: ieee should never be here
934 + */
803 935 exc.type = TLOSS;
804 936 exc.name = "yn";
805 937 exc.retval = 0.0;
806 938 ieee_retval = 0.0; /* shall not be used */
939 +
807 940 if (lib_version == strict_ansi) {
808 941 errno = ERANGE;
809 942 } else if (!matherr(&exc)) {
810 943 if (lib_version == c_issue_4) {
811 944 (void) write(2, exc.name, 2);
812 945 (void) write(2, ": TLOSS error\n", 14);
813 946 }
947 +
814 948 errno = ERANGE;
815 949 }
950 +
816 951 break;
817 952 case 40:
818 953 /* gamma(finite) overflow */
819 954 exc.type = OVERFLOW;
820 955 exc.name = "gamma";
821 956 ieee_retval = setexception(2, 1.0);
957 +
822 958 if (lib_version == c_issue_4)
823 959 exc.retval = HUGE;
824 960 else
825 961 exc.retval = HUGE_VAL;
962 +
826 963 if (lib_version == strict_ansi)
827 964 errno = ERANGE;
828 965 else if (!matherr(&exc))
829 966 errno = ERANGE;
967 +
830 968 break;
831 969 case 41:
832 970 /* gamma(-integer) or gamma(0) */
833 971 exc.type = SING;
834 972 exc.name = "gamma";
835 973 ieee_retval = setexception(0, 1.0);
974 +
836 975 if (lib_version == c_issue_4)
837 976 exc.retval = HUGE;
838 977 else
839 978 exc.retval = HUGE_VAL;
979 +
840 980 if (lib_version == strict_ansi) {
841 981 errno = EDOM;
842 982 } else if (!matherr(&exc)) {
843 - if (lib_version == c_issue_4) {
983 + if (lib_version == c_issue_4)
844 984 (void) write(2, "gamma: SING error\n", 18);
845 - }
985 +
846 986 errno = EDOM;
847 987 }
988 +
848 989 break;
849 990 case 42:
850 - /* pow(NaN,0.0) */
851 - /* error if lib_version == c_issue_4 or ansi_1 */
991 +
992 + /*
993 + * pow(NaN,0.0)
994 + * error if lib_version == c_issue_4 or ansi_1
995 + */
852 996 exc.type = DOMAIN;
853 997 exc.name = "pow";
854 998 exc.retval = x;
855 999 ieee_retval = 1.0;
1000 +
856 1001 if (lib_version == strict_ansi) {
857 1002 exc.retval = 1.0;
858 1003 } else if (!matherr(&exc)) {
859 - if ((lib_version == c_issue_4) || (lib_version == ansi_1))
1004 + if ((lib_version == c_issue_4) || (lib_version ==
1005 + ansi_1))
860 1006 errno = EDOM;
861 1007 }
1008 +
862 1009 break;
863 1010 case 43:
864 1011 /* log1p(-1) */
865 1012 exc.type = SING;
866 1013 exc.name = "log1p";
867 1014 ieee_retval = setexception(0, -1.0);
1015 +
868 1016 if (lib_version == c_issue_4)
869 1017 exc.retval = -HUGE;
870 1018 else
871 1019 exc.retval = -HUGE_VAL;
1020 +
872 1021 if (lib_version == strict_ansi) {
873 1022 errno = ERANGE;
874 1023 } else if (!matherr(&exc)) {
875 1024 if (lib_version == c_issue_4) {
876 1025 (void) write(2, "log1p: SING error\n", 18);
877 1026 errno = EDOM;
878 1027 } else {
879 1028 errno = ERANGE;
880 1029 }
881 1030 }
1031 +
882 1032 break;
883 1033 case 44:
884 1034 /* log1p(x<-1) */
885 1035 exc.type = DOMAIN;
886 1036 exc.name = "log1p";
887 1037 ieee_retval = setexception(3, 1.0);
888 1038 exc.retval = ieee_retval;
1039 +
889 1040 if (lib_version == strict_ansi) {
890 1041 errno = EDOM;
891 1042 } else if (!matherr(&exc)) {
892 - if (lib_version == c_issue_4) {
1043 + if (lib_version == c_issue_4)
893 1044 (void) write(2, "log1p: DOMAIN error\n", 20);
894 - }
1045 +
895 1046 errno = EDOM;
896 1047 }
1048 +
897 1049 break;
898 1050 case 45:
899 1051 /* logb(0) */
900 1052 exc.type = DOMAIN;
901 1053 exc.name = "logb";
902 1054 ieee_retval = setexception(0, -1.0);
903 1055 exc.retval = -HUGE_VAL;
1056 +
904 1057 if (lib_version == strict_ansi)
905 1058 errno = EDOM;
906 1059 else if (!matherr(&exc))
907 1060 errno = EDOM;
1061 +
908 1062 break;
909 1063 case 46:
910 1064 /* nextafter overflow */
911 1065 exc.type = OVERFLOW;
912 1066 exc.name = "nextafter";
1067 +
913 1068 /*
914 1069 * The value as returned by setexception is +/-DBL_MAX in
915 1070 * round-to-{zero,-/+Inf} mode respectively, which is not
916 1071 * usable.
917 1072 */
918 1073 (void) setexception(2, x);
919 1074 ieee_retval = x > 0 ? Inf : -Inf;
920 1075 exc.retval = x > 0 ? HUGE_VAL : -HUGE_VAL;
1076 +
921 1077 if (lib_version == strict_ansi)
922 1078 errno = ERANGE;
923 1079 else if (!matherr(&exc))
924 1080 errno = ERANGE;
1081 +
925 1082 break;
926 1083 case 47:
927 1084 /* scalb(x,inf) */
928 1085 iy = ((int *)&y)[HIWORD];
1086 +
929 1087 if (lib_version == c_issue_4)
930 1088 /* SVID3: ERANGE in all cases */
931 1089 errno = ERANGE;
932 1090 else if ((x == 0.0 && iy > 0) || (!finite(x) && iy < 0))
933 1091 /* EDOM for scalb(0,+inf) or scalb(inf,-inf) */
934 1092 errno = EDOM;
935 - exc.retval = ieee_retval = ((iy < 0)? x / -y : x * y);
1093 +
1094 + exc.retval = ieee_retval = ((iy < 0) ? x / -y : x * y);
936 1095 break;
937 1096 }
1097 +
938 1098 switch (lib_version) {
939 1099 case c_issue_4:
940 1100 case ansi_1:
941 1101 case strict_ansi:
942 1102 return (exc.retval);
943 - /* NOTREACHED */
1103 + /* NOTREACHED */
944 1104 default:
945 1105 return (ieee_retval);
946 1106 }
1107 +
947 1108 /* NOTREACHED */
948 1109 }
949 1110
950 1111 static double
951 -setexception(int n, double x) {
1112 +setexception(int n, double x)
1113 +{
952 1114 /*
953 1115 * n =
954 1116 * 0 division by zero
955 1117 * 1 underflow
956 1118 * 2 overflow
957 1119 * 3 invalid
958 1120 */
959 1121 volatile double one = 1.0, zero = 0.0, retv;
960 1122
961 1123 switch (n) {
962 - case 0: /* division by zero */
1124 + case 0: /* division by zero */
963 1125 retv = copysign(one / zero, x);
964 1126 break;
965 - case 1: /* underflow */
1127 + case 1: /* underflow */
966 1128 retv = DBL_MIN * copysign(DBL_MIN, x);
967 1129 break;
968 - case 2: /* overflow */
1130 + case 2: /* overflow */
969 1131 retv = DBL_MAX * copysign(DBL_MAX, x);
970 1132 break;
971 - case 3: /* invalid */
1133 + case 3: /* invalid */
972 1134 retv = zero * Inf; /* for Cheetah */
973 1135 break;
974 1136 }
1137 +
975 1138 return (retv);
976 1139 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX