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