k_standard.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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 <math-svid-compat.h>
  18. #include <errno.h>
  19. #include <assert.h>
  20. #if LIBM_SVID_COMPAT
  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. /* XXX gcc versions until now don't delay the 0.0/0.0 division until
  30. runtime but produce NaN at compile time. This is wrong since the
  31. exceptions are not set correctly. */
  32. # if 0
  33. static const double zero = 0.0; /* used as const */
  34. # else
  35. static double zero = 0.0; /* used as const */
  36. # endif
  37. /*
  38. * Standard conformance (non-IEEE) on exception cases.
  39. * Mapping:
  40. * 1 -- acos(|x|>1)
  41. * 2 -- asin(|x|>1)
  42. * 3 -- atan2(+-0,+-0)
  43. * 4 -- hypot overflow
  44. * 5 -- cosh overflow
  45. * 6 -- exp overflow
  46. * 7 -- exp underflow
  47. * 8 -- y0(0)
  48. * 9 -- y0(-ve)
  49. * 10-- y1(0)
  50. * 11-- y1(-ve)
  51. * 12-- yn(0)
  52. * 13-- yn(-ve)
  53. * 14-- lgamma(finite) overflow
  54. * 15-- lgamma(-integer)
  55. * 16-- log(0)
  56. * 17-- log(x<0)
  57. * 18-- log10(0)
  58. * 19-- log10(x<0)
  59. * 21-- pow(x,y) overflow
  60. * 22-- pow(x,y) underflow
  61. * 23-- pow(0,negative)
  62. * 24-- pow(neg,non-integral)
  63. * 25-- sinh(finite) overflow
  64. * 26-- sqrt(negative)
  65. * 27-- fmod(x,0)
  66. * 28-- remainder(x,0)
  67. * 29-- acosh(x<1)
  68. * 30-- atanh(|x|>1)
  69. * 31-- atanh(|x|=1)
  70. * 32-- scalb overflow
  71. * 33-- scalb underflow
  72. * 34-- j0(|x|>X_TLOSS)
  73. * 35-- y0(x>X_TLOSS)
  74. * 36-- j1(|x|>X_TLOSS)
  75. * 37-- y1(x>X_TLOSS)
  76. * 38-- jn(|x|>X_TLOSS, n)
  77. * 39-- yn(x>X_TLOSS, n)
  78. * 40-- tgamma(finite) overflow
  79. * 41-- tgamma(-integer)
  80. * 43-- +0**neg
  81. * 44-- exp2 overflow
  82. * 45-- exp2 underflow
  83. * 46-- exp10 overflow
  84. * 47-- exp10 underflow
  85. * 48-- log2(0)
  86. * 49-- log2(x<0)
  87. * 50-- tgamma(+-0)
  88. */
  89. double
  90. __kernel_standard(double x, double y, int type)
  91. {
  92. struct exception exc;
  93. # ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
  94. # define HUGE_VAL inf
  95. double inf = 0.0;
  96. SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
  97. # endif
  98. /* The SVID struct exception uses a field "char *name;". */
  99. # define CSTR(func) ((char *) (type < 100 \
  100. ? func \
  101. : (type < 200 ? func "f" : func "l")))
  102. # ifdef _USE_WRITE
  103. (void) fflush(stdout);
  104. # endif
  105. exc.arg1 = x;
  106. exc.arg2 = y;
  107. switch(type) {
  108. case 1:
  109. case 101:
  110. case 201:
  111. /* acos(|x|>1) */
  112. exc.type = DOMAIN;
  113. exc.name = CSTR ("acos");
  114. if (_LIB_VERSION == _SVID_)
  115. exc.retval = HUGE;
  116. else
  117. exc.retval = NAN;
  118. if (_LIB_VERSION == _POSIX_)
  119. __set_errno (EDOM);
  120. else if (!matherr(&exc)) {
  121. if(_LIB_VERSION == _SVID_) {
  122. (void) WRITE2("acos: DOMAIN error\n", 19);
  123. }
  124. __set_errno (EDOM);
  125. }
  126. break;
  127. case 2:
  128. case 102:
  129. case 202:
  130. /* asin(|x|>1) */
  131. exc.type = DOMAIN;
  132. exc.name = CSTR ("asin");
  133. if (_LIB_VERSION == _SVID_)
  134. exc.retval = HUGE;
  135. else
  136. exc.retval = NAN;
  137. if(_LIB_VERSION == _POSIX_)
  138. __set_errno (EDOM);
  139. else if (!matherr(&exc)) {
  140. if(_LIB_VERSION == _SVID_) {
  141. (void) WRITE2("asin: DOMAIN error\n", 19);
  142. }
  143. __set_errno (EDOM);
  144. }
  145. break;
  146. case 3:
  147. case 103:
  148. case 203:
  149. /* atan2(+-0,+-0) */
  150. exc.arg1 = y;
  151. exc.arg2 = x;
  152. exc.type = DOMAIN;
  153. exc.name = CSTR ("atan2");
  154. assert (_LIB_VERSION == _SVID_);
  155. exc.retval = HUGE;
  156. if(_LIB_VERSION == _POSIX_)
  157. __set_errno (EDOM);
  158. else if (!matherr(&exc)) {
  159. if(_LIB_VERSION == _SVID_) {
  160. (void) WRITE2("atan2: DOMAIN error\n", 20);
  161. }
  162. __set_errno (EDOM);
  163. }
  164. break;
  165. case 4:
  166. case 104:
  167. case 204:
  168. /* hypot(finite,finite) overflow */
  169. exc.type = OVERFLOW;
  170. exc.name = CSTR ("hypot");
  171. if (_LIB_VERSION == _SVID_)
  172. exc.retval = HUGE;
  173. else
  174. exc.retval = HUGE_VAL;
  175. if (_LIB_VERSION == _POSIX_)
  176. __set_errno (ERANGE);
  177. else if (!matherr(&exc)) {
  178. __set_errno (ERANGE);
  179. }
  180. break;
  181. case 5:
  182. case 105:
  183. case 205:
  184. /* cosh(finite) overflow */
  185. exc.type = OVERFLOW;
  186. exc.name = CSTR ("cosh");
  187. if (_LIB_VERSION == _SVID_)
  188. exc.retval = HUGE;
  189. else
  190. exc.retval = HUGE_VAL;
  191. if (_LIB_VERSION == _POSIX_)
  192. __set_errno (ERANGE);
  193. else if (!matherr(&exc)) {
  194. __set_errno (ERANGE);
  195. }
  196. break;
  197. case 6:
  198. case 106:
  199. case 206:
  200. /* exp(finite) overflow */
  201. exc.type = OVERFLOW;
  202. exc.name = CSTR ("exp");
  203. if (_LIB_VERSION == _SVID_)
  204. exc.retval = HUGE;
  205. else
  206. exc.retval = HUGE_VAL;
  207. if (_LIB_VERSION == _POSIX_)
  208. __set_errno (ERANGE);
  209. else if (!matherr(&exc)) {
  210. __set_errno (ERANGE);
  211. }
  212. break;
  213. case 7:
  214. case 107:
  215. case 207:
  216. /* exp(finite) underflow */
  217. exc.type = UNDERFLOW;
  218. exc.name = CSTR ("exp");
  219. exc.retval = zero;
  220. if (_LIB_VERSION == _POSIX_)
  221. __set_errno (ERANGE);
  222. else if (!matherr(&exc)) {
  223. __set_errno (ERANGE);
  224. }
  225. break;
  226. case 8:
  227. case 108:
  228. case 208:
  229. /* y0(0) = -inf */
  230. exc.type = DOMAIN; /* should be SING for IEEE */
  231. exc.name = CSTR ("y0");
  232. if (_LIB_VERSION == _SVID_)
  233. exc.retval = -HUGE;
  234. else
  235. exc.retval = -HUGE_VAL;
  236. if (_LIB_VERSION == _POSIX_)
  237. __set_errno (ERANGE);
  238. else if (!matherr(&exc)) {
  239. if (_LIB_VERSION == _SVID_) {
  240. (void) WRITE2("y0: DOMAIN error\n", 17);
  241. }
  242. __set_errno (EDOM);
  243. }
  244. break;
  245. case 9:
  246. case 109:
  247. case 209:
  248. /* y0(x<0) = NaN */
  249. exc.type = DOMAIN;
  250. exc.name = CSTR ("y0");
  251. if (_LIB_VERSION == _SVID_)
  252. exc.retval = -HUGE;
  253. else
  254. exc.retval = NAN;
  255. if (_LIB_VERSION == _POSIX_)
  256. __set_errno (EDOM);
  257. else if (!matherr(&exc)) {
  258. if (_LIB_VERSION == _SVID_) {
  259. (void) WRITE2("y0: DOMAIN error\n", 17);
  260. }
  261. __set_errno (EDOM);
  262. }
  263. break;
  264. case 10:
  265. case 110:
  266. case 210:
  267. /* y1(0) = -inf */
  268. exc.type = DOMAIN; /* should be SING for IEEE */
  269. exc.name = CSTR ("y1");
  270. if (_LIB_VERSION == _SVID_)
  271. exc.retval = -HUGE;
  272. else
  273. exc.retval = -HUGE_VAL;
  274. if (_LIB_VERSION == _POSIX_)
  275. __set_errno (ERANGE);
  276. else if (!matherr(&exc)) {
  277. if (_LIB_VERSION == _SVID_) {
  278. (void) WRITE2("y1: DOMAIN error\n", 17);
  279. }
  280. __set_errno (EDOM);
  281. }
  282. break;
  283. case 11:
  284. case 111:
  285. case 211:
  286. /* y1(x<0) = NaN */
  287. exc.type = DOMAIN;
  288. exc.name = CSTR ("y1");
  289. if (_LIB_VERSION == _SVID_)
  290. exc.retval = -HUGE;
  291. else
  292. exc.retval = NAN;
  293. if (_LIB_VERSION == _POSIX_)
  294. __set_errno (EDOM);
  295. else if (!matherr(&exc)) {
  296. if (_LIB_VERSION == _SVID_) {
  297. (void) WRITE2("y1: DOMAIN error\n", 17);
  298. }
  299. __set_errno (EDOM);
  300. }
  301. break;
  302. case 12:
  303. case 112:
  304. case 212:
  305. /* yn(n,0) = -inf */
  306. exc.type = DOMAIN; /* should be SING for IEEE */
  307. exc.name = CSTR ("yn");
  308. if (_LIB_VERSION == _SVID_)
  309. exc.retval = -HUGE;
  310. else
  311. exc.retval = ((x < 0 && ((int) x & 1) != 0)
  312. ? HUGE_VAL
  313. : -HUGE_VAL);
  314. if (_LIB_VERSION == _POSIX_)
  315. __set_errno (ERANGE);
  316. else if (!matherr(&exc)) {
  317. if (_LIB_VERSION == _SVID_) {
  318. (void) WRITE2("yn: DOMAIN error\n", 17);
  319. }
  320. __set_errno (EDOM);
  321. }
  322. break;
  323. case 13:
  324. case 113:
  325. case 213:
  326. /* yn(x<0) = NaN */
  327. exc.type = DOMAIN;
  328. exc.name = CSTR ("yn");
  329. if (_LIB_VERSION == _SVID_)
  330. exc.retval = -HUGE;
  331. else
  332. exc.retval = NAN;
  333. if (_LIB_VERSION == _POSIX_)
  334. __set_errno (EDOM);
  335. else if (!matherr(&exc)) {
  336. if (_LIB_VERSION == _SVID_) {
  337. (void) WRITE2("yn: DOMAIN error\n", 17);
  338. }
  339. __set_errno (EDOM);
  340. }
  341. break;
  342. case 14:
  343. case 114:
  344. case 214:
  345. /* lgamma(finite) overflow */
  346. exc.type = OVERFLOW;
  347. exc.name = CSTR ("lgamma");
  348. if (_LIB_VERSION == _SVID_)
  349. exc.retval = HUGE;
  350. else
  351. exc.retval = HUGE_VAL;
  352. if (_LIB_VERSION == _POSIX_)
  353. __set_errno (ERANGE);
  354. else if (!matherr(&exc)) {
  355. __set_errno (ERANGE);
  356. }
  357. break;
  358. case 15:
  359. case 115:
  360. case 215:
  361. /* lgamma(-integer) or lgamma(0) */
  362. exc.type = SING;
  363. exc.name = CSTR ("lgamma");
  364. if (_LIB_VERSION == _SVID_)
  365. exc.retval = HUGE;
  366. else
  367. exc.retval = HUGE_VAL;
  368. if (_LIB_VERSION == _POSIX_)
  369. __set_errno (ERANGE);
  370. else if (!matherr(&exc)) {
  371. if (_LIB_VERSION == _SVID_) {
  372. (void) WRITE2("lgamma: SING error\n", 19);
  373. }
  374. __set_errno (EDOM);
  375. }
  376. break;
  377. case 16:
  378. case 116:
  379. case 216:
  380. /* log(0) */
  381. exc.type = SING;
  382. exc.name = CSTR ("log");
  383. if (_LIB_VERSION == _SVID_)
  384. exc.retval = -HUGE;
  385. else
  386. exc.retval = -HUGE_VAL;
  387. if (_LIB_VERSION == _POSIX_)
  388. __set_errno (ERANGE);
  389. else if (!matherr(&exc)) {
  390. if (_LIB_VERSION == _SVID_) {
  391. (void) WRITE2("log: SING error\n", 16);
  392. }
  393. __set_errno (EDOM);
  394. }
  395. break;
  396. case 17:
  397. case 117:
  398. case 217:
  399. /* log(x<0) */
  400. exc.type = DOMAIN;
  401. exc.name = CSTR ("log");
  402. if (_LIB_VERSION == _SVID_)
  403. exc.retval = -HUGE;
  404. else
  405. exc.retval = NAN;
  406. if (_LIB_VERSION == _POSIX_)
  407. __set_errno (EDOM);
  408. else if (!matherr(&exc)) {
  409. if (_LIB_VERSION == _SVID_) {
  410. (void) WRITE2("log: DOMAIN error\n", 18);
  411. }
  412. __set_errno (EDOM);
  413. }
  414. break;
  415. case 18:
  416. case 118:
  417. case 218:
  418. /* log10(0) */
  419. exc.type = SING;
  420. exc.name = CSTR ("log10");
  421. if (_LIB_VERSION == _SVID_)
  422. exc.retval = -HUGE;
  423. else
  424. exc.retval = -HUGE_VAL;
  425. if (_LIB_VERSION == _POSIX_)
  426. __set_errno (ERANGE);
  427. else if (!matherr(&exc)) {
  428. if (_LIB_VERSION == _SVID_) {
  429. (void) WRITE2("log10: SING error\n", 18);
  430. }
  431. __set_errno (EDOM);
  432. }
  433. break;
  434. case 19:
  435. case 119:
  436. case 219:
  437. /* log10(x<0) */
  438. exc.type = DOMAIN;
  439. exc.name = CSTR ("log10");
  440. if (_LIB_VERSION == _SVID_)
  441. exc.retval = -HUGE;
  442. else
  443. exc.retval = NAN;
  444. if (_LIB_VERSION == _POSIX_)
  445. __set_errno (EDOM);
  446. else if (!matherr(&exc)) {
  447. if (_LIB_VERSION == _SVID_) {
  448. (void) WRITE2("log10: DOMAIN error\n", 20);
  449. }
  450. __set_errno (EDOM);
  451. }
  452. break;
  453. case 21:
  454. case 121:
  455. case 221:
  456. /* pow(x,y) overflow */
  457. exc.type = OVERFLOW;
  458. exc.name = CSTR ("pow");
  459. if (_LIB_VERSION == _SVID_) {
  460. exc.retval = HUGE;
  461. y *= 0.5;
  462. if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
  463. } else {
  464. exc.retval = HUGE_VAL;
  465. y *= 0.5;
  466. if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
  467. }
  468. if (_LIB_VERSION == _POSIX_)
  469. __set_errno (ERANGE);
  470. else if (!matherr(&exc)) {
  471. __set_errno (ERANGE);
  472. }
  473. break;
  474. case 22:
  475. case 122:
  476. case 222:
  477. /* pow(x,y) underflow */
  478. exc.type = UNDERFLOW;
  479. exc.name = CSTR ("pow");
  480. exc.retval = zero;
  481. y *= 0.5;
  482. if (x < zero && rint (y) != y)
  483. exc.retval = -zero;
  484. if (_LIB_VERSION == _POSIX_)
  485. __set_errno (ERANGE);
  486. else if (!matherr(&exc)) {
  487. __set_errno (ERANGE);
  488. }
  489. break;
  490. case 23:
  491. case 123:
  492. case 223:
  493. /* -0**neg */
  494. exc.type = DOMAIN;
  495. exc.name = CSTR ("pow");
  496. if (_LIB_VERSION == _SVID_)
  497. exc.retval = zero;
  498. else
  499. exc.retval = -HUGE_VAL;
  500. if (_LIB_VERSION == _POSIX_)
  501. __set_errno (ERANGE);
  502. else if (!matherr(&exc)) {
  503. if (_LIB_VERSION == _SVID_) {
  504. (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
  505. }
  506. __set_errno (EDOM);
  507. }
  508. break;
  509. case 43:
  510. case 143:
  511. case 243:
  512. /* +0**neg */
  513. exc.type = DOMAIN;
  514. exc.name = CSTR ("pow");
  515. if (_LIB_VERSION == _SVID_)
  516. exc.retval = zero;
  517. else
  518. exc.retval = HUGE_VAL;
  519. if (_LIB_VERSION == _POSIX_)
  520. __set_errno (ERANGE);
  521. else if (!matherr(&exc)) {
  522. if (_LIB_VERSION == _SVID_) {
  523. (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
  524. }
  525. __set_errno (EDOM);
  526. }
  527. break;
  528. case 24:
  529. case 124:
  530. case 224:
  531. /* neg**non-integral */
  532. exc.type = DOMAIN;
  533. exc.name = CSTR ("pow");
  534. if (_LIB_VERSION == _SVID_)
  535. exc.retval = zero;
  536. else
  537. exc.retval = zero/zero; /* X/Open allow NaN */
  538. if (_LIB_VERSION == _POSIX_)
  539. __set_errno (EDOM);
  540. else if (!matherr(&exc)) {
  541. if (_LIB_VERSION == _SVID_) {
  542. (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
  543. }
  544. __set_errno (EDOM);
  545. }
  546. break;
  547. case 25:
  548. case 125:
  549. case 225:
  550. /* sinh(finite) overflow */
  551. exc.type = OVERFLOW;
  552. exc.name = CSTR ("sinh");
  553. if (_LIB_VERSION == _SVID_)
  554. exc.retval = ( (x>zero) ? HUGE : -HUGE);
  555. else
  556. exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
  557. if (_LIB_VERSION == _POSIX_)
  558. __set_errno (ERANGE);
  559. else if (!matherr(&exc)) {
  560. __set_errno (ERANGE);
  561. }
  562. break;
  563. case 26:
  564. case 126:
  565. case 226:
  566. /* sqrt(x<0) */
  567. exc.type = DOMAIN;
  568. exc.name = CSTR ("sqrt");
  569. if (_LIB_VERSION == _SVID_)
  570. exc.retval = zero;
  571. else
  572. exc.retval = zero/zero;
  573. if (_LIB_VERSION == _POSIX_)
  574. __set_errno (EDOM);
  575. else if (!matherr(&exc)) {
  576. if (_LIB_VERSION == _SVID_) {
  577. (void) WRITE2("sqrt: DOMAIN error\n", 19);
  578. }
  579. __set_errno (EDOM);
  580. }
  581. break;
  582. case 27:
  583. case 127:
  584. case 227:
  585. /* fmod(x,0) */
  586. exc.type = DOMAIN;
  587. exc.name = CSTR ("fmod");
  588. if (_LIB_VERSION == _SVID_)
  589. exc.retval = x;
  590. else
  591. exc.retval = zero/zero;
  592. if (_LIB_VERSION == _POSIX_)
  593. __set_errno (EDOM);
  594. else if (!matherr(&exc)) {
  595. if (_LIB_VERSION == _SVID_) {
  596. (void) WRITE2("fmod: DOMAIN error\n", 20);
  597. }
  598. __set_errno (EDOM);
  599. }
  600. break;
  601. case 28:
  602. case 128:
  603. case 228:
  604. /* remainder(x,0) */
  605. exc.type = DOMAIN;
  606. exc.name = CSTR ("remainder");
  607. exc.retval = zero/zero;
  608. if (_LIB_VERSION == _POSIX_)
  609. __set_errno (EDOM);
  610. else if (!matherr(&exc)) {
  611. if (_LIB_VERSION == _SVID_) {
  612. (void) WRITE2("remainder: DOMAIN error\n", 24);
  613. }
  614. __set_errno (EDOM);
  615. }
  616. break;
  617. case 29:
  618. case 129:
  619. case 229:
  620. /* acosh(x<1) */
  621. exc.type = DOMAIN;
  622. exc.name = CSTR ("acosh");
  623. exc.retval = zero/zero;
  624. if (_LIB_VERSION == _POSIX_)
  625. __set_errno (EDOM);
  626. else if (!matherr(&exc)) {
  627. if (_LIB_VERSION == _SVID_) {
  628. (void) WRITE2("acosh: DOMAIN error\n", 20);
  629. }
  630. __set_errno (EDOM);
  631. }
  632. break;
  633. case 30:
  634. case 130:
  635. case 230:
  636. /* atanh(|x|>1) */
  637. exc.type = DOMAIN;
  638. exc.name = CSTR ("atanh");
  639. exc.retval = zero/zero;
  640. if (_LIB_VERSION == _POSIX_)
  641. __set_errno (EDOM);
  642. else if (!matherr(&exc)) {
  643. if (_LIB_VERSION == _SVID_) {
  644. (void) WRITE2("atanh: DOMAIN error\n", 20);
  645. }
  646. __set_errno (EDOM);
  647. }
  648. break;
  649. case 31:
  650. case 131:
  651. case 231:
  652. /* atanh(|x|=1) */
  653. exc.type = SING;
  654. exc.name = CSTR ("atanh");
  655. exc.retval = x/zero; /* sign(x)*inf */
  656. if (_LIB_VERSION == _POSIX_)
  657. __set_errno (ERANGE);
  658. else if (!matherr(&exc)) {
  659. if (_LIB_VERSION == _SVID_) {
  660. (void) WRITE2("atanh: SING error\n", 18);
  661. }
  662. __set_errno (EDOM);
  663. }
  664. break;
  665. case 32:
  666. case 132:
  667. case 232:
  668. /* scalb overflow; SVID also returns +-HUGE_VAL */
  669. exc.type = OVERFLOW;
  670. exc.name = CSTR ("scalb");
  671. exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
  672. if (_LIB_VERSION == _POSIX_)
  673. __set_errno (ERANGE);
  674. else if (!matherr(&exc)) {
  675. __set_errno (ERANGE);
  676. }
  677. break;
  678. case 33:
  679. case 133:
  680. case 233:
  681. /* scalb underflow */
  682. exc.type = UNDERFLOW;
  683. exc.name = CSTR ("scalb");
  684. exc.retval = copysign(zero,x);
  685. if (_LIB_VERSION == _POSIX_)
  686. __set_errno (ERANGE);
  687. else if (!matherr(&exc)) {
  688. __set_errno (ERANGE);
  689. }
  690. break;
  691. case 34:
  692. case 134:
  693. case 234:
  694. /* j0(|x|>X_TLOSS) */
  695. exc.type = TLOSS;
  696. exc.name = CSTR ("j0");
  697. exc.retval = zero;
  698. if (_LIB_VERSION == _POSIX_)
  699. __set_errno (ERANGE);
  700. else if (!matherr(&exc)) {
  701. if (_LIB_VERSION == _SVID_) {
  702. (void) WRITE2(exc.name, 2);
  703. (void) WRITE2(": TLOSS error\n", 14);
  704. }
  705. __set_errno (ERANGE);
  706. }
  707. break;
  708. case 35:
  709. case 135:
  710. case 235:
  711. /* y0(x>X_TLOSS) */
  712. exc.type = TLOSS;
  713. exc.name = CSTR ("y0");
  714. exc.retval = zero;
  715. if (_LIB_VERSION == _POSIX_)
  716. __set_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. __set_errno (ERANGE);
  723. }
  724. break;
  725. case 36:
  726. case 136:
  727. case 236:
  728. /* j1(|x|>X_TLOSS) */
  729. exc.type = TLOSS;
  730. exc.name = CSTR ("j1");
  731. exc.retval = zero;
  732. if (_LIB_VERSION == _POSIX_)
  733. __set_errno (ERANGE);
  734. else if (!matherr(&exc)) {
  735. if (_LIB_VERSION == _SVID_) {
  736. (void) WRITE2(exc.name, 2);
  737. (void) WRITE2(": TLOSS error\n", 14);
  738. }
  739. __set_errno (ERANGE);
  740. }
  741. break;
  742. case 37:
  743. case 137:
  744. case 237:
  745. /* y1(x>X_TLOSS) */
  746. exc.type = TLOSS;
  747. exc.name = CSTR ("y1");
  748. exc.retval = zero;
  749. if (_LIB_VERSION == _POSIX_)
  750. __set_errno (ERANGE);
  751. else if (!matherr(&exc)) {
  752. if (_LIB_VERSION == _SVID_) {
  753. (void) WRITE2(exc.name, 2);
  754. (void) WRITE2(": TLOSS error\n", 14);
  755. }
  756. __set_errno (ERANGE);
  757. }
  758. break;
  759. case 38:
  760. case 138:
  761. case 238:
  762. /* jn(|x|>X_TLOSS) */
  763. exc.type = TLOSS;
  764. exc.name = CSTR ("jn");
  765. exc.retval = zero;
  766. if (_LIB_VERSION == _POSIX_)
  767. __set_errno (ERANGE);
  768. else if (!matherr(&exc)) {
  769. if (_LIB_VERSION == _SVID_) {
  770. (void) WRITE2(exc.name, 2);
  771. (void) WRITE2(": TLOSS error\n", 14);
  772. }
  773. __set_errno (ERANGE);
  774. }
  775. break;
  776. case 39:
  777. case 139:
  778. case 239:
  779. /* yn(x>X_TLOSS) */
  780. exc.type = TLOSS;
  781. exc.name = CSTR ("yn");
  782. exc.retval = zero;
  783. if (_LIB_VERSION == _POSIX_)
  784. __set_errno (ERANGE);
  785. else if (!matherr(&exc)) {
  786. if (_LIB_VERSION == _SVID_) {
  787. (void) WRITE2(exc.name, 2);
  788. (void) WRITE2(": TLOSS error\n", 14);
  789. }
  790. __set_errno (ERANGE);
  791. }
  792. break;
  793. case 40:
  794. case 140:
  795. case 240:
  796. /* tgamma(finite) overflow */
  797. exc.type = OVERFLOW;
  798. exc.name = CSTR ("tgamma");
  799. exc.retval = copysign (HUGE_VAL, x);
  800. if (_LIB_VERSION == _POSIX_)
  801. __set_errno (ERANGE);
  802. else if (!matherr(&exc)) {
  803. __set_errno (ERANGE);
  804. }
  805. break;
  806. case 41:
  807. case 141:
  808. case 241:
  809. /* tgamma(-integer) */
  810. exc.type = SING;
  811. exc.name = CSTR ("tgamma");
  812. exc.retval = NAN;
  813. if (_LIB_VERSION == _POSIX_)
  814. __set_errno (EDOM);
  815. else if (!matherr(&exc)) {
  816. if (_LIB_VERSION == _SVID_) {
  817. (void) WRITE2("tgamma: SING error\n", 18);
  818. exc.retval = HUGE_VAL;
  819. }
  820. __set_errno (EDOM);
  821. }
  822. break;
  823. case 44:
  824. case 144:
  825. case 244:
  826. /* exp(finite) overflow */
  827. exc.type = OVERFLOW;
  828. exc.name = CSTR ("exp2");
  829. if (_LIB_VERSION == _SVID_)
  830. exc.retval = HUGE;
  831. else
  832. exc.retval = HUGE_VAL;
  833. if (_LIB_VERSION == _POSIX_)
  834. __set_errno (ERANGE);
  835. else if (!matherr(&exc)) {
  836. __set_errno (ERANGE);
  837. }
  838. break;
  839. case 45:
  840. case 145:
  841. case 245:
  842. /* exp(finite) underflow */
  843. exc.type = UNDERFLOW;
  844. exc.name = CSTR ("exp2");
  845. exc.retval = zero;
  846. if (_LIB_VERSION == _POSIX_)
  847. __set_errno (ERANGE);
  848. else if (!matherr(&exc)) {
  849. __set_errno (ERANGE);
  850. }
  851. break;
  852. case 46:
  853. case 146:
  854. case 246:
  855. /* exp(finite) overflow */
  856. exc.type = OVERFLOW;
  857. exc.name = CSTR ("exp10");
  858. if (_LIB_VERSION == _SVID_)
  859. exc.retval = HUGE;
  860. else
  861. exc.retval = HUGE_VAL;
  862. if (_LIB_VERSION == _POSIX_)
  863. __set_errno (ERANGE);
  864. else if (!matherr(&exc)) {
  865. __set_errno (ERANGE);
  866. }
  867. break;
  868. case 47:
  869. case 147:
  870. case 247:
  871. /* exp(finite) underflow */
  872. exc.type = UNDERFLOW;
  873. exc.name = CSTR ("exp10");
  874. exc.retval = zero;
  875. if (_LIB_VERSION == _POSIX_)
  876. __set_errno (ERANGE);
  877. else if (!matherr(&exc)) {
  878. __set_errno (ERANGE);
  879. }
  880. break;
  881. case 48:
  882. case 148:
  883. case 248:
  884. /* log2(0) */
  885. exc.type = SING;
  886. exc.name = CSTR ("log2");
  887. if (_LIB_VERSION == _SVID_)
  888. exc.retval = -HUGE;
  889. else
  890. exc.retval = -HUGE_VAL;
  891. if (_LIB_VERSION == _POSIX_)
  892. __set_errno (ERANGE);
  893. else if (!matherr(&exc)) {
  894. __set_errno (EDOM);
  895. }
  896. break;
  897. case 49:
  898. case 149:
  899. case 249:
  900. /* log2(x<0) */
  901. exc.type = DOMAIN;
  902. exc.name = CSTR ("log2");
  903. if (_LIB_VERSION == _SVID_)
  904. exc.retval = -HUGE;
  905. else
  906. exc.retval = NAN;
  907. if (_LIB_VERSION == _POSIX_)
  908. __set_errno (EDOM);
  909. else if (!matherr(&exc)) {
  910. __set_errno (EDOM);
  911. }
  912. break;
  913. case 50:
  914. case 150:
  915. case 250:
  916. /* tgamma(+-0) */
  917. exc.type = SING;
  918. exc.name = CSTR ("tgamma");
  919. exc.retval = copysign (HUGE_VAL, x);
  920. if (_LIB_VERSION == _POSIX_)
  921. __set_errno (ERANGE);
  922. else if (!matherr(&exc)) {
  923. if (_LIB_VERSION == _SVID_)
  924. (void) WRITE2("tgamma: SING error\n", 18);
  925. __set_errno (ERANGE);
  926. }
  927. break;
  928. /* #### Last used is 50/150/250 ### */
  929. default:
  930. __builtin_unreachable ();
  931. }
  932. return exc.retval;
  933. }
  934. #endif