OSDN Git Service

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