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