k_standard.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. #include <assert.h>
  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. /* XXX gcc versions until now don't delay the 0.0/0.0 division until
  28. runtime but produce NaN at compile time. This is wrong since the
  29. exceptions are not set correctly. */
  30. #if 0
  31. static const double zero = 0.0; /* used as const */
  32. #else
  33. static double zero = 0.0; /* used as const */
  34. #endif
  35. /*
  36. * Standard conformance (non-IEEE) on exception cases.
  37. * Mapping:
  38. * 1 -- acos(|x|>1)
  39. * 2 -- asin(|x|>1)
  40. * 3 -- atan2(+-0,+-0)
  41. * 4 -- hypot overflow
  42. * 5 -- cosh overflow
  43. * 6 -- exp overflow
  44. * 7 -- exp underflow
  45. * 8 -- y0(0)
  46. * 9 -- y0(-ve)
  47. * 10-- y1(0)
  48. * 11-- y1(-ve)
  49. * 12-- yn(0)
  50. * 13-- yn(-ve)
  51. * 14-- lgamma(finite) overflow
  52. * 15-- lgamma(-integer)
  53. * 16-- log(0)
  54. * 17-- log(x<0)
  55. * 18-- log10(0)
  56. * 19-- log10(x<0)
  57. * 20-- pow(0.0,0.0)
  58. * 21-- pow(x,y) overflow
  59. * 22-- pow(x,y) underflow
  60. * 23-- pow(0,negative)
  61. * 24-- pow(neg,non-integral)
  62. * 25-- sinh(finite) overflow
  63. * 26-- sqrt(negative)
  64. * 27-- fmod(x,0)
  65. * 28-- remainder(x,0)
  66. * 29-- acosh(x<1)
  67. * 30-- atanh(|x|>1)
  68. * 31-- atanh(|x|=1)
  69. * 32-- scalb overflow
  70. * 33-- scalb underflow
  71. * 34-- j0(|x|>X_TLOSS)
  72. * 35-- y0(x>X_TLOSS)
  73. * 36-- j1(|x|>X_TLOSS)
  74. * 37-- y1(x>X_TLOSS)
  75. * 38-- jn(|x|>X_TLOSS, n)
  76. * 39-- yn(x>X_TLOSS, n)
  77. * 40-- tgamma(finite) overflow
  78. * 41-- tgamma(-integer)
  79. * 42-- pow(NaN,0.0)
  80. * 43-- +0**neg
  81. * 44-- exp2 overflow done
  82. * 45-- exp2 underflow done
  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 20:
  454. case 120:
  455. case 220:
  456. /* pow(0.0,0.0) */
  457. /* error only if _LIB_VERSION == _SVID_ */
  458. exc.type = DOMAIN;
  459. exc.name = CSTR ("pow");
  460. exc.retval = zero;
  461. if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
  462. else if (!matherr(&exc)) {
  463. (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
  464. __set_errno (EDOM);
  465. }
  466. break;
  467. case 21:
  468. case 121:
  469. case 221:
  470. /* pow(x,y) overflow */
  471. exc.type = OVERFLOW;
  472. exc.name = CSTR ("pow");
  473. if (_LIB_VERSION == _SVID_) {
  474. exc.retval = HUGE;
  475. y *= 0.5;
  476. if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
  477. } else {
  478. exc.retval = HUGE_VAL;
  479. y *= 0.5;
  480. if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
  481. }
  482. if (_LIB_VERSION == _POSIX_)
  483. __set_errno (ERANGE);
  484. else if (!matherr(&exc)) {
  485. __set_errno (ERANGE);
  486. }
  487. break;
  488. case 22:
  489. case 122:
  490. case 222:
  491. /* pow(x,y) underflow */
  492. exc.type = UNDERFLOW;
  493. exc.name = CSTR ("pow");
  494. exc.retval = zero;
  495. y *= 0.5;
  496. if (x < zero && rint (y) != y)
  497. exc.retval = -zero;
  498. if (_LIB_VERSION == _POSIX_)
  499. __set_errno (ERANGE);
  500. else if (!matherr(&exc)) {
  501. __set_errno (ERANGE);
  502. }
  503. break;
  504. case 23:
  505. case 123:
  506. case 223:
  507. /* -0**neg */
  508. exc.type = DOMAIN;
  509. exc.name = CSTR ("pow");
  510. if (_LIB_VERSION == _SVID_)
  511. exc.retval = zero;
  512. else
  513. exc.retval = -HUGE_VAL;
  514. if (_LIB_VERSION == _POSIX_)
  515. __set_errno (ERANGE);
  516. else if (!matherr(&exc)) {
  517. if (_LIB_VERSION == _SVID_) {
  518. (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
  519. }
  520. __set_errno (EDOM);
  521. }
  522. break;
  523. case 43:
  524. case 143:
  525. case 243:
  526. /* +0**neg */
  527. exc.type = DOMAIN;
  528. exc.name = CSTR ("pow");
  529. if (_LIB_VERSION == _SVID_)
  530. exc.retval = zero;
  531. else
  532. exc.retval = HUGE_VAL;
  533. if (_LIB_VERSION == _POSIX_)
  534. __set_errno (ERANGE);
  535. else if (!matherr(&exc)) {
  536. if (_LIB_VERSION == _SVID_) {
  537. (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
  538. }
  539. __set_errno (EDOM);
  540. }
  541. break;
  542. case 24:
  543. case 124:
  544. case 224:
  545. /* neg**non-integral */
  546. exc.type = DOMAIN;
  547. exc.name = CSTR ("pow");
  548. if (_LIB_VERSION == _SVID_)
  549. exc.retval = zero;
  550. else
  551. exc.retval = zero/zero; /* X/Open allow NaN */
  552. if (_LIB_VERSION == _POSIX_)
  553. __set_errno (EDOM);
  554. else if (!matherr(&exc)) {
  555. if (_LIB_VERSION == _SVID_) {
  556. (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
  557. }
  558. __set_errno (EDOM);
  559. }
  560. break;
  561. case 25:
  562. case 125:
  563. case 225:
  564. /* sinh(finite) overflow */
  565. exc.type = OVERFLOW;
  566. exc.name = CSTR ("sinh");
  567. if (_LIB_VERSION == _SVID_)
  568. exc.retval = ( (x>zero) ? HUGE : -HUGE);
  569. else
  570. exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
  571. if (_LIB_VERSION == _POSIX_)
  572. __set_errno (ERANGE);
  573. else if (!matherr(&exc)) {
  574. __set_errno (ERANGE);
  575. }
  576. break;
  577. case 26:
  578. case 126:
  579. case 226:
  580. /* sqrt(x<0) */
  581. exc.type = DOMAIN;
  582. exc.name = CSTR ("sqrt");
  583. if (_LIB_VERSION == _SVID_)
  584. exc.retval = zero;
  585. else
  586. exc.retval = zero/zero;
  587. if (_LIB_VERSION == _POSIX_)
  588. __set_errno (EDOM);
  589. else if (!matherr(&exc)) {
  590. if (_LIB_VERSION == _SVID_) {
  591. (void) WRITE2("sqrt: DOMAIN error\n", 19);
  592. }
  593. __set_errno (EDOM);
  594. }
  595. break;
  596. case 27:
  597. case 127:
  598. case 227:
  599. /* fmod(x,0) */
  600. exc.type = DOMAIN;
  601. exc.name = CSTR ("fmod");
  602. if (_LIB_VERSION == _SVID_)
  603. exc.retval = x;
  604. else
  605. exc.retval = zero/zero;
  606. if (_LIB_VERSION == _POSIX_)
  607. __set_errno (EDOM);
  608. else if (!matherr(&exc)) {
  609. if (_LIB_VERSION == _SVID_) {
  610. (void) WRITE2("fmod: DOMAIN error\n", 20);
  611. }
  612. __set_errno (EDOM);
  613. }
  614. break;
  615. case 28:
  616. case 128:
  617. case 228:
  618. /* remainder(x,0) */
  619. exc.type = DOMAIN;
  620. exc.name = CSTR ("remainder");
  621. exc.retval = zero/zero;
  622. if (_LIB_VERSION == _POSIX_)
  623. __set_errno (EDOM);
  624. else if (!matherr(&exc)) {
  625. if (_LIB_VERSION == _SVID_) {
  626. (void) WRITE2("remainder: DOMAIN error\n", 24);
  627. }
  628. __set_errno (EDOM);
  629. }
  630. break;
  631. case 29:
  632. case 129:
  633. case 229:
  634. /* acosh(x<1) */
  635. exc.type = DOMAIN;
  636. exc.name = CSTR ("acosh");
  637. exc.retval = zero/zero;
  638. if (_LIB_VERSION == _POSIX_)
  639. __set_errno (EDOM);
  640. else if (!matherr(&exc)) {
  641. if (_LIB_VERSION == _SVID_) {
  642. (void) WRITE2("acosh: DOMAIN error\n", 20);
  643. }
  644. __set_errno (EDOM);
  645. }
  646. break;
  647. case 30:
  648. case 130:
  649. case 230:
  650. /* atanh(|x|>1) */
  651. exc.type = DOMAIN;
  652. exc.name = CSTR ("atanh");
  653. exc.retval = zero/zero;
  654. if (_LIB_VERSION == _POSIX_)
  655. __set_errno (EDOM);
  656. else if (!matherr(&exc)) {
  657. if (_LIB_VERSION == _SVID_) {
  658. (void) WRITE2("atanh: DOMAIN error\n", 20);
  659. }
  660. __set_errno (EDOM);
  661. }
  662. break;
  663. case 31:
  664. case 131:
  665. case 231:
  666. /* atanh(|x|=1) */
  667. exc.type = SING;
  668. exc.name = CSTR ("atanh");
  669. exc.retval = x/zero; /* sign(x)*inf */
  670. if (_LIB_VERSION == _POSIX_)
  671. __set_errno (ERANGE);
  672. else if (!matherr(&exc)) {
  673. if (_LIB_VERSION == _SVID_) {
  674. (void) WRITE2("atanh: SING error\n", 18);
  675. }
  676. __set_errno (EDOM);
  677. }
  678. break;
  679. case 32:
  680. case 132:
  681. case 232:
  682. /* scalb overflow; SVID also returns +-HUGE_VAL */
  683. exc.type = OVERFLOW;
  684. exc.name = CSTR ("scalb");
  685. exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
  686. if (_LIB_VERSION == _POSIX_)
  687. __set_errno (ERANGE);
  688. else if (!matherr(&exc)) {
  689. __set_errno (ERANGE);
  690. }
  691. break;
  692. case 33:
  693. case 133:
  694. case 233:
  695. /* scalb underflow */
  696. exc.type = UNDERFLOW;
  697. exc.name = CSTR ("scalb");
  698. exc.retval = copysign(zero,x);
  699. if (_LIB_VERSION == _POSIX_)
  700. __set_errno (ERANGE);
  701. else if (!matherr(&exc)) {
  702. __set_errno (ERANGE);
  703. }
  704. break;
  705. case 34:
  706. case 134:
  707. case 234:
  708. /* j0(|x|>X_TLOSS) */
  709. exc.type = TLOSS;
  710. exc.name = CSTR ("j0");
  711. exc.retval = zero;
  712. if (_LIB_VERSION == _POSIX_)
  713. __set_errno (ERANGE);
  714. else if (!matherr(&exc)) {
  715. if (_LIB_VERSION == _SVID_) {
  716. (void) WRITE2(exc.name, 2);
  717. (void) WRITE2(": TLOSS error\n", 14);
  718. }
  719. __set_errno (ERANGE);
  720. }
  721. break;
  722. case 35:
  723. case 135:
  724. case 235:
  725. /* y0(x>X_TLOSS) */
  726. exc.type = TLOSS;
  727. exc.name = CSTR ("y0");
  728. exc.retval = zero;
  729. if (_LIB_VERSION == _POSIX_)
  730. __set_errno (ERANGE);
  731. else if (!matherr(&exc)) {
  732. if (_LIB_VERSION == _SVID_) {
  733. (void) WRITE2(exc.name, 2);
  734. (void) WRITE2(": TLOSS error\n", 14);
  735. }
  736. __set_errno (ERANGE);
  737. }
  738. break;
  739. case 36:
  740. case 136:
  741. case 236:
  742. /* j1(|x|>X_TLOSS) */
  743. exc.type = TLOSS;
  744. exc.name = CSTR ("j1");
  745. exc.retval = zero;
  746. if (_LIB_VERSION == _POSIX_)
  747. __set_errno (ERANGE);
  748. else if (!matherr(&exc)) {
  749. if (_LIB_VERSION == _SVID_) {
  750. (void) WRITE2(exc.name, 2);
  751. (void) WRITE2(": TLOSS error\n", 14);
  752. }
  753. __set_errno (ERANGE);
  754. }
  755. break;
  756. case 37:
  757. case 137:
  758. case 237:
  759. /* y1(x>X_TLOSS) */
  760. exc.type = TLOSS;
  761. exc.name = CSTR ("y1");
  762. exc.retval = zero;
  763. if (_LIB_VERSION == _POSIX_)
  764. __set_errno (ERANGE);
  765. else if (!matherr(&exc)) {
  766. if (_LIB_VERSION == _SVID_) {
  767. (void) WRITE2(exc.name, 2);
  768. (void) WRITE2(": TLOSS error\n", 14);
  769. }
  770. __set_errno (ERANGE);
  771. }
  772. break;
  773. case 38:
  774. case 138:
  775. case 238:
  776. /* jn(|x|>X_TLOSS) */
  777. exc.type = TLOSS;
  778. exc.name = CSTR ("jn");
  779. exc.retval = zero;
  780. if (_LIB_VERSION == _POSIX_)
  781. __set_errno (ERANGE);
  782. else if (!matherr(&exc)) {
  783. if (_LIB_VERSION == _SVID_) {
  784. (void) WRITE2(exc.name, 2);
  785. (void) WRITE2(": TLOSS error\n", 14);
  786. }
  787. __set_errno (ERANGE);
  788. }
  789. break;
  790. case 39:
  791. case 139:
  792. case 239:
  793. /* yn(x>X_TLOSS) */
  794. exc.type = TLOSS;
  795. exc.name = CSTR ("yn");
  796. exc.retval = zero;
  797. if (_LIB_VERSION == _POSIX_)
  798. __set_errno (ERANGE);
  799. else if (!matherr(&exc)) {
  800. if (_LIB_VERSION == _SVID_) {
  801. (void) WRITE2(exc.name, 2);
  802. (void) WRITE2(": TLOSS error\n", 14);
  803. }
  804. __set_errno (ERANGE);
  805. }
  806. break;
  807. case 40:
  808. case 140:
  809. case 240:
  810. /* tgamma(finite) overflow */
  811. exc.type = OVERFLOW;
  812. exc.name = CSTR ("tgamma");
  813. exc.retval = copysign (HUGE_VAL, x);
  814. if (_LIB_VERSION == _POSIX_)
  815. __set_errno (ERANGE);
  816. else if (!matherr(&exc)) {
  817. __set_errno (ERANGE);
  818. }
  819. break;
  820. case 41:
  821. case 141:
  822. case 241:
  823. /* tgamma(-integer) */
  824. exc.type = SING;
  825. exc.name = CSTR ("tgamma");
  826. exc.retval = NAN;
  827. if (_LIB_VERSION == _POSIX_)
  828. __set_errno (EDOM);
  829. else if (!matherr(&exc)) {
  830. if (_LIB_VERSION == _SVID_) {
  831. (void) WRITE2("tgamma: SING error\n", 18);
  832. exc.retval = HUGE_VAL;
  833. }
  834. __set_errno (EDOM);
  835. }
  836. break;
  837. case 42:
  838. case 142:
  839. case 242:
  840. /* pow(NaN,0.0) */
  841. /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
  842. exc.type = DOMAIN;
  843. exc.name = CSTR ("pow");
  844. exc.retval = x;
  845. if (_LIB_VERSION == _IEEE_ ||
  846. _LIB_VERSION == _POSIX_) exc.retval = 1.0;
  847. else if (!matherr(&exc)) {
  848. __set_errno (EDOM);
  849. }
  850. break;
  851. case 44:
  852. case 144:
  853. case 244:
  854. /* exp(finite) overflow */
  855. exc.type = OVERFLOW;
  856. exc.name = CSTR ("exp2");
  857. if (_LIB_VERSION == _SVID_)
  858. exc.retval = HUGE;
  859. else
  860. exc.retval = HUGE_VAL;
  861. if (_LIB_VERSION == _POSIX_)
  862. __set_errno (ERANGE);
  863. else if (!matherr(&exc)) {
  864. __set_errno (ERANGE);
  865. }
  866. break;
  867. case 45:
  868. case 145:
  869. case 245:
  870. /* exp(finite) underflow */
  871. exc.type = UNDERFLOW;
  872. exc.name = CSTR ("exp2");
  873. exc.retval = zero;
  874. if (_LIB_VERSION == _POSIX_)
  875. __set_errno (ERANGE);
  876. else if (!matherr(&exc)) {
  877. __set_errno (ERANGE);
  878. }
  879. break;
  880. case 46:
  881. case 146:
  882. case 246:
  883. /* exp(finite) overflow */
  884. exc.type = OVERFLOW;
  885. exc.name = CSTR ("exp10");
  886. if (_LIB_VERSION == _SVID_)
  887. exc.retval = HUGE;
  888. else
  889. exc.retval = HUGE_VAL;
  890. if (_LIB_VERSION == _POSIX_)
  891. __set_errno (ERANGE);
  892. else if (!matherr(&exc)) {
  893. __set_errno (ERANGE);
  894. }
  895. break;
  896. case 47:
  897. case 147:
  898. case 247:
  899. /* exp(finite) underflow */
  900. exc.type = UNDERFLOW;
  901. exc.name = CSTR ("exp10");
  902. exc.retval = zero;
  903. if (_LIB_VERSION == _POSIX_)
  904. __set_errno (ERANGE);
  905. else if (!matherr(&exc)) {
  906. __set_errno (ERANGE);
  907. }
  908. break;
  909. case 48:
  910. case 148:
  911. case 248:
  912. /* log2(0) */
  913. exc.type = SING;
  914. exc.name = CSTR ("log2");
  915. if (_LIB_VERSION == _SVID_)
  916. exc.retval = -HUGE;
  917. else
  918. exc.retval = -HUGE_VAL;
  919. if (_LIB_VERSION == _POSIX_)
  920. __set_errno (ERANGE);
  921. else if (!matherr(&exc)) {
  922. __set_errno (EDOM);
  923. }
  924. break;
  925. case 49:
  926. case 149:
  927. case 249:
  928. /* log2(x<0) */
  929. exc.type = DOMAIN;
  930. exc.name = CSTR ("log2");
  931. if (_LIB_VERSION == _SVID_)
  932. exc.retval = -HUGE;
  933. else
  934. exc.retval = NAN;
  935. if (_LIB_VERSION == _POSIX_)
  936. __set_errno (EDOM);
  937. else if (!matherr(&exc)) {
  938. __set_errno (EDOM);
  939. }
  940. break;
  941. case 50:
  942. case 150:
  943. case 250:
  944. /* tgamma(+-0) */
  945. exc.type = SING;
  946. exc.name = CSTR ("tgamma");
  947. exc.retval = copysign (HUGE_VAL, x);
  948. if (_LIB_VERSION == _POSIX_)
  949. __set_errno (ERANGE);
  950. else if (!matherr(&exc)) {
  951. if (_LIB_VERSION == _SVID_)
  952. (void) WRITE2("tgamma: SING error\n", 18);
  953. __set_errno (ERANGE);
  954. }
  955. break;
  956. /* #### Last used is 50/150/250 ### */
  957. }
  958. return exc.retval;
  959. }