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