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