k_standard.c 20 KB

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