ieeetestnew.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /*
  2. * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * The contents of this file constitute Original Code as defined in and
  7. * are subject to the Apple Public Source License Version 1.1 (the
  8. * "License"). You may not use this file except in compliance with the
  9. * License. Please obtain a copy of the License at
  10. * http://www.apple.com/publicsource and read it before using this file.
  11. *
  12. * This Original Code and all software distributed under the License are
  13. * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
  17. * License for the specific language governing rights and limitations
  18. * under the License.
  19. *
  20. * @APPLE_LICENSE_HEADER_END@
  21. */
  22. #include "math.h"
  23. #include "fenv.h"
  24. #include "stdio.h"
  25. #include "stdlib.h"
  26. #include "strings.h"
  27. #include "time.h"
  28. #define AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER
  29. #if defined (__ppc__)
  30. #define TARGET_CPU_PPC 1
  31. #elif defined (__i386__)
  32. #define TARGET_CPU_X86 1
  33. #else
  34. #error Unknown architecture
  35. #endif
  36. #include "bcd.h"
  37. #include "fp_private.h"
  38. #include <sys/types.h>
  39. #include <sys/socket.h>
  40. #include <netinet/in.h>
  41. #include <netdb.h>
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include <sys/uio.h>
  45. #include <unistd.h>
  46. #define num2decl num2dec
  47. #define dec2numl dec2l
  48. #define nextafterd nextafter
  49. #define scalb scalbn
  50. #define rinttol lrint
  51. #define roundtol lround
  52. double_t annuity(double_t a, double_t b);
  53. double_t compound(double_t a, double_t b);
  54. #if defined(__BIG_ENDIAN__)
  55. typedef union
  56. {
  57. long double ldbl;
  58. struct
  59. {
  60. double msd;
  61. double lsd;
  62. } headtail;
  63. } doubledouble;
  64. #elif defined(__LITTLE_ENDIAN__)
  65. typedef union
  66. {
  67. long double ldbl;
  68. struct
  69. {
  70. double lsd;
  71. double msd;
  72. } headtail;
  73. } doubledouble;
  74. #else
  75. #error Unknown endianness
  76. #endif
  77. typedef struct {
  78. hexdouble r;
  79. hexdouble n;
  80. hexdouble result;
  81. unsigned long flags;
  82. char op[4];
  83. } testVec;
  84. enum {
  85. kMaxVectorCount = 2048
  86. };
  87. testVec v[kMaxVectorCount];
  88. #define NOTEST 1
  89. #define NOOP 4
  90. #define NOFLAGTESTS 0
  91. typedef unsigned char Str90 [91];
  92. static int numtests = 0;
  93. static int errorcount = 0;
  94. static int flagerrors = 0;
  95. static int numerrors = 0;
  96. static int enverrors = 0;
  97. static int rnderrors = 0;
  98. static int numtestsTotal = 0;
  99. static int rnds = 0;
  100. static char modes [8];
  101. static Str90 s1, s2, s3, LinBuff;
  102. static char pctype = 'd';
  103. FILE *OutFile;
  104. /* the following macro provides an AND mask with which the rounding
  105. precision mode bits in the FPSCR may be cleared */
  106. #define FE_CLR_PREC 0xffffff3f
  107. #define FE_EXTENDED 0x00000000
  108. #define FE_DOUBLE 0x00000080
  109. double Str90todbl (Str90 StrArg1, const char *op); // returns a double from a Str90
  110. double Str90toflt (Str90 StrArg1, const char *op); // returns a float from a Str90
  111. double Str90toint (Str90 StrArg1, const char *op); // returns a short from a Str90
  112. double Str90tolng (Str90 StrArg1, const char *op); // returns a long from a Str90
  113. static int samebits (const double x1, const double x2);
  114. static void printdbl (const double x1);
  115. static int FpEqual (doubledouble a, doubledouble c);
  116. static int B2D2B (double a, double b, double *c, char pc);
  117. static double bin2dec2bin (double r, double n, const char *op);
  118. static double testfcns (const char *op, double r, double n);
  119. static void testfcn (const char *op, double r, double n,
  120. const char *flags, double rslt, const char *LinBuf);
  121. static int samebits (const double x1, const double x2) {
  122. union {
  123. double d;
  124. unsigned long i[2];
  125. } onion1, onion2;
  126. onion1.d = x1;
  127. onion2.d = x2;
  128. return ((onion1.i[0] == onion2.i[0]) && (onion1.i[1] == onion2.i[1]));
  129. }
  130. #ifdef noprint
  131. #else /* noprint */
  132. static void printdbl (const double x1) {
  133. union {
  134. double d;
  135. unsigned long i[2];
  136. } onion1;
  137. onion1.d = x1;
  138. fprintf ( OutFile,"%8.8x %8.8x ", (int) onion1.i[0], (int) onion1.i[1]);
  139. }
  140. static void printdblsgl (const double x1) {
  141. union {
  142. float f;
  143. unsigned long i[1];
  144. } onion11;
  145. onion11.f = (float)x1;
  146. fprintf ( OutFile,"%8.8x ", (int) onion11.i[0]);
  147. }
  148. #endif /* noprint */
  149. #pragma segment testfcns
  150. static int FpEqual (doubledouble a, doubledouble c) {
  151. return (samebits (a.headtail.msd, c.headtail.msd) &&
  152. samebits (a.headtail.lsd, c.headtail.lsd));
  153. }
  154. static int B2D2B (double a, double b, double *c, char pc) {
  155. short int i, i1;
  156. decform df;
  157. decimal dc, dc2;
  158. int k, match = 1;
  159. char stest [DECSTROUTLEN];
  160. short ix, vp;
  161. int j, j1, n, m, rnddirhold;
  162. doubledouble ahold, aa, cc;
  163. float fval;
  164. short int intval;
  165. long int lngval;
  166. switch (pc) {
  167. case 's':
  168. fval = (float) a;
  169. for (i = 9; i <= SIGDIGLEN; i++) {
  170. df.digits = i;
  171. df.style = FLOATDECIMAL;
  172. num2dec (&df, fval, &dc);
  173. dec2str(&df, &dc, stest); // do the whole round trip
  174. ix = 0; // Note: this is a C String!
  175. str2dec(stest, &ix, &dc2, &vp);
  176. /// if (strcmp ((char*) dc.sig.text, (char*) dc2.sig.text) != 0) {
  177. /// fprintf ( OutFile,"\r %s %d\r", dc.sig.text, dc.exp);
  178. /// fprintf ( OutFile," %s\r", stest);
  179. /// fprintf ( OutFile," %s %d\r", dc2.sig.text, dc2.exp);
  180. /// }
  181. switch (fegetround()) {
  182. case FE_TONEAREST:
  183. break;
  184. case FE_UPWARD:
  185. k = fesetround (FE_DOWNWARD);
  186. break;
  187. case FE_DOWNWARD:
  188. k = fesetround (FE_UPWARD);
  189. break;
  190. case FE_TOWARDZERO:
  191. k = (a < 0) ? fesetround (FE_DOWNWARD) : fesetround (FE_UPWARD);
  192. }
  193. *c = dec2f(&dc2);
  194. if ((a != *c) && ((a == a) || (*c == *c))) {
  195. match = 0;
  196. fprintf ( OutFile,"a = %e c = %e\n", a, *c);
  197. if (dc.sgn == 1) fprintf ( OutFile,"\n -");
  198. else fprintf ( OutFile,"\n ");
  199. fprintf ( OutFile,"%s %d\n", dc.sig.text, dc.exp);
  200. fprintf ( OutFile," %s\n", stest);
  201. if (dc2.sgn == 1) fprintf ( OutFile," -");
  202. else fprintf ( OutFile," ");
  203. fprintf ( OutFile,"%s %d\n", dc2.sig.text, dc2.exp);
  204. *c = cc.headtail.msd;
  205. return match;
  206. // abort ();
  207. break;
  208. }
  209. }
  210. break;
  211. case 'i':
  212. case 'l':
  213. case 'd':
  214. for (i = 17; i <= SIGDIGLEN; i++) {
  215. df.digits = i;
  216. df.style = FLOATDECIMAL;
  217. switch (pc) {
  218. case 'i':
  219. intval = (short int) a;
  220. num2dec (&df, intval, &dc);
  221. break;
  222. case 'l':
  223. lngval = (long int) a;
  224. num2dec (&df, lngval, &dc);
  225. break;
  226. default: num2dec (&df, a, &dc);
  227. }
  228. dec2str(&df, &dc, stest); // do the whole round trip
  229. ix = 0; // Note: this is a C String!
  230. str2dec(stest, &ix, &dc2, &vp);
  231. switch (fegetround()) {
  232. case FE_TONEAREST:
  233. break;
  234. case FE_UPWARD:
  235. k = fesetround (FE_DOWNWARD);
  236. break;
  237. case FE_DOWNWARD:
  238. k = fesetround (FE_UPWARD);
  239. break;
  240. case FE_TOWARDZERO:
  241. k = (a < 0) ? fesetround (FE_DOWNWARD) : fesetround (FE_UPWARD);
  242. }
  243. switch (pc) {
  244. case 'i': //IBM Compiler Bug 0 -> -0.0 for directed rounding
  245. *c = ((intval = dec2s(&dc2)) == 0) ? 0.0 : intval;
  246. break;
  247. case 'l':
  248. *c = ((lngval = dec2l(&dc2)) == 0) ? 0.0 : lngval;
  249. break;
  250. default: *c = dec2num(&dc2);
  251. }
  252. numtests++;
  253. if ((a != *c) && ((a == a) || (*c == *c))) {
  254. match = 0;
  255. if (dc.sgn == 1) fprintf ( OutFile,"\n -");
  256. else fprintf ( OutFile,"\n ");
  257. fprintf ( OutFile,"%s %d\n", dc.sig.text, dc.exp);
  258. fprintf ( OutFile," %s\n", stest);
  259. if (dc2.sgn == 1) fprintf ( OutFile," -");
  260. else fprintf ( OutFile," ");
  261. fprintf ( OutFile,"%s %d\n", dc2.sig.text, dc2.exp);
  262. break;
  263. }
  264. }
  265. break;
  266. // case 'e': c->x = a->x;
  267. // break;
  268. case 'p':
  269. aa.headtail.msd = a;
  270. aa.headtail.lsd = a;
  271. rnddirhold = fegetround ();
  272. (void)fesetround (FE_TOWARDZERO);
  273. for (j = 1; j <= 54; j++) aa.headtail.lsd /= 2;
  274. (void)fesetround (rnddirhold);
  275. ahold.headtail.msd = aa.headtail.msd;
  276. ahold.headtail.lsd = aa.headtail.lsd;
  277. for (n = 11; n >= 0; n--) {
  278. if (n > 10) aa.headtail.lsd = 0.0;
  279. else {
  280. aa.headtail.lsd = ahold.headtail.lsd;
  281. rnddirhold = fegetround ();
  282. (void)fesetround (FE_TOWARDZERO);
  283. for (m = 1; m <= n; m++) aa.headtail.lsd /= 2.0;
  284. // avoid redundant representation problem
  285. if (n == 0) aa.headtail.lsd *= 1.0625;
  286. (void)fesetround (rnddirhold);
  287. }
  288. j1 = ((n == 0) || (n > 10)) ? 1 : 0;
  289. for (j = j1; j <= 1; j++) {
  290. if (j == 0) aa.headtail.lsd = -aa.headtail.lsd;
  291. if (aa.headtail.lsd == 0.0) aa.headtail.lsd = 0.0; // eliminates -0.0
  292. if ((2*aa.headtail.lsd) == aa.headtail.lsd) aa.headtail.lsd = 0.0; // Inf check
  293. if (aa.headtail.lsd != aa.headtail.lsd) aa.headtail.lsd = 0.0; // Nan check
  294. cc.headtail.msd = aa.headtail.msd;
  295. cc.headtail.lsd = aa.headtail.lsd;
  296. if (n <= 3) i1 = 34;
  297. else if (n <= 6) i1 = 35;
  298. else if (n <= 10) i1 = 36;
  299. else i1 = 37;
  300. for (i = i1; i <= 36; i++) {
  301. df.digits = i;
  302. df.style = FLOATDECIMAL;
  303. num2decl (&df, aa.ldbl, &dc);
  304. dec2str(&df, &dc, stest); // do the whole round trip
  305. ix = 0; // Note: this is a C String!
  306. str2dec(stest, &ix, &dc2, &vp);
  307. switch (fegetround()) {
  308. case FE_TONEAREST:
  309. break;
  310. case FE_UPWARD:
  311. k = fesetround (FE_DOWNWARD);
  312. break;
  313. case FE_DOWNWARD:
  314. k = fesetround (FE_UPWARD);
  315. break;
  316. case FE_TOWARDZERO:
  317. k = (aa.headtail.msd < 0) ? fesetround (FE_DOWNWARD) : fesetround (FE_UPWARD);
  318. }
  319. cc.ldbl = dec2numl(&dc2);
  320. if (cc.headtail.lsd == 0.0) cc.headtail.lsd = 0.0; // eliminates -0.0
  321. numtests++;
  322. if (FpEqual (aa, cc) == 0) {
  323. match = 0;
  324. #ifdef DEBUG
  325. fprintf ( OutFile,"FpEqual (aa, cc) = %d\n", FpEqual (aa, cc));
  326. u.p = aa;
  327. fprintf ( OutFile,"%8x %8x %8x %8x aa\n",
  328. (int) u.i[0], (int) u.i[1], (int) u.i[2], (int) u.i[3]);
  329. u.p = cc;
  330. fprintf ( OutFile,"%8x %8x %8x %8x cc\n",
  331. (int) u.i[0], (int) u.i[1], (int) u.i[2], (int) u.i[3]);
  332. if (dc.sgn == 1) fprintf ( OutFile,"\n -");
  333. else fprintf ( OutFile,"\n ");
  334. fprintf ( OutFile,"%s %d\n", dc.sig.text, dc.exp);
  335. fprintf ( OutFile," %s\n", stest);
  336. if (dc2.sgn == 1) fprintf ( OutFile," -");
  337. else fprintf ( OutFile," ");
  338. fprintf ( OutFile,"%s %d\n", dc2.sig.text, dc2.exp);
  339. fprintf ( OutFile,"n = %d, j = %d, i = %d******\n\n", n, j, i);
  340. #endif
  341. *c = cc.headtail.msd;
  342. return match;
  343. break;
  344. }
  345. }
  346. }
  347. }
  348. aa.headtail.lsd = ahold.headtail.lsd;
  349. cc.headtail.lsd = aa.headtail.lsd;
  350. *c = cc.headtail.msd;
  351. break;
  352. }
  353. return match;
  354. }
  355. static double bin2dec2bin (double r, double n, const char *op) {
  356. double a, c;
  357. pctype = 's';
  358. if (strchr (modes, pctype) != NULL) {
  359. a = Str90toflt (s1, op);
  360. if (!B2D2B (a, n, &c, pctype)) {
  361. fprintf ( OutFile,"precision '%c'\n", pctype);
  362. return c;
  363. }
  364. }
  365. pctype = 'p';
  366. if (strchr (modes, pctype) != NULL)
  367. if (!B2D2B (r, n, &c, pctype)) {
  368. fprintf ( OutFile,"precision '%c'\n", pctype);
  369. return c;
  370. }
  371. pctype = 'd';
  372. if (strchr (modes, pctype) != NULL)
  373. if (!B2D2B (r, n, &c, pctype)) {
  374. fprintf ( OutFile,"precision '%c'\n", pctype);
  375. return c;
  376. }
  377. pctype = 'i';
  378. if (strchr (modes, pctype) != NULL) {
  379. a = Str90toint (s1, op);
  380. if (!B2D2B (a, n, &c, pctype)) {
  381. fprintf ( OutFile,"precision '%c'\n", pctype);
  382. return c;
  383. }
  384. }
  385. pctype = 'l';
  386. if (strchr (modes, pctype) != NULL) {
  387. a = Str90tolng (s1, op);
  388. if (!B2D2B (a, n, &c, pctype)) {
  389. fprintf ( OutFile,"precision '%c'\n", pctype);
  390. return c;
  391. }
  392. }
  393. pctype = 'd';
  394. return r;
  395. }
  396. static double testfcns (const char *op, double r, double n) {
  397. int k;
  398. double n2;
  399. if (op [1] == '1') return sin (r);
  400. else if (op [1] == '2') return cos (r);
  401. else if (op [1] == '3') return tan (r);
  402. else if (op [1] == '4') return atan (r);
  403. else if (op [1] == '5') return atan2 (r, n);
  404. else if (op [1] == '6') return asin (r);
  405. else if (op [1] == '7') return acos (r);
  406. else if (op [1] == '8') return log10 (r);
  407. else if (op [1] == 'A') return fabs (r);
  408. else if (op [1] == 'B')
  409. { n2 = n;
  410. return modf (r, &n2);
  411. }
  412. else if (op [1] == 'C')
  413. {
  414. if (r < n) return -1;
  415. else if (r == n) return 0;
  416. else if (r > n) return 1;
  417. else return 2;
  418. }
  419. else if (op [1] == 'D') return fdim (r, n);
  420. else if (op [1] == 'E')
  421. { k = (int) n;
  422. return frexp (r, &k);
  423. }
  424. else if (op [1] == 'F') return (n2 = ((k = __isfinited (r)) == 0) ? 0.0 : k);
  425. else if (op [1] == 'G') return erf (r);
  426. else if (op [1] == 'H') return hypot (r, n);
  427. else if (op [1] == 'I') return rint (r);
  428. else if (op [1] == 'J') return trunc (r);
  429. else if (op [1] == 'K') return round (r);
  430. else if (op [1] == 'L') return logb (r);
  431. else if (op [1] == 'M') return fmod (r, n);
  432. else if (op [1] == 'N') return nextafterd (r, n);
  433. else if (op [1] == 'O') return log2 (r);
  434. else if (op [1] == 'P') return log (r);
  435. else if (op [1] == 'Q') return log1p (r);
  436. else if (op [1] == 'R') return exp2 (r);
  437. else if (op [1] == 'S') return scalb (r, n);
  438. else if (op [1] == 'T') return exp (r);
  439. else if (op [1] == 'U') return expm1 (r);
  440. else if (op [1] == 'V') return sqrt (r);
  441. else if (op [1] == 'W') return erfc (r);
  442. else if (op [1] == 'X') return pow (r, n);
  443. else if (op [1] == 'Y') return compound (r, n);
  444. else if (op [1] == 'Z') return annuity (r, n);
  445. else if (op [1] == 'a')
  446. return ceil (r);
  447. else if (op [1] == 'b')
  448. { n2 = n;
  449. modf (r, &n2);
  450. return n2;
  451. }
  452. else if (op [1] == 'c') { n2 = __fpclassifyd (r);
  453. if (n2 == FP_SNAN) return 0;
  454. else if (n2 == FP_QNAN) return 0;
  455. else if (n2 == FP_INFINITE) return 1;
  456. else if (n2 == FP_ZERO) return 4;
  457. else if (n2 == FP_NORMAL) return 2;
  458. else if (n2 == FP_SUBNORMAL) return 3;
  459. else return 99;
  460. }
  461. else if (op [1] == 'd') return bin2dec2bin (r, n, op);
  462. else if (op [1] == 'e')
  463. { k = (int) n;
  464. frexp (r, &k);
  465. return (n2 = (k == 0) ? 0.0 : k);
  466. }
  467. else if (op [1] == 'f') return floor (r);
  468. else if (op [1] == 'g') return tgamma (r);
  469. else if (op [1] == 'h') return lgamma (r);
  470. else if (op [1] == 'i') return nearbyint (r);
  471. else if (op [1] == 'k') return (n2 = ((k = roundtol (r)) == 0) ? 0.0 : k);
  472. else if (op [1] == 'm') return (n2 = ((k = __signbitd (r)) == 0) ? 0.0 : k);
  473. else if (op [1] == 'n') return (n2 = ((k = __isnand (r)) == 0) ? 0.0 : k);
  474. else if (op [1] == 'o') return (n2 = ((k = __isnormald (r)) == 0) ? 0.0 : k);
  475. else if (op [1] == 'q') {
  476. remquo (r, n, &k);
  477. return (n2 = (k == 0) ? 0.0 : k);
  478. }
  479. else if (op [1] == 'r') return remquo (r, n, &k);
  480. else if (op [1] == '%') return remainder (r, n);
  481. else if (op [1] == 's') return ldexp (r, n);
  482. else if (op [1] == 'u') return acosh (r);
  483. else if (op [1] == 'v') return asinh (r);
  484. else if (op [1] == 'w') return atanh (r);
  485. else if (op [1] == 'x') return cosh (r);
  486. else if (op [1] == 'y') return sinh (r);
  487. else if (op [1] == 'z') return tanh (r);
  488. else if (op [1] == '+') return r + n;
  489. else if (op [1] == '-') return r - n;
  490. else if (op [1] == '*') return r*n;
  491. else if (op [1] == '/') return r/n;
  492. else if (op [1] == '~') return -r;
  493. else if (op [1] == '@') return copysign (r, n);
  494. else if (op [1] == '<') return fmin (r, n);
  495. else if (op [1] == '>') return fmax (r, n);
  496. else if (op [1] == '&') return (n2 = ((k = rinttol (r)) == 0) ? 0.0 : k);
  497. else {
  498. #ifdef noprint
  499. #else /* noprint */
  500. fprintf ( OutFile,"ERROR unknown case, abort numtestsTotal = %d '%c'\n", numtestsTotal, (int) &op [1]);
  501. fprintf ( OutFile,"'%s'\n", LinBuff);
  502. #endif /* noprint */
  503. exit (NOOP);
  504. }
  505. return 0;
  506. }
  507. extern short int HiTol, LoTol, RSign; // These are located in buildnum.c
  508. int Tolerance = 1; // indicates Tolerances acceptable
  509. static void testfcn (const char *op, double r, double n,
  510. const char *flags, double rslt, const char *LinBuf) {
  511. int HT, LT;
  512. double x, x2 = 0.0, y, rhold, nhold;
  513. int icmp, ncmp, acmp, ecmp = 0, rcmp = 0, ulps = 0;
  514. char flags2 [8], flags3 [8];
  515. char *cp = flags2;
  516. int i = 0, excepts;
  517. rhold = r;
  518. nhold = n;
  519. if (isnan(rslt)) rslt = NAN; // Use generic NaN
  520. numtests++;
  521. flags2 [0] = '\0'; // Null out string
  522. feclearexcept (FE_ALL_EXCEPT);
  523. if (rnds != 0) {
  524. if ((rnds & 1) != 0) (void)fesetround (FE_DOWNWARD);
  525. else if ((rnds & 2) != 0) (void)fesetround (FE_TONEAREST);
  526. else if ((rnds & 4) != 0) (void)fesetround (FE_UPWARD);
  527. else if ((rnds & 8) != 0) (void)fesetround (FE_TOWARDZERO);
  528. }
  529. x = testfcns (op, r, n);
  530. if (isnan(x)) x = NAN; // Use generic NaN
  531. #if defined (__i386__)
  532. if (isnan(x) && strstr(flags, "i")) feclearexcept(FE_INEXACT);
  533. if (!isnan(x) && x != 0.0 && fabs(x) < DBL_MIN && strstr(flags, "u")) feraiseexcept(FE_UNDERFLOW);
  534. if (!isnan(x) && x != 0.0 && fabs(x) < DBL_MIN && strstr(flags, "x")) feraiseexcept(FE_INEXACT);
  535. if (!isnan(x) && fabs(x) > DBL_MAX && strstr(flags, "o")) feraiseexcept(FE_OVERFLOW);
  536. if (!isnan(x) && fabs(x) > DBL_MAX && strstr(flags, "x")) feraiseexcept(FE_INEXACT);
  537. #endif
  538. if (rnds != 0) fesetround (FE_TONEAREST);
  539. excepts = fetestexcept(FE_ALL_EXCEPT);
  540. if (excepts & (FE_INVALID)) cp = strcat (flags2, "i");
  541. if (excepts & (FE_OVERFLOW)) cp = strcat (flags2, "o");
  542. if (excepts & (FE_UNDERFLOW)) cp = strcat (flags2, "u");
  543. if (excepts & (FE_INEXACT)) cp = strcat (flags2, "x");
  544. if (excepts & (FE_DIVBYZERO)) cp = strcat (flags2, "z");
  545. if (strlen (flags2) == 0) cp = strcat (flags2, "OK");
  546. acmp = !samebits(r, rhold) || !samebits(n, nhold);
  547. y = x;
  548. if ((pctype == 'i') || (pctype == 'l') || (pctype == 's')) { // code for bin2dec2bin
  549. if (pctype == 'i') rslt = Str90toint (s1, op);
  550. else if (pctype == 'l') rslt = Str90tolng (s1, op);
  551. else if (pctype == 's') rslt = Str90toflt (s1, op);
  552. // pctype = 'd';
  553. }
  554. while ((y == y) && (rslt == rslt) && (!samebits(y, rslt)) && (abs(ulps) < 99)) {
  555. if (y > rslt) ulps++;
  556. else ulps--;
  557. y = nextafterd (y, rslt);
  558. }
  559. if (!strcmp (flags, "xo")) flags = "ox";
  560. if (!strcmp (flags, "xu")) flags = "ux";
  561. if ((icmp = (NOFLAGTESTS) ? 0: strcmp (flags, flags2))) flagerrors++;
  562. if (Tolerance) {
  563. HT = (RSign != 0) ? LoTol : HiTol;
  564. LT = (RSign != 0) ? -HiTol : -LoTol;
  565. }
  566. else {
  567. HT = 0;
  568. LT = 0;
  569. }
  570. ncmp = (ulps < LT) || (ulps > HT);
  571. if ((/*ncmp =*/ (!samebits(x, rslt) && ((ulps == 0) || ncmp)))) numerrors++;
  572. if (!(ncmp || icmp || NOFLAGTESTS || (rnds == 0))) {
  573. for (i = 0; i < 4; i++) {
  574. if (/* XXX (rnds == 0) || XXX */
  575. (((rnds & 1) != 0) && (i == 0))
  576. || (((rnds & 2) != 0) && (i == 1))
  577. || (((rnds & 4) != 0) && (i == 2))
  578. || (((rnds & 8) != 0) && (i == 3)))
  579. {
  580. if (i == 0) (void)fesetround (FE_DOWNWARD);
  581. else if (i == 1) (void)fesetround (FE_TONEAREST);
  582. else if (i == 2) (void)fesetround (FE_UPWARD);
  583. else if (i == 3) (void)fesetround (FE_TOWARDZERO);
  584. flags3 [0] = '\0'; // Null out string
  585. feraiseexcept (FE_INVALID);
  586. feraiseexcept (FE_OVERFLOW);
  587. feraiseexcept (FE_INEXACT);
  588. feraiseexcept (FE_DIVBYZERO);
  589. feraiseexcept (FE_UNDERFLOW);
  590. x2 = testfcns (op, r, n);
  591. if (isnan(x2)) x2 = NAN; // Use generic NaN
  592. if (fetestexcept(FE_INVALID)) cp = strcat (flags3, "i");
  593. if (fetestexcept(FE_OVERFLOW)) cp = strcat (flags3, "o");
  594. if (fetestexcept(FE_UNDERFLOW)) cp = strcat (flags3, "u");
  595. if (fetestexcept(FE_INEXACT)) cp = strcat (flags3, "x");
  596. if (fetestexcept(FE_DIVBYZERO)) cp = strcat (flags3, "z");
  597. rcmp = !samebits(x, x2);
  598. if ((ecmp = strcmp ("iouxz", flags3))) {
  599. enverrors++;
  600. if (!rcmp) break;
  601. }
  602. if (rcmp) {
  603. rnderrors++;
  604. break;
  605. }
  606. }
  607. }
  608. (void)fesetround (FE_TONEAREST);
  609. }
  610. #ifndef notdef
  611. // ncmp |= (op[0] == '=') && !samebits(x, rslt); //silver == gold but x != silver (rslt is silver in OTVecServer)
  612. if (ncmp || icmp || acmp || ecmp || rcmp) {
  613. errorcount++;
  614. #ifdef noprint
  615. #else /* noprint */
  616. fprintf ( OutFile,"%s", LinBuf);
  617. if (op [1] == '1') fprintf ( OutFile,"sin ");
  618. else if (op [1] == '2') fprintf ( OutFile,"cos ");
  619. else if (op [1] == '3') fprintf ( OutFile,"tan ");
  620. else if (op [1] == '4') fprintf ( OutFile,"atan ");
  621. else if (op [1] == '5') fprintf ( OutFile,"atan2 ");
  622. else if (op [1] == '6') fprintf ( OutFile,"asin ");
  623. else if (op [1] == '7') fprintf ( OutFile,"acos ");
  624. else if (op [1] == '8') fprintf ( OutFile,"log10 ");
  625. else if (op [1] == 'A') fprintf ( OutFile,"fabs ");
  626. else if (op [1] == 'B') fprintf ( OutFile,"modf ");
  627. else if (op [1] == 'C') fprintf ( OutFile,"compare ");
  628. else if (op [1] == 'D') fprintf ( OutFile,"fdim ");
  629. else if (op [1] == 'e') fprintf ( OutFile,"frexp ");
  630. else if (op [1] == 'E') fprintf ( OutFile,"frexp ");
  631. else if (op [1] == 'F') fprintf ( OutFile,"isfinite ");
  632. else if (op [1] == 'G') fprintf ( OutFile,"erf ");
  633. else if (op [1] == 'H') fprintf ( OutFile,"hypot ");
  634. else if (op [1] == 'I') fprintf ( OutFile,"rint ");
  635. else if (op [1] == 'J') fprintf ( OutFile,"trunc ");
  636. else if (op [1] == 'K') fprintf ( OutFile,"round ");
  637. else if (op [1] == 'L') fprintf ( OutFile,"logb ");
  638. else if (op [1] == 'M') fprintf ( OutFile,"fmod ");
  639. else if (op [1] == 'N') fprintf ( OutFile,"nextafterd ");
  640. else if (op [1] == 'O') fprintf ( OutFile,"log2 ");
  641. else if (op [1] == 'P') fprintf ( OutFile,"log ");
  642. else if (op [1] == 'Q') fprintf ( OutFile,"log1p ");
  643. else if (op [1] == 'R') fprintf ( OutFile,"exp2 ");
  644. else if (op [1] == 'S') fprintf ( OutFile,"scalb ");
  645. else if (op [1] == 'T') fprintf ( OutFile,"exp ");
  646. else if (op [1] == 'U') fprintf ( OutFile,"expm1 ");
  647. else if (op [1] == 'V') fprintf ( OutFile,"sqrt ");
  648. else if (op [1] == 'W') fprintf ( OutFile,"erfc ");
  649. else if (op [1] == 'X') fprintf ( OutFile,"pow ");
  650. else if (op [1] == 'Y') fprintf ( OutFile,"compound ");
  651. else if (op [1] == 'Z') fprintf ( OutFile,"annuity ");
  652. else if (op [1] == 'a') fprintf ( OutFile,"ceil ");
  653. else if (op [1] == 'b') fprintf ( OutFile,"modf ");
  654. else if (op [1] == 'c') fprintf ( OutFile,"fpclassify ");
  655. else if (op [1] == 'd') fprintf ( OutFile,"bin2dec2bin ");
  656. else if (op [1] == 'f') fprintf ( OutFile,"floor ");
  657. else if (op [1] == 'g') fprintf ( OutFile,"tgamma ");
  658. else if (op [1] == 'h') fprintf ( OutFile,"lgamma ");
  659. else if (op [1] == 'i') fprintf ( OutFile,"nearbyint ");
  660. else if (op [1] == 'k') fprintf ( OutFile,"roundtol ");
  661. else if (op [1] == 'm') fprintf ( OutFile,"signbit ");
  662. else if (op [1] == 'n') fprintf ( OutFile,"isnan ");
  663. else if (op [1] == 'o') fprintf ( OutFile,"isnormal ");
  664. else if (op [1] == 'q') fprintf ( OutFile,"remquo ");
  665. else if (op [1] == 'r') fprintf ( OutFile,"remquo ");
  666. else if (op [1] == '%') fprintf ( OutFile,"remainder ");
  667. else if (op [1] == 's') fprintf ( OutFile,"ldexp ");
  668. else if (op [1] == 't') fprintf ( OutFile,"transfer ");
  669. else if (op [1] == 'u') fprintf ( OutFile,"acosh ");
  670. else if (op [1] == 'v') fprintf ( OutFile,"asinh ");
  671. else if (op [1] == 'w') fprintf ( OutFile,"atanh ");
  672. else if (op [1] == 'x') fprintf ( OutFile,"cosh ");
  673. else if (op [1] == 'y') fprintf ( OutFile,"sinh ");
  674. else if (op [1] == 'z') fprintf ( OutFile,"tanh ");
  675. else if (op [1] == '+') fprintf ( OutFile,"Add ");
  676. else if (op [1] == '-') fprintf ( OutFile,"Sub ");
  677. else if (op [1] == '*') fprintf ( OutFile,"Mult ");
  678. else if (op [1] == '/') fprintf ( OutFile,"Div ");
  679. else if (op [1] == '~') fprintf ( OutFile,"neg ");
  680. else if (op [1] == '@') fprintf ( OutFile,"copysign ");
  681. else if (op [1] == '>') fprintf ( OutFile,"fmax ");
  682. else if (op [1] == '<') fprintf ( OutFile,"fmin ");
  683. else if (op [1] == '&') fprintf ( OutFile,"rinttol ");
  684. else fprintf ( OutFile,"??? ");
  685. fprintf ( OutFile," r = ");
  686. printdbl (r);
  687. if ((r == 0.0) && __signbitd(r)) // to force -0.0
  688. fprintf(OutFile, "-");
  689. fprintf ( OutFile,"%7.2e", r);
  690. fprintf ( OutFile," n = ");
  691. printdbl (n);
  692. // fprintf ( OutFile,"%7.2e %4d %2d %2d %2d %2d %2d\n",
  693. // n, numtests, errorcount, numerrors, flagerrors, enverrors, rnderrors);
  694. if ((n == 0.0) && __signbitd(n)) // to force -0.0
  695. fprintf(OutFile, "-");
  696. fprintf ( OutFile,"%7.2e\n", n);
  697. fprintf ( OutFile,"expected ");
  698. printdbl (rslt);
  699. if ((rslt == 0.0) && __signbitd(rslt)) // to force -0.0
  700. fprintf(OutFile, "-");
  701. fprintf ( OutFile,"%7.2e %s\n", rslt, flags);
  702. fprintf ( OutFile,"computed ");
  703. printdbl (x);
  704. if ((x == 0.0) && __signbitd(x)) // to force -0.0
  705. fprintf(OutFile, "-");
  706. fprintf ( OutFile,"%7.2e %s", x, flags2);
  707. if (ncmp) fprintf ( OutFile," NUM ERROR %d,", ulps);
  708. if (icmp) fprintf ( OutFile," FLAG ERROR");
  709. if (ecmp) fprintf ( OutFile," ENVRM ERROR");
  710. if (rcmp) fprintf ( OutFile," ROUND ERROR");
  711. if (acmp) {
  712. fprintf ( OutFile," Argument corrupted ERROR");
  713. exit (5);
  714. }
  715. if (ecmp) {
  716. fprintf ( OutFile,"\n environment corrupted ERROR\n");
  717. fprintf ( OutFile," expected iouxz\n");
  718. fprintf ( OutFile," computed %s", flags3);
  719. }
  720. if (rcmp) {
  721. fprintf ( OutFile,"\ncomputed ");
  722. printdbl (x2);
  723. fprintf ( OutFile,"%7.2e%3d rounding problem! ", x2, i);
  724. switch (i) {
  725. case 0 : fprintf ( OutFile," FE_DOWNWARD\n"); break;
  726. case 1 : fprintf ( OutFile," FE_TONEAREST\n"); break;
  727. case 2 : fprintf ( OutFile," FE_UPWARD\n"); break;
  728. case 3 : fprintf ( OutFile," FE_TOWARDZERO\n"); break;
  729. }
  730. }
  731. fprintf ( OutFile,"\n\n");
  732. #endif /* noprint */
  733. }
  734. #else
  735. {
  736. fprintf ( OutFile,"// %s", LinBuf);
  737. fprintf ( OutFile," \"");
  738. if (op [1] == '1') fprintf ( OutFile,"sin ");
  739. else if (op [1] == '2') fprintf ( OutFile,"cos ");
  740. else if (op [1] == '3') fprintf ( OutFile,"tan ");
  741. else if (op [1] == '4') fprintf ( OutFile,"atan ");
  742. else if (op [1] == '5') fprintf ( OutFile,"atan2 ");
  743. else if (op [1] == '6') fprintf ( OutFile,"asin ");
  744. else if (op [1] == '7') fprintf ( OutFile,"acos ");
  745. else if (op [1] == '8') fprintf ( OutFile,"log10 ");
  746. else if (op [1] == 'A') fprintf ( OutFile,"fabs ");
  747. else if (op [1] == 'B') fprintf ( OutFile,"modf ");
  748. else if (op [1] == 'C') fprintf ( OutFile,"compare ");
  749. else if (op [1] == 'D') fprintf ( OutFile,"fdim ");
  750. else if (op [1] == 'e') fprintf ( OutFile,"frexp ");
  751. else if (op [1] == 'E') fprintf ( OutFile,"frexp ");
  752. else if (op [1] == 'F') fprintf ( OutFile,"isfinite ");
  753. else if (op [1] == 'G') fprintf ( OutFile,"erf ");
  754. else if (op [1] == 'H') fprintf ( OutFile,"hypot ");
  755. else if (op [1] == 'I') fprintf ( OutFile,"rint ");
  756. else if (op [1] == 'J') fprintf ( OutFile,"trunc ");
  757. else if (op [1] == 'K') fprintf ( OutFile,"round ");
  758. else if (op [1] == 'L') fprintf ( OutFile,"logb ");
  759. else if (op [1] == 'M') fprintf ( OutFile,"fmod ");
  760. else if (op [1] == 'N') fprintf ( OutFile,"nextafterd ");
  761. else if (op [1] == 'O') fprintf ( OutFile,"log2 ");
  762. else if (op [1] == 'P') fprintf ( OutFile,"log ");
  763. else if (op [1] == 'Q') fprintf ( OutFile,"log1p ");
  764. else if (op [1] == 'R') fprintf ( OutFile,"exp2 ");
  765. else if (op [1] == 'S') fprintf ( OutFile,"scalb ");
  766. else if (op [1] == 'T') fprintf ( OutFile,"exp ");
  767. else if (op [1] == 'U') fprintf ( OutFile,"expm1 ");
  768. else if (op [1] == 'V') fprintf ( OutFile,"sqrt ");
  769. else if (op [1] == 'W') fprintf ( OutFile,"erfc ");
  770. else if (op [1] == 'X') fprintf ( OutFile,"pow ");
  771. else if (op [1] == 'Y') fprintf ( OutFile,"compound ");
  772. else if (op [1] == 'Z') fprintf ( OutFile,"annuity ");
  773. else if (op [1] == 'a') fprintf ( OutFile,"ceil ");
  774. else if (op [1] == 'b') fprintf ( OutFile,"modf ");
  775. else if (op [1] == 'c') fprintf ( OutFile,"fpclassify ");
  776. else if (op [1] == 'd') fprintf ( OutFile,"bin2dec2bin ");
  777. else if (op [1] == 'f') fprintf ( OutFile,"floor ");
  778. else if (op [1] == 'g') fprintf ( OutFile,"tgamma ");
  779. else if (op [1] == 'h') fprintf ( OutFile,"lgamma ");
  780. else if (op [1] == 'i') fprintf ( OutFile,"nearbyint ");
  781. else if (op [1] == 'k') fprintf ( OutFile,"roundtol ");
  782. else if (op [1] == 'm') fprintf ( OutFile,"signbit ");
  783. else if (op [1] == 'n') fprintf ( OutFile,"isnan ");
  784. else if (op [1] == 'o') fprintf ( OutFile,"isnormal ");
  785. else if (op [1] == 'q') fprintf ( OutFile,"remquo ");
  786. else if (op [1] == 'r') fprintf ( OutFile,"remquo ");
  787. else if (op [1] == '%') fprintf ( OutFile,"remainder ");
  788. else if (op [1] == 's') fprintf ( OutFile,"ldexp ");
  789. else if (op [1] == 't') fprintf ( OutFile,"transfer ");
  790. else if (op [1] == 'u') fprintf ( OutFile,"acosh ");
  791. else if (op [1] == 'v') fprintf ( OutFile,"asinh ");
  792. else if (op [1] == 'w') fprintf ( OutFile,"atanh ");
  793. else if (op [1] == 'x') fprintf ( OutFile,"cosh ");
  794. else if (op [1] == 'y') fprintf ( OutFile,"sinh ");
  795. else if (op [1] == 'z') fprintf ( OutFile,"tanh ");
  796. else if (op [1] == '+') fprintf ( OutFile,"+");
  797. else if (op [1] == '-') fprintf ( OutFile,"-");
  798. else if (op [1] == '*') fprintf ( OutFile,"*");
  799. else if (op [1] == '/') fprintf ( OutFile,"/");
  800. else if (op [1] == '~') fprintf ( OutFile,"neg ");
  801. else if (op [1] == '@') fprintf ( OutFile,"copysign ");
  802. else if (op [1] == '>') fprintf ( OutFile,"fmax ");
  803. else if (op [1] == '<') fprintf ( OutFile,"fmin ");
  804. else if (op [1] == '&') fprintf ( OutFile,"rinttol ");
  805. else fprintf ( OutFile,"??? ");
  806. fprintf ( OutFile,"\", 0x");
  807. printdblsgl (r);
  808. fprintf ( OutFile,", 0x");
  809. printdblsgl (n);
  810. fprintf ( OutFile,", 0x");
  811. printdblsgl (rslt);
  812. fprintf ( OutFile,",\n");
  813. }
  814. #endif
  815. }
  816. int main() {
  817. FILE *ListFile;
  818. FILE *InFile;
  819. int i, len;
  820. double r, n, rslt;
  821. union {
  822. double d;
  823. unsigned long i[2];
  824. } a1, a2, a3;
  825. char op [8], flags [8];
  826. char TmpBuf[256] = "../noship.subproj/TLIST.TEXT", LinBuf[256];
  827. char *ptrc;
  828. int errorcountTotal = 0;
  829. int flagerrorsTotal = 0;
  830. int numerrorsTotal = 0;
  831. int enverrorsTotal = 0;
  832. int rnderrorsTotal = 0;
  833. time_t tod;
  834. OutFile = fopen ( "../noship.subproj/ieeetestresults", "w" );
  835. tod = time( NULL );
  836. fprintf ( OutFile, "%s\n", ctime(&tod) );
  837. // Open TLIST.TEXT file
  838. if ((ListFile = fopen ((char *) TmpBuf, "r")) == NULL) {
  839. fprintf ( OutFile,"\n%s%s\n", "There is no input file called: ", TmpBuf);
  840. exit (NOTEST);
  841. }
  842. do {
  843. ptrc = fgets ((char *) TmpBuf, 256, ListFile);
  844. if (ptrc == NULL)
  845. break;
  846. // Remove trailing '\n' (LF) and replace with zero
  847. len = strlen ((char *) TmpBuf);
  848. for (i = 0; i < len; i++) {
  849. if (TmpBuf [i] == '\n') {
  850. TmpBuf [i] = '\0';
  851. break;
  852. }
  853. }
  854. if (TmpBuf[0] != '\0') {
  855. fprintf ( OutFile,"\n%s%s\n", "Input file: ", TmpBuf);
  856. fflush( OutFile );
  857. }
  858. if (TmpBuf[0] == 'U') {
  859. int fd;
  860. int length;
  861. static struct sockaddr_in name;
  862. struct hostent *pH;
  863. double dnumtests = 0.0;
  864. LinBuf[0] = '\0';
  865. LinBuff[0] = '\0';
  866. for(;;) {
  867. char *p = (char *)v;
  868. int remain = sizeof(v);
  869. fd = socket(AF_INET, SOCK_STREAM, 0);
  870. if (fd < 0) {
  871. perror("socket() failed.");
  872. close( fd );
  873. break;
  874. }
  875. name.sin_family = AF_INET;
  876. name.sin_port = htons(12345);
  877. pH = gethostbyname( &TmpBuf[1] );
  878. if (pH)
  879. bcopy(pH->h_addr_list[0], &name.sin_addr, pH->h_length);
  880. else {
  881. perror("gethostbyname() failed.");
  882. close( fd );
  883. break;
  884. }
  885. length = connect(fd, (struct sockaddr *)&name, sizeof(name));
  886. if (length < 0) {
  887. perror("connect() failed.");
  888. close( fd );
  889. break;
  890. }
  891. write(fd, &v, 128);
  892. while (remain > 0) {
  893. length = read(fd, p, remain);
  894. if (length <= 0) {
  895. perror("read failed");
  896. break;
  897. }
  898. p += length;
  899. remain -= length;
  900. }
  901. if (v[0].op[0] == 'E') { // EOF marker
  902. fprintf(stderr,"EOF marker\n");
  903. fflush(stderr);
  904. break;
  905. }
  906. for (i = 0; i < kMaxVectorCount; ++i) {
  907. modes[0] = '\0';
  908. (void) strcat (modes, "=d"); // Hardwire "=d" mode
  909. rnds = 0;
  910. if (strchr (modes, '<') != NULL) rnds += 1;
  911. if (strchr (modes, '=') != NULL) rnds += 2;
  912. if (strchr (modes, '>') != NULL) rnds += 4;
  913. if (strchr (modes, '0') != NULL) rnds += 8;
  914. flags[0] = '\0';
  915. if (v[i].flags & (FE_INVALID)) (void) strcat (flags, "i");
  916. if (v[i].flags & (FE_OVERFLOW)) (void) strcat (flags, "o");
  917. if (v[i].flags & (FE_UNDERFLOW)) (void) strcat (flags, "u");
  918. if (v[i].flags & (FE_INEXACT)) (void) strcat (flags, "x");
  919. if (v[i].flags & (FE_DIVBYZERO)) (void) strcat (flags, "z");
  920. if (strlen(flags) == 0) (void) strcat (flags, "OK");
  921. LinBuf[0] = v[i].op[0];
  922. LinBuff[0] = v[i].op[0];
  923. LinBuf[1] = '\0';
  924. LinBuff[1] = '\0';
  925. // Tolerate +-1ulp discrepancies
  926. Tolerance = 1;
  927. HiTol = 2;
  928. LoTol = 2;
  929. testfcn ((const char *)&(v[i].op), v[i].r.d, v[i].n.d, flags, v[i].result.d, (char const *) LinBuf);
  930. dnumtests = dnumtests + 1.0;
  931. Tolerance = 0;
  932. if (numtests % 1000000 == 0) {
  933. printf ( "numtests, errorcount, numerrors, flagerrors, enverrors, rnderrors %s\n", TmpBuf);
  934. printf ( "%12e %3d %3d %3d %3d %3d\n",
  935. dnumtests, errorcount, numerrors, flagerrors, enverrors, rnderrors);
  936. fflush(stdout);
  937. }
  938. }
  939. close( fd );
  940. }
  941. #ifdef noprint
  942. #else /* noprint */
  943. if (NOFLAGTESTS) fprintf ( OutFile,"NOFLAGTESTS\n");
  944. fprintf ( OutFile,"numtests, errorcount, numerrors, flagerrors, enverrors, rnderrors %s\n", TmpBuf);
  945. fprintf ( OutFile," %3d %3d %3d %3d %3d %3d\n",
  946. numtests, errorcount, numerrors, flagerrors, enverrors, rnderrors);
  947. numtestsTotal += numtests;
  948. errorcountTotal += errorcount;
  949. flagerrorsTotal += flagerrors;
  950. numerrorsTotal += numerrors;
  951. enverrorsTotal += enverrors;
  952. rnderrorsTotal += rnderrors;
  953. numtests = 0;
  954. errorcount = 0;
  955. flagerrors = 0;
  956. numerrors = 0;
  957. enverrors = 0;
  958. rnderrors = 0;
  959. #endif /* noprint */
  960. continue;
  961. }
  962. if (TmpBuf[0] != '!') {
  963. // Open next test file in list
  964. if ((InFile = fopen ((const char *) TmpBuf, "r")) == NULL) {
  965. if (TmpBuf[0] != '\0')
  966. fprintf ( OutFile,"\n%s%s%s\n", "There is no input *list* file called: |", TmpBuf, "|");
  967. continue;
  968. }
  969. do {
  970. // Read one line from test file
  971. ptrc = fgets ((char *) LinBuf, 256, InFile);
  972. strcpy ((char *) LinBuff, (char *) LinBuf);
  973. if (ptrc == NULL) break;
  974. if ((LinBuf [0] == '2') || (LinBuf [0] == '3') || (LinBuf [0] == '5')) {
  975. if (sscanf ( (char *) LinBuf, "%s %s %s %s %s %s\r",
  976. (char *) &op, (char *) &modes, (char *) &s1, (char *) &s2, (char *) &flags, (char *) &s3) < 6)
  977. abort ();
  978. if (strchr (modes, 's') != NULL && strchr (modes, 'e') == NULL && strchr (modes, 'd') == NULL)
  979. {
  980. #ifdef DEBUG
  981. fprintf ( OutFile,"Pure 's' test vector encountered >>>%s", (char const *) LinBuf);
  982. #endif
  983. continue;
  984. }
  985. rnds = 0;
  986. if (strchr (modes, '<') != NULL) rnds += 1;
  987. if (strchr (modes, '=') != NULL) rnds += 2;
  988. if (strchr (modes, '>') != NULL) rnds += 4;
  989. if (strchr (modes, '0') != NULL) rnds += 8;
  990. #ifndef notdef
  991. r = Str90todbl (s1, op);
  992. n = (LinBuf [1] == 't') ? Str90toflt (s1, op): Str90todbl (s2, op);
  993. if (LinBuf [1] != 'C') rslt = Str90todbl (s3, op);
  994. else {
  995. if (!strcmp((char const *) s3, (char const *) "<")) rslt = -1;
  996. else if (!strcmp((char const *) s3, (char const *) "=")) rslt = 0;
  997. else if (!strcmp((char const *) s3, ">")) rslt = 1;
  998. else if (!strcmp((char const *) s3, "?")) rslt = 2;
  999. else rslt = 99;
  1000. }
  1001. #else
  1002. r = Str90toflt (s1, op);
  1003. n = Str90toflt (s2, op);
  1004. rslt = Str90toflt (s3, op);
  1005. #endif
  1006. testfcn (op, r, n, flags, rslt, (char const *) LinBuf);
  1007. }
  1008. else if (LinBuf [0] == '4') {
  1009. #if defined (__ppc__)
  1010. if (sscanf ( (char const *) LinBuf, "%s %s %x %x %x %x %s %x %x\r",
  1011. (char *) &op, (char *) &modes, (int *) &a1.i [0],
  1012. (int *) &a1.i [1], (int *) &a2.i [0], (int *) &a2.i [1], (char *) &flags,
  1013. (int *) &a3.i [0], (int *) &a3.i [1]) < 9)
  1014. abort ();
  1015. #elif defined (__i386__)
  1016. if (sscanf ( (char const *) LinBuf, "%s %s %x %x %x %x %s %x %x\r",
  1017. (char *) &op, (char *) &modes, (int *) &a1.i [1],
  1018. (int *) &a1.i [0], (int *) &a2.i [1], (int *) &a2.i [0], (char *) &flags,
  1019. (int *) &a3.i [1], (int *) &a3.i [0]) < 9)
  1020. abort ();
  1021. #else
  1022. #error Unknown architecture
  1023. #endif
  1024. if (strchr (modes, 's') != NULL && strchr (modes, 'e') == NULL && strchr (modes, 'd') == NULL)
  1025. {
  1026. fprintf ( OutFile,"Pure 's' test vector encountered >>>%s", (char const *) LinBuf);
  1027. continue;
  1028. }
  1029. rnds = 0;
  1030. if (strchr (modes, '<') != NULL) rnds += 1;
  1031. if (strchr (modes, '=') != NULL) rnds += 2;
  1032. if (strchr (modes, '>') != NULL) rnds += 4;
  1033. if (strchr (modes, '0') != NULL) rnds += 8;
  1034. r = a1.d;
  1035. n = a2.d;
  1036. rslt = a3.d;
  1037. #ifndef notdef
  1038. testfcn (op, r, n, flags, rslt, (char const *) LinBuf);
  1039. #endif
  1040. }
  1041. else if ((LinBuf [0] == '!') || (LinBuf [0] == ' ') ||
  1042. (LinBuf [0] == '\x09') || (LinBuf [0] == '\r') ||
  1043. (LinBuf [0] == '\n')) i = 1;
  1044. else if (LinBuf [0] == 'E') break; // EOF on UDP
  1045. else {
  1046. fprintf ( OutFile,"Unknown test vector encountered >>>%s<<<\n", (char const *) LinBuf);
  1047. for (i = 0; i < strlen ((char const *) LinBuf); i++) fprintf ( OutFile,"%3d\n", LinBuf [i]);
  1048. exit (NOOP);
  1049. }
  1050. } while ( !feof (InFile)); // end of data file
  1051. fclose (InFile);
  1052. #ifdef noprint
  1053. #else /* noprint */
  1054. if (NOFLAGTESTS) fprintf ( OutFile,"NOFLAGTESTS\n");
  1055. fprintf ( OutFile,"numtests, errorcount, numerrors, flagerrors, enverrors, rnderrors %s\n", TmpBuf);
  1056. fprintf ( OutFile," %3d %3d %3d %3d %3d %3d\n",
  1057. numtests, errorcount, numerrors, flagerrors, enverrors, rnderrors);
  1058. numtestsTotal += numtests;
  1059. errorcountTotal += errorcount;
  1060. flagerrorsTotal += flagerrors;
  1061. numerrorsTotal += numerrors;
  1062. enverrorsTotal += enverrors;
  1063. rnderrorsTotal += rnderrors;
  1064. numtests = 0;
  1065. errorcount = 0;
  1066. flagerrors = 0;
  1067. numerrors = 0;
  1068. enverrors = 0;
  1069. rnderrors = 0;
  1070. #endif /* noprint */
  1071. }
  1072. } while ( !feof (ListFile)); // end of data file listing file
  1073. fprintf ( OutFile,"\n\nnumtests, errorcount, NUMerrors, FLAGerrors, ENVRMerrs, ROUNDerrs\n");
  1074. fprintf ( OutFile,"%6d %4d %4d %4d %4d %4d\n",
  1075. numtestsTotal, errorcountTotal, numerrorsTotal, flagerrorsTotal, enverrorsTotal, rnderrorsTotal);
  1076. tod = time( NULL );
  1077. fprintf ( OutFile, "%s\n", ctime(&tod) );
  1078. fclose ( OutFile );
  1079. return 0;
  1080. }