| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 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 | 	    case 32: | 
 | 602 | 	    case 132: | 
 | 603 | 		/* scalb overflow; SVID also returns +-HUGE_VAL */ | 
 | 604 | 		exc.type = OVERFLOW; | 
 | 605 | 		exc.name = type < 100 ? "scalb" : "scalbf"; | 
 | 606 | 		exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL; | 
 | 607 | 		if (_LIB_VERSION == _POSIX_) | 
 | 608 | 		  errno = ERANGE; | 
 | 609 | 		else if (!matherr(&exc)) { | 
 | 610 | 			errno = ERANGE; | 
 | 611 | 		} | 
 | 612 | 		break; | 
 | 613 | 	    case 33: | 
 | 614 | 	    case 133: | 
 | 615 | 		/* scalb underflow */ | 
 | 616 | 		exc.type = UNDERFLOW; | 
 | 617 | 		exc.name = type < 100 ? "scalb" : "scalbf"; | 
 | 618 | 		exc.retval = copysign(zero,x); | 
 | 619 | 		if (_LIB_VERSION == _POSIX_) | 
 | 620 | 		  errno = ERANGE; | 
 | 621 | 		else if (!matherr(&exc)) { | 
 | 622 | 			errno = ERANGE; | 
 | 623 | 		} | 
 | 624 | 		break; | 
 | 625 | 	    case 34: | 
 | 626 | 	    case 134: | 
 | 627 | 		/* j0(|x|>X_TLOSS) */ | 
 | 628 |                 exc.type = TLOSS; | 
 | 629 |                 exc.name = type < 100 ? "j0" : "j0f"; | 
 | 630 |                 exc.retval = zero; | 
 | 631 |                 if (_LIB_VERSION == _POSIX_) | 
 | 632 |                         errno = ERANGE; | 
 | 633 |                 else if (!matherr(&exc)) { | 
 | 634 |                         if (_LIB_VERSION == _SVID_) { | 
 | 635 |                                 (void) WRITE2(exc.name, 2); | 
 | 636 |                                 (void) WRITE2(": TLOSS error\n", 14); | 
 | 637 |                         } | 
 | 638 |                         errno = ERANGE; | 
 | 639 |                 } | 
 | 640 | 		break; | 
 | 641 | 	    case 35: | 
 | 642 | 	    case 135: | 
 | 643 | 		/* y0(x>X_TLOSS) */ | 
 | 644 |                 exc.type = TLOSS; | 
 | 645 |                 exc.name = type < 100 ? "y0" : "y0f"; | 
 | 646 |                 exc.retval = zero; | 
 | 647 |                 if (_LIB_VERSION == _POSIX_) | 
 | 648 |                         errno = ERANGE; | 
 | 649 |                 else if (!matherr(&exc)) { | 
 | 650 |                         if (_LIB_VERSION == _SVID_) { | 
 | 651 |                                 (void) WRITE2(exc.name, 2); | 
 | 652 |                                 (void) WRITE2(": TLOSS error\n", 14); | 
 | 653 |                         } | 
 | 654 |                         errno = ERANGE; | 
 | 655 |                 } | 
 | 656 | 		break; | 
 | 657 | 	    case 36: | 
 | 658 | 	    case 136: | 
 | 659 | 		/* j1(|x|>X_TLOSS) */ | 
 | 660 |                 exc.type = TLOSS; | 
 | 661 |                 exc.name = type < 100 ? "j1" : "j1f"; | 
 | 662 |                 exc.retval = zero; | 
 | 663 |                 if (_LIB_VERSION == _POSIX_) | 
 | 664 |                         errno = ERANGE; | 
 | 665 |                 else if (!matherr(&exc)) { | 
 | 666 |                         if (_LIB_VERSION == _SVID_) { | 
 | 667 |                                 (void) WRITE2(exc.name, 2); | 
 | 668 |                                 (void) WRITE2(": TLOSS error\n", 14); | 
 | 669 |                         } | 
 | 670 |                         errno = ERANGE; | 
 | 671 |                 } | 
 | 672 | 		break; | 
 | 673 | 	    case 37: | 
 | 674 | 	    case 137: | 
 | 675 | 		/* y1(x>X_TLOSS) */ | 
 | 676 |                 exc.type = TLOSS; | 
 | 677 |                 exc.name = type < 100 ? "y1" : "y1f"; | 
 | 678 |                 exc.retval = zero; | 
 | 679 |                 if (_LIB_VERSION == _POSIX_) | 
 | 680 |                         errno = ERANGE; | 
 | 681 |                 else if (!matherr(&exc)) { | 
 | 682 |                         if (_LIB_VERSION == _SVID_) { | 
 | 683 |                                 (void) WRITE2(exc.name, 2); | 
 | 684 |                                 (void) WRITE2(": TLOSS error\n", 14); | 
 | 685 |                         } | 
 | 686 |                         errno = ERANGE; | 
 | 687 |                 } | 
 | 688 | 		break; | 
 | 689 | 	    case 38: | 
 | 690 | 	    case 138: | 
 | 691 | 		/* jn(|x|>X_TLOSS) */ | 
 | 692 |                 exc.type = TLOSS; | 
 | 693 |                 exc.name = type < 100 ? "jn" : "jnf"; | 
 | 694 |                 exc.retval = zero; | 
 | 695 |                 if (_LIB_VERSION == _POSIX_) | 
 | 696 |                         errno = ERANGE; | 
 | 697 |                 else if (!matherr(&exc)) { | 
 | 698 |                         if (_LIB_VERSION == _SVID_) { | 
 | 699 |                                 (void) WRITE2(exc.name, 2); | 
 | 700 |                                 (void) WRITE2(": TLOSS error\n", 14); | 
 | 701 |                         } | 
 | 702 |                         errno = ERANGE; | 
 | 703 |                 } | 
 | 704 | 		break; | 
 | 705 | 	    case 39: | 
 | 706 | 	    case 139: | 
 | 707 | 		/* yn(x>X_TLOSS) */ | 
 | 708 |                 exc.type = TLOSS; | 
 | 709 |                 exc.name = type < 100 ? "yn" : "ynf"; | 
 | 710 |                 exc.retval = zero; | 
 | 711 |                 if (_LIB_VERSION == _POSIX_) | 
 | 712 |                         errno = ERANGE; | 
 | 713 |                 else if (!matherr(&exc)) { | 
 | 714 |                         if (_LIB_VERSION == _SVID_) { | 
 | 715 |                                 (void) WRITE2(exc.name, 2); | 
 | 716 |                                 (void) WRITE2(": TLOSS error\n", 14); | 
 | 717 |                         } | 
 | 718 |                         errno = ERANGE; | 
 | 719 |                 } | 
 | 720 | 		break; | 
 | 721 | 	    case 40: | 
 | 722 | 	    case 140: | 
 | 723 | 		/* gamma(finite) overflow */ | 
 | 724 | 		exc.type = OVERFLOW; | 
 | 725 | 		exc.name = type < 100 ? "gamma" : "gammaf"; | 
 | 726 |                 if (_LIB_VERSION == _SVID_) | 
 | 727 |                   exc.retval = HUGE; | 
 | 728 |                 else | 
 | 729 |                   exc.retval = HUGE_VAL; | 
 | 730 |                 if (_LIB_VERSION == _POSIX_) | 
 | 731 | 		  errno = ERANGE; | 
 | 732 |                 else if (!matherr(&exc)) { | 
 | 733 |                   errno = ERANGE; | 
 | 734 |                 } | 
 | 735 | 		break; | 
 | 736 | 	    case 41: | 
 | 737 | 	    case 141: | 
 | 738 | 		/* gamma(-integer) or gamma(0) */ | 
 | 739 | 		exc.type = SING; | 
 | 740 | 		exc.name = type < 100 ? "gamma" : "gammaf"; | 
 | 741 |                 if (_LIB_VERSION == _SVID_) | 
 | 742 |                   exc.retval = HUGE; | 
 | 743 |                 else | 
 | 744 |                   exc.retval = HUGE_VAL; | 
 | 745 | 		if (_LIB_VERSION == _POSIX_) | 
 | 746 | 		  errno = EDOM; | 
 | 747 | 		else if (!matherr(&exc)) { | 
 | 748 | 		  if (_LIB_VERSION == _SVID_) { | 
 | 749 | 			(void) WRITE2("gamma: SING error\n", 18); | 
 | 750 | 		      } | 
 | 751 | 		  errno = EDOM; | 
 | 752 | 		} | 
 | 753 | 		break; | 
 | 754 | 	    case 42: | 
 | 755 | 	    case 142: | 
 | 756 | 		/* pow(NaN,0.0) */ | 
 | 757 | 		/* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */ | 
 | 758 | 		exc.type = DOMAIN; | 
 | 759 | 		exc.name = type < 100 ? "pow" : "powf"; | 
 | 760 | 		exc.retval = x; | 
 | 761 | 		if (_LIB_VERSION == _IEEE_ || | 
 | 762 | 		    _LIB_VERSION == _POSIX_) exc.retval = 1.0; | 
 | 763 | 		else if (!matherr(&exc)) { | 
 | 764 | 			errno = EDOM; | 
 | 765 | 		} | 
 | 766 | 		break; | 
 | 767 | 	} | 
 | 768 | 	return exc.retval; | 
 | 769 | } | 
 | 770 | #endif /* _IEEE_LIBM */ |