Remove __STDC__ conditionals from libm.
[platform/upstream/glibc.git] / sysdeps / ieee754 / 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
13 #if defined(LIBM_SCCS) && !defined(lint)
14 static char rcsid[] = "$NetBSD: k_standard.c,v 1.6 1995/05/10 20:46:35 jtc Exp $";
15 #endif
16
17 #include "math.h"
18 #include "math_private.h"
19 #include <errno.h>
20
21 #include <assert.h>
22
23 #ifndef _USE_WRITE
24 #include <stdio.h>                      /* fputs(), stderr */
25 #define WRITE2(u,v)     fputs(u, stderr)
26 #else   /* !defined(_USE_WRITE) */
27 #include <unistd.h>                     /* write */
28 #define WRITE2(u,v)     write(2, u, v)
29 #undef fflush
30 #endif  /* !defined(_USE_WRITE) */
31
32 /* XXX gcc versions until now don't delay the 0.0/0.0 division until
33    runtime but produce NaN at copile time.  This is wrong since the
34    exceptions are not set correctly.  */
35 #if 0
36 static const double zero = 0.0; /* used as const */
37 #else
38 static double zero = 0.0;       /* used as const */
39 #endif
40
41 /*
42  * Standard conformance (non-IEEE) on exception cases.
43  * Mapping:
44  *      1 -- acos(|x|>1)
45  *      2 -- asin(|x|>1)
46  *      3 -- atan2(+-0,+-0)
47  *      4 -- hypot overflow
48  *      5 -- cosh overflow
49  *      6 -- exp overflow
50  *      7 -- exp underflow
51  *      8 -- y0(0)
52  *      9 -- y0(-ve)
53  *      10-- y1(0)
54  *      11-- y1(-ve)
55  *      12-- yn(0)
56  *      13-- yn(-ve)
57  *      14-- lgamma(finite) overflow
58  *      15-- lgamma(-integer)
59  *      16-- log(0)
60  *      17-- log(x<0)
61  *      18-- log10(0)
62  *      19-- log10(x<0)
63  *      20-- pow(0.0,0.0)
64  *      21-- pow(x,y) overflow
65  *      22-- pow(x,y) underflow
66  *      23-- pow(0,negative)
67  *      24-- pow(neg,non-integral)
68  *      25-- sinh(finite) overflow
69  *      26-- sqrt(negative)
70  *      27-- fmod(x,0)
71  *      28-- remainder(x,0)
72  *      29-- acosh(x<1)
73  *      30-- atanh(|x|>1)
74  *      31-- atanh(|x|=1)
75  *      32-- scalb overflow
76  *      33-- scalb underflow
77  *      34-- j0(|x|>X_TLOSS)
78  *      35-- y0(x>X_TLOSS)
79  *      36-- j1(|x|>X_TLOSS)
80  *      37-- y1(x>X_TLOSS)
81  *      38-- jn(|x|>X_TLOSS, n)
82  *      39-- yn(x>X_TLOSS, n)
83  *      40-- tgamma(finite) overflow
84  *      41-- tgamma(-integer)
85  *      42-- pow(NaN,0.0)
86  *      43-- +0**neg
87  *      44-- exp2 overflow
88  *      45-- exp2 underflow
89  *      46-- exp10 overflow
90  *      47-- exp10 underflow
91  *      48-- log2(0)
92  *      49-- log2(x<0)
93  *      50-- tgamma(+-0)
94  */
95
96
97 double
98 __kernel_standard(double x, double y, int type)
99 {
100         struct exception exc;
101 #ifndef HUGE_VAL        /* this is the only routine that uses HUGE_VAL */
102 #define HUGE_VAL inf
103         double inf = 0.0;
104
105         SET_HIGH_WORD(inf,0x7ff00000);  /* set inf to infinite */
106 #endif
107
108 #ifdef _USE_WRITE
109         (void) fflush(stdout);
110 #endif
111         exc.arg1 = x;
112         exc.arg2 = y;
113         switch(type) {
114             case 1:
115             case 101:
116             case 201:
117                 /* acos(|x|>1) */
118                 exc.type = DOMAIN;
119                 exc.name = type < 100 ? "acos" : (type < 200
120                                                   ? "acosf" : "acosl");;
121                 if (_LIB_VERSION == _SVID_)
122                   exc.retval = HUGE;
123                 else
124                   exc.retval = NAN;
125                 if (_LIB_VERSION == _POSIX_)
126                   __set_errno (EDOM);
127                 else if (!matherr(&exc)) {
128                   if(_LIB_VERSION == _SVID_) {
129                     (void) WRITE2("acos: DOMAIN error\n", 19);
130                   }
131                   __set_errno (EDOM);
132                 }
133                 break;
134             case 2:
135             case 102:
136             case 202:
137                 /* asin(|x|>1) */
138                 exc.type = DOMAIN;
139                 exc.name = type < 100 ? "asin" : (type < 200
140                                                   ? "asinf" : "asinl");
141                 if (_LIB_VERSION == _SVID_)
142                   exc.retval = HUGE;
143                 else
144                   exc.retval = NAN;
145                 if(_LIB_VERSION == _POSIX_)
146                   __set_errno (EDOM);
147                 else if (!matherr(&exc)) {
148                   if(_LIB_VERSION == _SVID_) {
149                         (void) WRITE2("asin: DOMAIN error\n", 19);
150                   }
151                   __set_errno (EDOM);
152                 }
153                 break;
154             case 3:
155             case 103:
156             case 203:
157                 /* atan2(+-0,+-0) */
158                 exc.arg1 = y;
159                 exc.arg2 = x;
160                 exc.type = DOMAIN;
161                 exc.name = type < 100 ? "atan2" : (type < 200
162                                                    ? "atan2f" : "atan2l");
163                 assert (_LIB_VERSION == _SVID_);
164                 exc.retval = HUGE;
165                 if(_LIB_VERSION == _POSIX_)
166                   __set_errno (EDOM);
167                 else if (!matherr(&exc)) {
168                   if(_LIB_VERSION == _SVID_) {
169                         (void) WRITE2("atan2: DOMAIN error\n", 20);
170                       }
171                   __set_errno (EDOM);
172                 }
173                 break;
174             case 4:
175             case 104:
176             case 204:
177                 /* hypot(finite,finite) overflow */
178                 exc.type = OVERFLOW;
179                 exc.name = type < 100 ? "hypot" : (type < 200
180                                                    ? "hypotf" : "hypotl");
181                 if (_LIB_VERSION == _SVID_)
182                   exc.retval = HUGE;
183                 else
184                   exc.retval = HUGE_VAL;
185                 if (_LIB_VERSION == _POSIX_)
186                   __set_errno (ERANGE);
187                 else if (!matherr(&exc)) {
188                         __set_errno (ERANGE);
189                 }
190                 break;
191             case 5:
192             case 105:
193             case 205:
194                 /* cosh(finite) overflow */
195                 exc.type = OVERFLOW;
196                 exc.name = type < 100 ? "cosh" : (type < 200
197                                                   ? "coshf" : "coshl");
198                 if (_LIB_VERSION == _SVID_)
199                   exc.retval = HUGE;
200                 else
201                   exc.retval = HUGE_VAL;
202                 if (_LIB_VERSION == _POSIX_)
203                   __set_errno (ERANGE);
204                 else if (!matherr(&exc)) {
205                         __set_errno (ERANGE);
206                 }
207                 break;
208             case 6:
209             case 106:
210             case 206:
211                 /* exp(finite) overflow */
212                 exc.type = OVERFLOW;
213                 exc.name = type < 100 ? "exp" : (type < 200
214                                                  ? "expf" : "expl");
215                 if (_LIB_VERSION == _SVID_)
216                   exc.retval = HUGE;
217                 else
218                   exc.retval = HUGE_VAL;
219                 if (_LIB_VERSION == _POSIX_)
220                   __set_errno (ERANGE);
221                 else if (!matherr(&exc)) {
222                         __set_errno (ERANGE);
223                 }
224                 break;
225             case 7:
226             case 107:
227             case 207:
228                 /* exp(finite) underflow */
229                 exc.type = UNDERFLOW;
230                 exc.name = type < 100 ? "exp" : (type < 200
231                                                  ? "expf" : "expl");
232                 exc.retval = zero;
233                 if (_LIB_VERSION == _POSIX_)
234                   __set_errno (ERANGE);
235                 else if (!matherr(&exc)) {
236                         __set_errno (ERANGE);
237                 }
238                 break;
239             case 8:
240             case 108:
241             case 208:
242                 /* y0(0) = -inf */
243                 exc.type = DOMAIN;      /* should be SING for IEEE */
244                 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
245                 if (_LIB_VERSION == _SVID_)
246                   exc.retval = -HUGE;
247                 else
248                   exc.retval = -HUGE_VAL;
249                 if (_LIB_VERSION == _POSIX_)
250                   __set_errno (EDOM);
251                 else if (!matherr(&exc)) {
252                   if (_LIB_VERSION == _SVID_) {
253                         (void) WRITE2("y0: DOMAIN error\n", 17);
254                       }
255                   __set_errno (EDOM);
256                 }
257                 break;
258             case 9:
259             case 109:
260             case 209:
261                 /* y0(x<0) = NaN */
262                 exc.type = DOMAIN;
263                 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
264                 if (_LIB_VERSION == _SVID_)
265                   exc.retval = -HUGE;
266                 else
267                   exc.retval = -HUGE_VAL;
268                 if (_LIB_VERSION == _POSIX_)
269                   __set_errno (EDOM);
270                 else if (!matherr(&exc)) {
271                   if (_LIB_VERSION == _SVID_) {
272                         (void) WRITE2("y0: DOMAIN error\n", 17);
273                       }
274                   __set_errno (EDOM);
275                 }
276                 break;
277             case 10:
278             case 110:
279             case 210:
280                 /* y1(0) = -inf */
281                 exc.type = DOMAIN;      /* should be SING for IEEE */
282                 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
283                 if (_LIB_VERSION == _SVID_)
284                   exc.retval = -HUGE;
285                 else
286                   exc.retval = -HUGE_VAL;
287                 if (_LIB_VERSION == _POSIX_)
288                   __set_errno (EDOM);
289                 else if (!matherr(&exc)) {
290                   if (_LIB_VERSION == _SVID_) {
291                         (void) WRITE2("y1: DOMAIN error\n", 17);
292                       }
293                   __set_errno (EDOM);
294                 }
295                 break;
296             case 11:
297             case 111:
298             case 211:
299                 /* y1(x<0) = NaN */
300                 exc.type = DOMAIN;
301                 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
302                 if (_LIB_VERSION == _SVID_)
303                   exc.retval = -HUGE;
304                 else
305                   exc.retval = -HUGE_VAL;
306                 if (_LIB_VERSION == _POSIX_)
307                   __set_errno (EDOM);
308                 else if (!matherr(&exc)) {
309                   if (_LIB_VERSION == _SVID_) {
310                         (void) WRITE2("y1: DOMAIN error\n", 17);
311                       }
312                   __set_errno (EDOM);
313                 }
314                 break;
315             case 12:
316             case 112:
317             case 212:
318                 /* yn(n,0) = -inf */
319                 exc.type = DOMAIN;      /* should be SING for IEEE */
320                 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
321                 if (_LIB_VERSION == _SVID_)
322                   exc.retval = -HUGE;
323                 else
324                   exc.retval = -HUGE_VAL;
325                 if (_LIB_VERSION == _POSIX_)
326                   __set_errno (EDOM);
327                 else if (!matherr(&exc)) {
328                   if (_LIB_VERSION == _SVID_) {
329                         (void) WRITE2("yn: DOMAIN error\n", 17);
330                       }
331                   __set_errno (EDOM);
332                 }
333                 break;
334             case 13:
335             case 113:
336             case 213:
337                 /* yn(x<0) = NaN */
338                 exc.type = DOMAIN;
339                 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
340                 if (_LIB_VERSION == _SVID_)
341                   exc.retval = -HUGE;
342                 else
343                   exc.retval = -HUGE_VAL;
344                 if (_LIB_VERSION == _POSIX_)
345                   __set_errno (EDOM);
346                 else if (!matherr(&exc)) {
347                   if (_LIB_VERSION == _SVID_) {
348                         (void) WRITE2("yn: DOMAIN error\n", 17);
349                       }
350                   __set_errno (EDOM);
351                 }
352                 break;
353             case 14:
354             case 114:
355             case 214:
356                 /* lgamma(finite) overflow */
357                 exc.type = OVERFLOW;
358                 exc.name = type < 100 ? "lgamma" : (type < 200
359                                                     ? "lgammaf" : "lgammal");
360                 if (_LIB_VERSION == _SVID_)
361                   exc.retval = HUGE;
362                 else
363                   exc.retval = HUGE_VAL;
364                 if (_LIB_VERSION == _POSIX_)
365                         __set_errno (ERANGE);
366                 else if (!matherr(&exc)) {
367                         __set_errno (ERANGE);
368                 }
369                 break;
370             case 15:
371             case 115:
372             case 215:
373                 /* lgamma(-integer) or lgamma(0) */
374                 exc.type = SING;
375                 exc.name = type < 100 ? "lgamma" : (type < 200
376                                                     ? "lgammaf" : "lgammal");
377                 if (_LIB_VERSION == _SVID_)
378                   exc.retval = HUGE;
379                 else
380                   exc.retval = HUGE_VAL;
381                 if (_LIB_VERSION == _POSIX_)
382                   __set_errno (ERANGE);
383                 else if (!matherr(&exc)) {
384                   if (_LIB_VERSION == _SVID_) {
385                         (void) WRITE2("lgamma: SING error\n", 19);
386                       }
387                   __set_errno (EDOM);
388                 }
389                 break;
390             case 16:
391             case 116:
392             case 216:
393                 /* log(0) */
394                 exc.type = SING;
395                 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
396                 if (_LIB_VERSION == _SVID_)
397                   exc.retval = -HUGE;
398                 else
399                   exc.retval = -HUGE_VAL;
400                 if (_LIB_VERSION == _POSIX_)
401                   __set_errno (ERANGE);
402                 else if (!matherr(&exc)) {
403                   if (_LIB_VERSION == _SVID_) {
404                         (void) WRITE2("log: SING error\n", 16);
405                       }
406                   __set_errno (EDOM);
407                 }
408                 break;
409             case 17:
410             case 117:
411             case 217:
412                 /* log(x<0) */
413                 exc.type = DOMAIN;
414                 exc.name = type < 100 ? "log" : (type < 200 ? "logf" : "logl");
415                 if (_LIB_VERSION == _SVID_)
416                   exc.retval = -HUGE;
417                 else
418                   exc.retval = NAN;
419                 if (_LIB_VERSION == _POSIX_)
420                   __set_errno (EDOM);
421                 else if (!matherr(&exc)) {
422                   if (_LIB_VERSION == _SVID_) {
423                         (void) WRITE2("log: DOMAIN error\n", 18);
424                       }
425                   __set_errno (EDOM);
426                 }
427                 break;
428             case 18:
429             case 118:
430             case 218:
431                 /* log10(0) */
432                 exc.type = SING;
433                 exc.name = type < 100 ? "log10" : (type < 200
434                                                    ? "log10f" : "log10l");
435                 if (_LIB_VERSION == _SVID_)
436                   exc.retval = -HUGE;
437                 else
438                   exc.retval = -HUGE_VAL;
439                 if (_LIB_VERSION == _POSIX_)
440                   __set_errno (ERANGE);
441                 else if (!matherr(&exc)) {
442                   if (_LIB_VERSION == _SVID_) {
443                         (void) WRITE2("log10: SING error\n", 18);
444                       }
445                   __set_errno (EDOM);
446                 }
447                 break;
448             case 19:
449             case 119:
450             case 219:
451                 /* log10(x<0) */
452                 exc.type = DOMAIN;
453                 exc.name = type < 100 ? "log10" : (type < 200
454                                                    ? "log10f" : "log10l");
455                 if (_LIB_VERSION == _SVID_)
456                   exc.retval = -HUGE;
457                 else
458                   exc.retval = NAN;
459                 if (_LIB_VERSION == _POSIX_)
460                   __set_errno (EDOM);
461                 else if (!matherr(&exc)) {
462                   if (_LIB_VERSION == _SVID_) {
463                         (void) WRITE2("log10: DOMAIN error\n", 20);
464                       }
465                   __set_errno (EDOM);
466                 }
467                 break;
468             case 20:
469             case 120:
470             case 220:
471                 /* pow(0.0,0.0) */
472                 /* error only if _LIB_VERSION == _SVID_ */
473                 exc.type = DOMAIN;
474                 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
475                 exc.retval = zero;
476                 if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
477                 else if (!matherr(&exc)) {
478                         (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
479                         __set_errno (EDOM);
480                 }
481                 break;
482             case 21:
483             case 121:
484             case 221:
485                 /* pow(x,y) overflow */
486                 exc.type = OVERFLOW;
487                 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
488                 if (_LIB_VERSION == _SVID_) {
489                   exc.retval = HUGE;
490                   y *= 0.5;
491                   if(x<zero&&__rint(y)!=y) exc.retval = -HUGE;
492                 } else {
493                   exc.retval = HUGE_VAL;
494                   y *= 0.5;
495                   if(x<zero&&__rint(y)!=y) exc.retval = -HUGE_VAL;
496                 }
497                 if (_LIB_VERSION == _POSIX_)
498                   __set_errno (ERANGE);
499                 else if (!matherr(&exc)) {
500                         __set_errno (ERANGE);
501                 }
502                 break;
503             case 22:
504             case 122:
505             case 222:
506                 /* pow(x,y) underflow */
507                 exc.type = UNDERFLOW;
508                 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
509                 exc.retval =  zero;
510                 if (_LIB_VERSION == _POSIX_)
511                   __set_errno (ERANGE);
512                 else if (!matherr(&exc)) {
513                         __set_errno (ERANGE);
514                 }
515                 break;
516             case 23:
517             case 123:
518             case 223:
519                 /* -0**neg */
520                 exc.type = DOMAIN;
521                 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
522                 if (_LIB_VERSION == _SVID_)
523                   exc.retval = zero;
524                 else
525                   exc.retval = -HUGE_VAL;
526                 if (_LIB_VERSION == _POSIX_)
527                   __set_errno (ERANGE);
528                 else if (!matherr(&exc)) {
529                   if (_LIB_VERSION == _SVID_) {
530                         (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
531                       }
532                   __set_errno (EDOM);
533                 }
534                 break;
535             case 43:
536             case 143:
537             case 243:
538                 /* +0**neg */
539                 exc.type = DOMAIN;
540                 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
541                 if (_LIB_VERSION == _SVID_)
542                   exc.retval = zero;
543                 else
544                   exc.retval = HUGE_VAL;
545                 if (_LIB_VERSION == _POSIX_)
546                   __set_errno (ERANGE);
547                 else if (!matherr(&exc)) {
548                   if (_LIB_VERSION == _SVID_) {
549                         (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
550                       }
551                   __set_errno (EDOM);
552                 }
553                 break;
554             case 24:
555             case 124:
556             case 224:
557                 /* neg**non-integral */
558                 exc.type = DOMAIN;
559                 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
560                 if (_LIB_VERSION == _SVID_)
561                     exc.retval = zero;
562                 else
563                     exc.retval = zero/zero;     /* X/Open allow NaN */
564                 if (_LIB_VERSION == _POSIX_)
565                    __set_errno (EDOM);
566                 else if (!matherr(&exc)) {
567                   if (_LIB_VERSION == _SVID_) {
568                         (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
569                       }
570                   __set_errno (EDOM);
571                 }
572                 break;
573             case 25:
574             case 125:
575             case 225:
576                 /* sinh(finite) overflow */
577                 exc.type = OVERFLOW;
578                 exc.name = type < 100 ? "sinh" : (type < 200
579                                                   ? "sinhf" : "sinhl");
580                 if (_LIB_VERSION == _SVID_)
581                   exc.retval = ( (x>zero) ? HUGE : -HUGE);
582                 else
583                   exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
584                 if (_LIB_VERSION == _POSIX_)
585                   __set_errno (ERANGE);
586                 else if (!matherr(&exc)) {
587                         __set_errno (ERANGE);
588                 }
589                 break;
590             case 26:
591             case 126:
592             case 226:
593                 /* sqrt(x<0) */
594                 exc.type = DOMAIN;
595                 exc.name = type < 100 ? "sqrt" : (type < 200
596                                                   ? "sqrtf" : "sqrtl");
597                 if (_LIB_VERSION == _SVID_)
598                   exc.retval = zero;
599                 else
600                   exc.retval = zero/zero;
601                 if (_LIB_VERSION == _POSIX_)
602                   __set_errno (EDOM);
603                 else if (!matherr(&exc)) {
604                   if (_LIB_VERSION == _SVID_) {
605                         (void) WRITE2("sqrt: DOMAIN error\n", 19);
606                       }
607                   __set_errno (EDOM);
608                 }
609                 break;
610             case 27:
611             case 127:
612             case 227:
613                 /* fmod(x,0) */
614                 exc.type = DOMAIN;
615                 exc.name = type < 100 ? "fmod" : (type < 200
616                                                   ? "fmodf" : "fmodl");
617                 if (_LIB_VERSION == _SVID_)
618                     exc.retval = x;
619                 else
620                     exc.retval = zero/zero;
621                 if (_LIB_VERSION == _POSIX_)
622                   __set_errno (EDOM);
623                 else if (!matherr(&exc)) {
624                   if (_LIB_VERSION == _SVID_) {
625                     (void) WRITE2("fmod:  DOMAIN error\n", 20);
626                   }
627                   __set_errno (EDOM);
628                 }
629                 break;
630             case 28:
631             case 128:
632             case 228:
633                 /* remainder(x,0) */
634                 exc.type = DOMAIN;
635                 exc.name = type < 100 ? "remainder" : (type < 200
636                                                        ? "remainderf"
637                                                        : "remainderl");
638                 exc.retval = zero/zero;
639                 if (_LIB_VERSION == _POSIX_)
640                   __set_errno (EDOM);
641                 else if (!matherr(&exc)) {
642                   if (_LIB_VERSION == _SVID_) {
643                     (void) WRITE2("remainder: DOMAIN error\n", 24);
644                   }
645                   __set_errno (EDOM);
646                 }
647                 break;
648             case 29:
649             case 129:
650             case 229:
651                 /* acosh(x<1) */
652                 exc.type = DOMAIN;
653                 exc.name = type < 100 ? "acosh" : (type < 200
654                                                    ? "acoshf" : "acoshl");
655                 exc.retval = zero/zero;
656                 if (_LIB_VERSION == _POSIX_)
657                   __set_errno (EDOM);
658                 else if (!matherr(&exc)) {
659                   if (_LIB_VERSION == _SVID_) {
660                     (void) WRITE2("acosh: DOMAIN error\n", 20);
661                   }
662                   __set_errno (EDOM);
663                 }
664                 break;
665             case 30:
666             case 130:
667             case 230:
668                 /* atanh(|x|>1) */
669                 exc.type = DOMAIN;
670                 exc.name = type < 100 ? "atanh" : (type < 200
671                                                    ? "atanhf" : "atanhl");
672                 exc.retval = zero/zero;
673                 if (_LIB_VERSION == _POSIX_)
674                   __set_errno (EDOM);
675                 else if (!matherr(&exc)) {
676                   if (_LIB_VERSION == _SVID_) {
677                     (void) WRITE2("atanh: DOMAIN error\n", 20);
678                   }
679                   __set_errno (EDOM);
680                 }
681                 break;
682             case 31:
683             case 131:
684             case 231:
685                 /* atanh(|x|=1) */
686                 exc.type = SING;
687                 exc.name = type < 100 ? "atanh" : (type < 200
688                                                    ? "atanhf" : "atanhl");
689                 exc.retval = x/zero;    /* sign(x)*inf */
690                 if (_LIB_VERSION == _POSIX_)
691                   __set_errno (ERANGE);
692                 else if (!matherr(&exc)) {
693                   if (_LIB_VERSION == _SVID_) {
694                     (void) WRITE2("atanh: SING error\n", 18);
695                   }
696                   __set_errno (EDOM);
697                 }
698                 break;
699             case 32:
700             case 132:
701             case 232:
702                 /* scalb overflow; SVID also returns +-HUGE_VAL */
703                 exc.type = OVERFLOW;
704                 exc.name = type < 100 ? "scalb" : (type < 200
705                                                    ? "scalbf" : "scalbl");
706                 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
707                 if (_LIB_VERSION == _POSIX_)
708                   __set_errno (ERANGE);
709                 else if (!matherr(&exc)) {
710                         __set_errno (ERANGE);
711                 }
712                 break;
713             case 33:
714             case 133:
715             case 233:
716                 /* scalb underflow */
717                 exc.type = UNDERFLOW;
718                 exc.name = type < 100 ? "scalb" : (type < 200
719                                                    ? "scalbf" : "scalbl");
720                 exc.retval = __copysign(zero,x);
721                 if (_LIB_VERSION == _POSIX_)
722                   __set_errno (ERANGE);
723                 else if (!matherr(&exc)) {
724                         __set_errno (ERANGE);
725                 }
726                 break;
727             case 34:
728             case 134:
729             case 234:
730                 /* j0(|x|>X_TLOSS) */
731                 exc.type = TLOSS;
732                 exc.name = type < 100 ? "j0" : (type < 200 ? "j0f" : "j0l");
733                 exc.retval = zero;
734                 if (_LIB_VERSION == _POSIX_)
735                         __set_errno (ERANGE);
736                 else if (!matherr(&exc)) {
737                         if (_LIB_VERSION == _SVID_) {
738                                 (void) WRITE2(exc.name, 2);
739                                 (void) WRITE2(": TLOSS error\n", 14);
740                         }
741                         __set_errno (ERANGE);
742                 }
743                 break;
744             case 35:
745             case 135:
746             case 235:
747                 /* y0(x>X_TLOSS) */
748                 exc.type = TLOSS;
749                 exc.name = type < 100 ? "y0" : (type < 200 ? "y0f" : "y0l");
750                 exc.retval = zero;
751                 if (_LIB_VERSION == _POSIX_)
752                         __set_errno (ERANGE);
753                 else if (!matherr(&exc)) {
754                         if (_LIB_VERSION == _SVID_) {
755                                 (void) WRITE2(exc.name, 2);
756                                 (void) WRITE2(": TLOSS error\n", 14);
757                         }
758                         __set_errno (ERANGE);
759                 }
760                 break;
761             case 36:
762             case 136:
763             case 236:
764                 /* j1(|x|>X_TLOSS) */
765                 exc.type = TLOSS;
766                 exc.name = type < 100 ? "j1" : (type < 200 ? "j1f" : "j1l");
767                 exc.retval = zero;
768                 if (_LIB_VERSION == _POSIX_)
769                         __set_errno (ERANGE);
770                 else if (!matherr(&exc)) {
771                         if (_LIB_VERSION == _SVID_) {
772                                 (void) WRITE2(exc.name, 2);
773                                 (void) WRITE2(": TLOSS error\n", 14);
774                         }
775                         __set_errno (ERANGE);
776                 }
777                 break;
778             case 37:
779             case 137:
780             case 237:
781                 /* y1(x>X_TLOSS) */
782                 exc.type = TLOSS;
783                 exc.name = type < 100 ? "y1" : (type < 200 ? "y1f" : "y1l");
784                 exc.retval = zero;
785                 if (_LIB_VERSION == _POSIX_)
786                         __set_errno (ERANGE);
787                 else if (!matherr(&exc)) {
788                         if (_LIB_VERSION == _SVID_) {
789                                 (void) WRITE2(exc.name, 2);
790                                 (void) WRITE2(": TLOSS error\n", 14);
791                         }
792                         __set_errno (ERANGE);
793                 }
794                 break;
795             case 38:
796             case 138:
797             case 238:
798                 /* jn(|x|>X_TLOSS) */
799                 exc.type = TLOSS;
800                 exc.name = type < 100 ? "jn" : (type < 200 ? "jnf" : "jnl");
801                 exc.retval = zero;
802                 if (_LIB_VERSION == _POSIX_)
803                         __set_errno (ERANGE);
804                 else if (!matherr(&exc)) {
805                         if (_LIB_VERSION == _SVID_) {
806                                 (void) WRITE2(exc.name, 2);
807                                 (void) WRITE2(": TLOSS error\n", 14);
808                         }
809                         __set_errno (ERANGE);
810                 }
811                 break;
812             case 39:
813             case 139:
814             case 239:
815                 /* yn(x>X_TLOSS) */
816                 exc.type = TLOSS;
817                 exc.name = type < 100 ? "yn" : (type < 200 ? "ynf" : "ynl");
818                 exc.retval = zero;
819                 if (_LIB_VERSION == _POSIX_)
820                         __set_errno (ERANGE);
821                 else if (!matherr(&exc)) {
822                         if (_LIB_VERSION == _SVID_) {
823                                 (void) WRITE2(exc.name, 2);
824                                 (void) WRITE2(": TLOSS error\n", 14);
825                         }
826                         __set_errno (ERANGE);
827                 }
828                 break;
829             case 40:
830             case 140:
831             case 240:
832                 /* tgamma(finite) overflow */
833                 exc.type = OVERFLOW;
834                 exc.name = type < 100 ? "tgamma" : (type < 200
835                                                    ? "tgammaf" : "tgammal");
836                 exc.retval = HUGE_VAL;
837                 if (_LIB_VERSION == _POSIX_)
838                   __set_errno (ERANGE);
839                 else if (!matherr(&exc)) {
840                   __set_errno (ERANGE);
841                 }
842                 break;
843             case 41:
844             case 141:
845             case 241:
846                 /* tgamma(-integer) */
847                 exc.type = SING;
848                 exc.name = type < 100 ? "tgamma" : (type < 200
849                                                    ? "tgammaf" : "tgammal");
850                 exc.retval = NAN;
851                 if (_LIB_VERSION == _POSIX_)
852                   __set_errno (EDOM);
853                 else if (!matherr(&exc)) {
854                   if (_LIB_VERSION == _SVID_) {
855                         (void) WRITE2("tgamma: SING error\n", 18);
856                         exc.retval = HUGE_VAL;
857                       }
858                   __set_errno (EDOM);
859                 }
860                 break;
861             case 42:
862             case 142:
863             case 242:
864                 /* pow(NaN,0.0) */
865                 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
866                 exc.type = DOMAIN;
867                 exc.name = type < 100 ? "pow" : (type < 200 ? "powf" : "powl");
868                 exc.retval = x;
869                 if (_LIB_VERSION == _IEEE_ ||
870                     _LIB_VERSION == _POSIX_) exc.retval = 1.0;
871                 else if (!matherr(&exc)) {
872                         __set_errno (EDOM);
873                 }
874                 break;
875
876             case 44:
877             case 144:
878             case 244:
879                 /* exp(finite) overflow */
880                 exc.type = OVERFLOW;
881                 exc.name = type < 100 ? "exp2" : (type < 200
882                                                   ? "exp2f" : "exp2l");
883                 if (_LIB_VERSION == _SVID_)
884                   exc.retval = HUGE;
885                 else
886                   exc.retval = HUGE_VAL;
887                 if (_LIB_VERSION == _POSIX_)
888                   __set_errno (ERANGE);
889                 else if (!matherr(&exc)) {
890                         __set_errno (ERANGE);
891                 }
892                 break;
893             case 45:
894             case 145:
895             case 245:
896                 /* exp(finite) underflow */
897                 exc.type = UNDERFLOW;
898                 exc.name = type < 100 ? "exp2" : (type < 200
899                                                   ? "exp2f" : "exp2l");
900                 exc.retval = zero;
901                 if (_LIB_VERSION == _POSIX_)
902                   __set_errno (ERANGE);
903                 else if (!matherr(&exc)) {
904                         __set_errno (ERANGE);
905                 }
906                 break;
907
908             case 46:
909             case 146:
910             case 246:
911                 /* exp(finite) overflow */
912                 exc.type = OVERFLOW;
913                 exc.name = type < 100 ? "exp10" : (type < 200
914                                                    ? "exp10f" : "exp10l");
915                 if (_LIB_VERSION == _SVID_)
916                   exc.retval = HUGE;
917                 else
918                   exc.retval = HUGE_VAL;
919                 if (_LIB_VERSION == _POSIX_)
920                   __set_errno (ERANGE);
921                 else if (!matherr(&exc)) {
922                         __set_errno (ERANGE);
923                 }
924                 break;
925             case 47:
926             case 147:
927             case 247:
928                 /* exp(finite) underflow */
929                 exc.type = UNDERFLOW;
930                 exc.name = type < 100 ? "exp10" : (type < 200
931                                                    ? "exp10f" : "exp10l");
932                 exc.retval = zero;
933                 if (_LIB_VERSION == _POSIX_)
934                   __set_errno (ERANGE);
935                 else if (!matherr(&exc)) {
936                         __set_errno (ERANGE);
937                 }
938                 break;
939             case 48:
940             case 148:
941             case 248:
942                 /* log2(0) */
943                 exc.type = SING;
944                 exc.name = type < 100 ? "log2" : (type < 200
945                                                    ? "log2f" : "log2l");
946                 if (_LIB_VERSION == _SVID_)
947                   exc.retval = -HUGE;
948                 else
949                   exc.retval = -HUGE_VAL;
950                 if (_LIB_VERSION == _POSIX_)
951                   __set_errno (ERANGE);
952                 else if (!matherr(&exc)) {
953                   __set_errno (EDOM);
954                 }
955                 break;
956             case 49:
957             case 149:
958             case 249:
959                 /* log2(x<0) */
960                 exc.type = DOMAIN;
961                 exc.name = type < 100 ? "log2" : (type < 200
962                                                    ? "log2f" : "log2l");
963                 if (_LIB_VERSION == _SVID_)
964                   exc.retval = -HUGE;
965                 else
966                   exc.retval = NAN;
967                 if (_LIB_VERSION == _POSIX_)
968                   __set_errno (EDOM);
969                 else if (!matherr(&exc)) {
970                   __set_errno (EDOM);
971                 }
972                 break;
973             case 50:
974             case 150:
975             case 250:
976                 /* tgamma(+-0) */
977                 exc.type = SING;
978                 exc.name = type < 100 ? "tgamma" : (type < 200
979                                                     ? "tgammaf" : "tgammal");
980                 exc.retval = __copysign (HUGE_VAL, x);
981                 if (_LIB_VERSION == _POSIX_)
982                   __set_errno (ERANGE);
983                 else if (!matherr(&exc)) {
984                   if (_LIB_VERSION == _SVID_)
985                     (void) WRITE2("tgamma: SING error\n", 18);
986                   __set_errno (ERANGE);
987                 }
988                 break;
989
990                 /* #### Last used is 50/150/250 ### */
991         }
992         return exc.retval;
993 }
994
995
996 float
997 __kernel_standard_f(float x, float y, int type)
998 {
999         return __kernel_standard(x, y, type);
1000 }