k_standard.c 20 KB

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