Annotation of src/lib/libm/src/k_standard.c, Revision 1.10
1.1 jtc 1: /* @(#)k_standard.c 5.1 93/09/24 */
2: /*
3: * ====================================================
4: * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5: *
6: * Developed at SunPro, a Sun Microsystems, Inc. business.
7: * Permission to use, copy, modify, and distribute this
1.8 simonb 8: * software is freely granted, provided that this notice
1.1 jtc 9: * is preserved.
10: * ====================================================
11: */
1.3 jtc 12:
1.7 lukem 13: #include <sys/cdefs.h>
1.5 jtc 14: #if defined(LIBM_SCCS) && !defined(lint)
1.10 ! aymeric 15: __RCSID("$NetBSD: k_standard.c,v 1.9 2001/05/22 08:31:27 aymeric Exp $");
1.3 jtc 16: #endif
1.1 jtc 17:
1.4 jtc 18: #include "math.h"
19: #include "math_private.h"
1.1 jtc 20: #include <errno.h>
21:
22: #ifndef _USE_WRITE
23: #include <stdio.h> /* fputs(), stderr */
24: #define WRITE2(u,v) fputs(u, stderr)
25: #else /* !defined(_USE_WRITE) */
26: #include <unistd.h> /* write */
27: #define WRITE2(u,v) write(2, u, v)
28: #undef fflush
29: #endif /* !defined(_USE_WRITE) */
30:
1.4 jtc 31: #ifdef __STDC__
32: static const double zero = 0.0; /* used as const */
33: #else
1.1 jtc 34: static double zero = 0.0; /* used as const */
1.4 jtc 35: #endif
1.1 jtc 36:
1.8 simonb 37: /*
1.1 jtc 38: * Standard conformance (non-IEEE) on exception cases.
39: * Mapping:
40: * 1 -- acos(|x|>1)
41: * 2 -- asin(|x|>1)
42: * 3 -- atan2(+-0,+-0)
43: * 4 -- hypot overflow
44: * 5 -- cosh overflow
45: * 6 -- exp overflow
46: * 7 -- exp underflow
47: * 8 -- y0(0)
48: * 9 -- y0(-ve)
49: * 10-- y1(0)
50: * 11-- y1(-ve)
51: * 12-- yn(0)
52: * 13-- yn(-ve)
53: * 14-- lgamma(finite) overflow
54: * 15-- lgamma(-integer)
55: * 16-- log(0)
56: * 17-- log(x<0)
57: * 18-- log10(0)
58: * 19-- log10(x<0)
59: * 20-- pow(0.0,0.0)
60: * 21-- pow(x,y) overflow
61: * 22-- pow(x,y) underflow
1.8 simonb 62: * 23-- pow(0,negative)
1.1 jtc 63: * 24-- pow(neg,non-integral)
64: * 25-- sinh(finite) overflow
65: * 26-- sqrt(negative)
66: * 27-- fmod(x,0)
67: * 28-- remainder(x,0)
68: * 29-- acosh(x<1)
69: * 30-- atanh(|x|>1)
70: * 31-- atanh(|x|=1)
71: * 32-- scalb overflow
72: * 33-- scalb underflow
73: * 34-- j0(|x|>X_TLOSS)
74: * 35-- y0(x>X_TLOSS)
75: * 36-- j1(|x|>X_TLOSS)
76: * 37-- y1(x>X_TLOSS)
77: * 38-- jn(|x|>X_TLOSS, n)
78: * 39-- yn(x>X_TLOSS, n)
79: * 40-- gamma(finite) overflow
80: * 41-- gamma(-integer)
81: * 42-- pow(NaN,0.0)
82: */
83:
84:
85: #ifdef __STDC__
1.8 simonb 86: double __kernel_standard(double x, double y, int type)
1.1 jtc 87: #else
1.8 simonb 88: double __kernel_standard(x,y,type)
1.1 jtc 89: double x,y; int type;
90: #endif
91: {
92: struct exception exc;
1.8 simonb 93: #ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
1.1 jtc 94: #define HUGE_VAL inf
1.4 jtc 95: double inf = 0.0;
1.1 jtc 96:
1.4 jtc 97: SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
1.1 jtc 98: #endif
99:
1.10 ! aymeric 100: #ifdef _USE_WRITE
1.1 jtc 101: (void) fflush(stdout);
102: #endif
103: exc.arg1 = x;
104: exc.arg2 = y;
105: switch(type) {
106: case 1:
1.4 jtc 107: case 101:
1.1 jtc 108: /* acos(|x|>1) */
109: exc.type = DOMAIN;
1.4 jtc 110: exc.name = type < 100 ? "acos" : "acosf";
1.1 jtc 111: exc.retval = zero;
112: if (_LIB_VERSION == _POSIX_)
113: errno = EDOM;
114: else if (!matherr(&exc)) {
115: if(_LIB_VERSION == _SVID_) {
116: (void) WRITE2("acos: DOMAIN error\n", 19);
117: }
118: errno = EDOM;
119: }
120: break;
121: case 2:
1.4 jtc 122: case 102:
1.1 jtc 123: /* asin(|x|>1) */
124: exc.type = DOMAIN;
1.4 jtc 125: exc.name = type < 100 ? "asin" : "asinf";
1.1 jtc 126: exc.retval = zero;
127: if(_LIB_VERSION == _POSIX_)
128: errno = EDOM;
129: else if (!matherr(&exc)) {
130: if(_LIB_VERSION == _SVID_) {
131: (void) WRITE2("asin: DOMAIN error\n", 19);
132: }
133: errno = EDOM;
134: }
135: break;
136: case 3:
1.4 jtc 137: case 103:
1.1 jtc 138: /* atan2(+-0,+-0) */
139: exc.arg1 = y;
140: exc.arg2 = x;
141: exc.type = DOMAIN;
1.4 jtc 142: exc.name = type < 100 ? "atan2" : "atan2f";
1.1 jtc 143: exc.retval = zero;
144: if(_LIB_VERSION == _POSIX_)
145: errno = EDOM;
146: else if (!matherr(&exc)) {
147: if(_LIB_VERSION == _SVID_) {
148: (void) WRITE2("atan2: DOMAIN error\n", 20);
149: }
150: errno = EDOM;
151: }
152: break;
153: case 4:
1.4 jtc 154: case 104:
1.1 jtc 155: /* hypot(finite,finite) overflow */
156: exc.type = OVERFLOW;
1.4 jtc 157: exc.name = type < 100 ? "hypot" : "hypotf";
1.1 jtc 158: if (_LIB_VERSION == _SVID_)
159: exc.retval = HUGE;
160: else
161: exc.retval = HUGE_VAL;
162: if (_LIB_VERSION == _POSIX_)
163: errno = ERANGE;
164: else if (!matherr(&exc)) {
165: errno = ERANGE;
166: }
167: break;
168: case 5:
1.4 jtc 169: case 105:
1.1 jtc 170: /* cosh(finite) overflow */
171: exc.type = OVERFLOW;
1.4 jtc 172: exc.name = type < 100 ? "cosh" : "coshf";
1.1 jtc 173: if (_LIB_VERSION == _SVID_)
174: exc.retval = HUGE;
175: else
176: exc.retval = HUGE_VAL;
177: if (_LIB_VERSION == _POSIX_)
178: errno = ERANGE;
179: else if (!matherr(&exc)) {
180: errno = ERANGE;
181: }
182: break;
183: case 6:
1.4 jtc 184: case 106:
1.1 jtc 185: /* exp(finite) overflow */
186: exc.type = OVERFLOW;
1.4 jtc 187: exc.name = type < 100 ? "exp" : "expf";
1.1 jtc 188: if (_LIB_VERSION == _SVID_)
189: exc.retval = HUGE;
190: else
191: exc.retval = HUGE_VAL;
192: if (_LIB_VERSION == _POSIX_)
193: errno = ERANGE;
194: else if (!matherr(&exc)) {
195: errno = ERANGE;
196: }
197: break;
198: case 7:
1.4 jtc 199: case 107:
1.1 jtc 200: /* exp(finite) underflow */
201: exc.type = UNDERFLOW;
1.4 jtc 202: exc.name = type < 100 ? "exp" : "expf";
1.1 jtc 203: exc.retval = zero;
204: if (_LIB_VERSION == _POSIX_)
205: errno = ERANGE;
206: else if (!matherr(&exc)) {
207: errno = ERANGE;
208: }
209: break;
210: case 8:
1.4 jtc 211: case 108:
1.1 jtc 212: /* y0(0) = -inf */
213: exc.type = DOMAIN; /* should be SING for IEEE */
1.4 jtc 214: exc.name = type < 100 ? "y0" : "y0f";
1.1 jtc 215: if (_LIB_VERSION == _SVID_)
216: exc.retval = -HUGE;
217: else
218: exc.retval = -HUGE_VAL;
219: if (_LIB_VERSION == _POSIX_)
220: errno = EDOM;
221: else if (!matherr(&exc)) {
222: if (_LIB_VERSION == _SVID_) {
223: (void) WRITE2("y0: DOMAIN error\n", 17);
224: }
225: errno = EDOM;
226: }
227: break;
228: case 9:
1.4 jtc 229: case 109:
1.1 jtc 230: /* y0(x<0) = NaN */
231: exc.type = DOMAIN;
1.4 jtc 232: exc.name = type < 100 ? "y0" : "y0f";
1.1 jtc 233: if (_LIB_VERSION == _SVID_)
234: exc.retval = -HUGE;
235: else
236: exc.retval = -HUGE_VAL;
237: if (_LIB_VERSION == _POSIX_)
238: errno = EDOM;
239: else if (!matherr(&exc)) {
240: if (_LIB_VERSION == _SVID_) {
241: (void) WRITE2("y0: DOMAIN error\n", 17);
242: }
243: errno = EDOM;
244: }
245: break;
246: case 10:
1.4 jtc 247: case 110:
1.1 jtc 248: /* y1(0) = -inf */
249: exc.type = DOMAIN; /* should be SING for IEEE */
1.4 jtc 250: exc.name = type < 100 ? "y1" : "y1f";
1.1 jtc 251: if (_LIB_VERSION == _SVID_)
252: exc.retval = -HUGE;
253: else
254: exc.retval = -HUGE_VAL;
255: if (_LIB_VERSION == _POSIX_)
256: errno = EDOM;
257: else if (!matherr(&exc)) {
258: if (_LIB_VERSION == _SVID_) {
259: (void) WRITE2("y1: DOMAIN error\n", 17);
260: }
261: errno = EDOM;
262: }
263: break;
264: case 11:
1.4 jtc 265: case 111:
1.1 jtc 266: /* y1(x<0) = NaN */
267: exc.type = DOMAIN;
1.4 jtc 268: exc.name = type < 100 ? "y1" : "y1f";
1.1 jtc 269: if (_LIB_VERSION == _SVID_)
270: exc.retval = -HUGE;
271: else
272: exc.retval = -HUGE_VAL;
273: if (_LIB_VERSION == _POSIX_)
274: errno = EDOM;
275: else if (!matherr(&exc)) {
276: if (_LIB_VERSION == _SVID_) {
277: (void) WRITE2("y1: DOMAIN error\n", 17);
278: }
279: errno = EDOM;
280: }
281: break;
282: case 12:
1.4 jtc 283: case 112:
1.1 jtc 284: /* yn(n,0) = -inf */
285: exc.type = DOMAIN; /* should be SING for IEEE */
1.4 jtc 286: exc.name = type < 100 ? "yn" : "ynf";
1.1 jtc 287: if (_LIB_VERSION == _SVID_)
288: exc.retval = -HUGE;
289: else
290: exc.retval = -HUGE_VAL;
291: if (_LIB_VERSION == _POSIX_)
292: errno = EDOM;
293: else if (!matherr(&exc)) {
294: if (_LIB_VERSION == _SVID_) {
295: (void) WRITE2("yn: DOMAIN error\n", 17);
296: }
297: errno = EDOM;
298: }
299: break;
300: case 13:
1.4 jtc 301: case 113:
1.1 jtc 302: /* yn(x<0) = NaN */
303: exc.type = DOMAIN;
1.4 jtc 304: exc.name = type < 100 ? "yn" : "ynf";
1.1 jtc 305: if (_LIB_VERSION == _SVID_)
306: exc.retval = -HUGE;
307: else
308: exc.retval = -HUGE_VAL;
309: if (_LIB_VERSION == _POSIX_)
310: errno = EDOM;
311: else if (!matherr(&exc)) {
312: if (_LIB_VERSION == _SVID_) {
313: (void) WRITE2("yn: DOMAIN error\n", 17);
314: }
315: errno = EDOM;
316: }
317: break;
318: case 14:
1.4 jtc 319: case 114:
1.1 jtc 320: /* lgamma(finite) overflow */
321: exc.type = OVERFLOW;
1.4 jtc 322: exc.name = type < 100 ? "lgamma" : "lgammaf";
1.1 jtc 323: if (_LIB_VERSION == _SVID_)
324: exc.retval = HUGE;
325: else
326: exc.retval = HUGE_VAL;
327: if (_LIB_VERSION == _POSIX_)
328: errno = ERANGE;
329: else if (!matherr(&exc)) {
330: errno = ERANGE;
331: }
332: break;
333: case 15:
1.4 jtc 334: case 115:
1.1 jtc 335: /* lgamma(-integer) or lgamma(0) */
336: exc.type = SING;
1.4 jtc 337: exc.name = type < 100 ? "lgamma" : "lgammaf";
1.1 jtc 338: if (_LIB_VERSION == _SVID_)
339: exc.retval = HUGE;
340: else
341: exc.retval = HUGE_VAL;
342: if (_LIB_VERSION == _POSIX_)
343: errno = EDOM;
344: else if (!matherr(&exc)) {
345: if (_LIB_VERSION == _SVID_) {
346: (void) WRITE2("lgamma: SING error\n", 19);
347: }
348: errno = EDOM;
349: }
350: break;
351: case 16:
1.4 jtc 352: case 116:
1.1 jtc 353: /* log(0) */
354: exc.type = SING;
1.4 jtc 355: exc.name = type < 100 ? "log" : "logf";
1.1 jtc 356: if (_LIB_VERSION == _SVID_)
357: exc.retval = -HUGE;
358: else
359: exc.retval = -HUGE_VAL;
360: if (_LIB_VERSION == _POSIX_)
361: errno = ERANGE;
362: else if (!matherr(&exc)) {
363: if (_LIB_VERSION == _SVID_) {
364: (void) WRITE2("log: SING error\n", 16);
365: }
366: errno = EDOM;
367: }
368: break;
369: case 17:
1.4 jtc 370: case 117:
1.1 jtc 371: /* log(x<0) */
372: exc.type = DOMAIN;
1.4 jtc 373: exc.name = type < 100 ? "log" : "logf";
1.1 jtc 374: if (_LIB_VERSION == _SVID_)
375: exc.retval = -HUGE;
376: else
377: exc.retval = -HUGE_VAL;
378: if (_LIB_VERSION == _POSIX_)
379: errno = EDOM;
380: else if (!matherr(&exc)) {
381: if (_LIB_VERSION == _SVID_) {
382: (void) WRITE2("log: DOMAIN error\n", 18);
383: }
384: errno = EDOM;
385: }
386: break;
387: case 18:
1.4 jtc 388: case 118:
1.1 jtc 389: /* log10(0) */
390: exc.type = SING;
1.4 jtc 391: exc.name = type < 100 ? "log10" : "log10f";
1.1 jtc 392: if (_LIB_VERSION == _SVID_)
393: exc.retval = -HUGE;
394: else
395: exc.retval = -HUGE_VAL;
396: if (_LIB_VERSION == _POSIX_)
397: errno = ERANGE;
398: else if (!matherr(&exc)) {
399: if (_LIB_VERSION == _SVID_) {
400: (void) WRITE2("log10: SING error\n", 18);
401: }
402: errno = EDOM;
403: }
404: break;
405: case 19:
1.4 jtc 406: case 119:
1.1 jtc 407: /* log10(x<0) */
408: exc.type = DOMAIN;
1.4 jtc 409: exc.name = type < 100 ? "log10" : "log10f";
1.1 jtc 410: if (_LIB_VERSION == _SVID_)
411: exc.retval = -HUGE;
412: else
413: exc.retval = -HUGE_VAL;
414: if (_LIB_VERSION == _POSIX_)
415: errno = EDOM;
416: else if (!matherr(&exc)) {
417: if (_LIB_VERSION == _SVID_) {
418: (void) WRITE2("log10: DOMAIN error\n", 20);
419: }
420: errno = EDOM;
421: }
422: break;
423: case 20:
1.4 jtc 424: case 120:
1.1 jtc 425: /* pow(0.0,0.0) */
426: /* error only if _LIB_VERSION == _SVID_ */
427: exc.type = DOMAIN;
1.4 jtc 428: exc.name = type < 100 ? "pow" : "powf";
1.1 jtc 429: exc.retval = zero;
430: if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
431: else if (!matherr(&exc)) {
432: (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
433: errno = EDOM;
434: }
435: break;
436: case 21:
1.4 jtc 437: case 121:
1.1 jtc 438: /* pow(x,y) overflow */
439: exc.type = OVERFLOW;
1.4 jtc 440: exc.name = type < 100 ? "pow" : "powf";
1.1 jtc 441: if (_LIB_VERSION == _SVID_) {
442: exc.retval = HUGE;
443: y *= 0.5;
444: if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
445: } else {
446: exc.retval = HUGE_VAL;
447: y *= 0.5;
448: if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
449: }
450: if (_LIB_VERSION == _POSIX_)
451: errno = ERANGE;
452: else if (!matherr(&exc)) {
453: errno = ERANGE;
454: }
455: break;
456: case 22:
1.4 jtc 457: case 122:
1.1 jtc 458: /* pow(x,y) underflow */
459: exc.type = UNDERFLOW;
1.4 jtc 460: exc.name = type < 100 ? "pow" : "powf";
1.1 jtc 461: exc.retval = zero;
462: if (_LIB_VERSION == _POSIX_)
463: errno = ERANGE;
464: else if (!matherr(&exc)) {
465: errno = ERANGE;
466: }
467: break;
468: case 23:
1.4 jtc 469: case 123:
1.1 jtc 470: /* 0**neg */
471: exc.type = DOMAIN;
1.4 jtc 472: exc.name = type < 100 ? "pow" : "powf";
1.8 simonb 473: if (_LIB_VERSION == _SVID_)
1.1 jtc 474: exc.retval = zero;
475: else
476: exc.retval = -HUGE_VAL;
477: if (_LIB_VERSION == _POSIX_)
478: errno = EDOM;
479: else if (!matherr(&exc)) {
480: if (_LIB_VERSION == _SVID_) {
481: (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
482: }
483: errno = EDOM;
484: }
485: break;
486: case 24:
1.4 jtc 487: case 124:
1.1 jtc 488: /* neg**non-integral */
489: exc.type = DOMAIN;
1.4 jtc 490: exc.name = type < 100 ? "pow" : "powf";
1.8 simonb 491: if (_LIB_VERSION == _SVID_)
1.1 jtc 492: exc.retval = zero;
1.8 simonb 493: else
1.1 jtc 494: exc.retval = zero/zero; /* X/Open allow NaN */
1.8 simonb 495: if (_LIB_VERSION == _POSIX_)
1.1 jtc 496: errno = EDOM;
497: else if (!matherr(&exc)) {
498: if (_LIB_VERSION == _SVID_) {
499: (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
500: }
501: errno = EDOM;
502: }
503: break;
504: case 25:
1.4 jtc 505: case 125:
1.1 jtc 506: /* sinh(finite) overflow */
507: exc.type = OVERFLOW;
1.4 jtc 508: exc.name = type < 100 ? "sinh" : "sinhf";
1.1 jtc 509: if (_LIB_VERSION == _SVID_)
510: exc.retval = ( (x>zero) ? HUGE : -HUGE);
511: else
512: exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
513: if (_LIB_VERSION == _POSIX_)
514: errno = ERANGE;
515: else if (!matherr(&exc)) {
516: errno = ERANGE;
517: }
518: break;
519: case 26:
1.4 jtc 520: case 126:
1.1 jtc 521: /* sqrt(x<0) */
522: exc.type = DOMAIN;
1.4 jtc 523: exc.name = type < 100 ? "sqrt" : "sqrtf";
1.1 jtc 524: if (_LIB_VERSION == _SVID_)
525: exc.retval = zero;
526: else
527: exc.retval = zero/zero;
528: if (_LIB_VERSION == _POSIX_)
529: errno = EDOM;
530: else if (!matherr(&exc)) {
531: if (_LIB_VERSION == _SVID_) {
532: (void) WRITE2("sqrt: DOMAIN error\n", 19);
533: }
534: errno = EDOM;
535: }
536: break;
537: case 27:
1.4 jtc 538: case 127:
1.1 jtc 539: /* fmod(x,0) */
540: exc.type = DOMAIN;
1.4 jtc 541: exc.name = type < 100 ? "fmod" : "fmodf";
1.1 jtc 542: if (_LIB_VERSION == _SVID_)
543: exc.retval = x;
544: else
545: exc.retval = zero/zero;
546: if (_LIB_VERSION == _POSIX_)
547: errno = EDOM;
548: else if (!matherr(&exc)) {
549: if (_LIB_VERSION == _SVID_) {
550: (void) WRITE2("fmod: DOMAIN error\n", 20);
551: }
552: errno = EDOM;
553: }
554: break;
555: case 28:
1.4 jtc 556: case 128:
1.1 jtc 557: /* remainder(x,0) */
558: exc.type = DOMAIN;
1.4 jtc 559: exc.name = type < 100 ? "remainder" : "remainderf";
1.1 jtc 560: exc.retval = zero/zero;
561: if (_LIB_VERSION == _POSIX_)
562: errno = EDOM;
563: else if (!matherr(&exc)) {
564: if (_LIB_VERSION == _SVID_) {
565: (void) WRITE2("remainder: DOMAIN error\n", 24);
566: }
567: errno = EDOM;
568: }
569: break;
570: case 29:
1.4 jtc 571: case 129:
1.1 jtc 572: /* acosh(x<1) */
573: exc.type = DOMAIN;
1.4 jtc 574: exc.name = type < 100 ? "acosh" : "acoshf";
1.1 jtc 575: exc.retval = zero/zero;
576: if (_LIB_VERSION == _POSIX_)
577: errno = EDOM;
578: else if (!matherr(&exc)) {
579: if (_LIB_VERSION == _SVID_) {
580: (void) WRITE2("acosh: DOMAIN error\n", 20);
581: }
582: errno = EDOM;
583: }
584: break;
585: case 30:
1.4 jtc 586: case 130:
1.1 jtc 587: /* atanh(|x|>1) */
588: exc.type = DOMAIN;
1.4 jtc 589: exc.name = type < 100 ? "atanh" : "atanhf";
1.1 jtc 590: exc.retval = zero/zero;
591: if (_LIB_VERSION == _POSIX_)
592: errno = EDOM;
593: else if (!matherr(&exc)) {
594: if (_LIB_VERSION == _SVID_) {
595: (void) WRITE2("atanh: DOMAIN error\n", 20);
596: }
597: errno = EDOM;
598: }
599: break;
600: case 31:
1.4 jtc 601: case 131:
1.1 jtc 602: /* atanh(|x|=1) */
603: exc.type = SING;
1.4 jtc 604: exc.name = type < 100 ? "atanh" : "atanhf";
1.1 jtc 605: exc.retval = x/zero; /* sign(x)*inf */
606: if (_LIB_VERSION == _POSIX_)
607: errno = EDOM;
608: else if (!matherr(&exc)) {
609: if (_LIB_VERSION == _SVID_) {
610: (void) WRITE2("atanh: SING error\n", 18);
611: }
612: errno = EDOM;
613: }
614: break;
615: case 32:
1.4 jtc 616: case 132:
1.1 jtc 617: /* scalb overflow; SVID also returns +-HUGE_VAL */
618: exc.type = OVERFLOW;
1.4 jtc 619: exc.name = type < 100 ? "scalb" : "scalbf";
1.1 jtc 620: exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
621: if (_LIB_VERSION == _POSIX_)
622: errno = ERANGE;
623: else if (!matherr(&exc)) {
624: errno = ERANGE;
625: }
626: break;
627: case 33:
1.4 jtc 628: case 133:
1.1 jtc 629: /* scalb underflow */
630: exc.type = UNDERFLOW;
1.4 jtc 631: exc.name = type < 100 ? "scalb" : "scalbf";
1.1 jtc 632: exc.retval = copysign(zero,x);
633: if (_LIB_VERSION == _POSIX_)
634: errno = ERANGE;
635: else if (!matherr(&exc)) {
636: errno = ERANGE;
637: }
638: break;
639: case 34:
1.4 jtc 640: case 134:
1.1 jtc 641: /* j0(|x|>X_TLOSS) */
642: exc.type = TLOSS;
1.4 jtc 643: exc.name = type < 100 ? "j0" : "j0f";
1.1 jtc 644: exc.retval = zero;
645: if (_LIB_VERSION == _POSIX_)
646: errno = ERANGE;
647: else if (!matherr(&exc)) {
648: if (_LIB_VERSION == _SVID_) {
649: (void) WRITE2(exc.name, 2);
650: (void) WRITE2(": TLOSS error\n", 14);
651: }
652: errno = ERANGE;
1.8 simonb 653: }
1.1 jtc 654: break;
655: case 35:
1.4 jtc 656: case 135:
1.1 jtc 657: /* y0(x>X_TLOSS) */
658: exc.type = TLOSS;
1.4 jtc 659: exc.name = type < 100 ? "y0" : "y0f";
1.1 jtc 660: exc.retval = zero;
661: if (_LIB_VERSION == _POSIX_)
662: errno = ERANGE;
663: else if (!matherr(&exc)) {
664: if (_LIB_VERSION == _SVID_) {
665: (void) WRITE2(exc.name, 2);
666: (void) WRITE2(": TLOSS error\n", 14);
667: }
668: errno = ERANGE;
1.8 simonb 669: }
1.1 jtc 670: break;
671: case 36:
1.4 jtc 672: case 136:
1.1 jtc 673: /* j1(|x|>X_TLOSS) */
674: exc.type = TLOSS;
1.4 jtc 675: exc.name = type < 100 ? "j1" : "j1f";
1.1 jtc 676: exc.retval = zero;
677: if (_LIB_VERSION == _POSIX_)
678: errno = ERANGE;
679: else if (!matherr(&exc)) {
680: if (_LIB_VERSION == _SVID_) {
681: (void) WRITE2(exc.name, 2);
682: (void) WRITE2(": TLOSS error\n", 14);
683: }
684: errno = ERANGE;
1.8 simonb 685: }
1.1 jtc 686: break;
687: case 37:
1.4 jtc 688: case 137:
1.1 jtc 689: /* y1(x>X_TLOSS) */
690: exc.type = TLOSS;
1.4 jtc 691: exc.name = type < 100 ? "y1" : "y1f";
1.1 jtc 692: exc.retval = zero;
693: if (_LIB_VERSION == _POSIX_)
694: errno = ERANGE;
695: else if (!matherr(&exc)) {
696: if (_LIB_VERSION == _SVID_) {
697: (void) WRITE2(exc.name, 2);
698: (void) WRITE2(": TLOSS error\n", 14);
699: }
700: errno = ERANGE;
1.8 simonb 701: }
1.1 jtc 702: break;
703: case 38:
1.4 jtc 704: case 138:
1.1 jtc 705: /* jn(|x|>X_TLOSS) */
706: exc.type = TLOSS;
1.4 jtc 707: exc.name = type < 100 ? "jn" : "jnf";
1.1 jtc 708: exc.retval = zero;
709: if (_LIB_VERSION == _POSIX_)
710: errno = ERANGE;
711: else if (!matherr(&exc)) {
712: if (_LIB_VERSION == _SVID_) {
713: (void) WRITE2(exc.name, 2);
714: (void) WRITE2(": TLOSS error\n", 14);
715: }
716: errno = ERANGE;
1.8 simonb 717: }
1.1 jtc 718: break;
719: case 39:
1.4 jtc 720: case 139:
1.1 jtc 721: /* yn(x>X_TLOSS) */
722: exc.type = TLOSS;
1.4 jtc 723: exc.name = type < 100 ? "yn" : "ynf";
1.1 jtc 724: exc.retval = zero;
725: if (_LIB_VERSION == _POSIX_)
726: errno = ERANGE;
727: else if (!matherr(&exc)) {
728: if (_LIB_VERSION == _SVID_) {
729: (void) WRITE2(exc.name, 2);
730: (void) WRITE2(": TLOSS error\n", 14);
731: }
732: errno = ERANGE;
1.8 simonb 733: }
1.1 jtc 734: break;
735: case 40:
1.4 jtc 736: case 140:
1.1 jtc 737: /* gamma(finite) overflow */
738: exc.type = OVERFLOW;
1.4 jtc 739: exc.name = type < 100 ? "gamma" : "gammaf";
1.1 jtc 740: if (_LIB_VERSION == _SVID_)
741: exc.retval = HUGE;
742: else
743: exc.retval = HUGE_VAL;
744: if (_LIB_VERSION == _POSIX_)
745: errno = ERANGE;
746: else if (!matherr(&exc)) {
747: errno = ERANGE;
748: }
749: break;
750: case 41:
1.4 jtc 751: case 141:
1.1 jtc 752: /* gamma(-integer) or gamma(0) */
753: exc.type = SING;
1.4 jtc 754: exc.name = type < 100 ? "gamma" : "gammaf";
1.1 jtc 755: if (_LIB_VERSION == _SVID_)
756: exc.retval = HUGE;
757: else
758: exc.retval = HUGE_VAL;
759: if (_LIB_VERSION == _POSIX_)
760: errno = EDOM;
761: else if (!matherr(&exc)) {
762: if (_LIB_VERSION == _SVID_) {
763: (void) WRITE2("gamma: SING error\n", 18);
764: }
765: errno = EDOM;
766: }
767: break;
768: case 42:
1.4 jtc 769: case 142:
1.1 jtc 770: /* pow(NaN,0.0) */
771: /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
772: exc.type = DOMAIN;
1.4 jtc 773: exc.name = type < 100 ? "pow" : "powf";
1.1 jtc 774: exc.retval = x;
775: if (_LIB_VERSION == _IEEE_ ||
776: _LIB_VERSION == _POSIX_) exc.retval = 1.0;
777: else if (!matherr(&exc)) {
778: errno = EDOM;
779: }
780: break;
781: }
1.8 simonb 782: return exc.retval;
1.1 jtc 783: }
CVSweb <webmaster@jp.NetBSD.org>