k_standard.c 20 KB

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