home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume10 / config42 < prev    next >
Encoding:
Text File  |  1990-02-13  |  65.4 KB  |  2,315 lines

  1. Newsgroups: comp.sources.misc
  2. organization: CWI, Amsterdam
  3. subject: v10i062: config.c v4.2, Everything you wanted to know about your C compiler (and more)
  4. from: steven@cwi.nl (Steven Pemberton)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 10, Issue 62
  8. Submitted-by: steven@cwi.nl (Steven Pemberton)
  9. Archive-name: config42
  10.  
  11. Here is the latest version of config.c, a program that finds out all
  12. sorts of properties of your machine and C compiler. It will also
  13. optionally produce the ANSI C float.h and limits.h files for you.
  14.  
  15. All documentation is in the file itself.
  16.  
  17. Steven Pemberton, CWI, Amsterdam; steven@cwi.nl
  18. "Let us go then you and I/while the night is laid out against the sky/like a
  19.                     smear of mustard on an old pork pie"
  20. "Nice poem Tom. I have suggestions for changes though, why not come over?"- Ez.
  21.  
  22. -----------------CUT HERE-------------------------
  23. : This is a shell archive.
  24. : Extract with 'sh this_file'.
  25. echo 'Start of pack.out, part 01 out of 01:'
  26. if test -s 'config.c'
  27. then echo '*** I will not over-write existing file config.c'
  28. else
  29. echo 'x - config.c'
  30. sed 's/^X//' > 'config.c' << 'EOF'
  31. X/* Everything you wanted to know about your machine and C compiler,
  32. X   but didn't know who to ask. */
  33. X
  34. X#ifndef VERSION
  35. X#define VERSION "4.2"
  36. X#endif
  37. X
  38. X/* Author: Steven Pemberton, CWI, Amsterdam; steven@cwi.nl
  39. X   Bugfixes and upgrades gratefully received.
  40. X
  41. X   Copyright (c) 1988, 1989, 1990 Steven Pemberton, CWI, Amsterdam.
  42. X   All rights reserved.
  43. X
  44. X   COMPILING
  45. X   With luck and a following wind, just the following will work:
  46. X    cc config.c -o config
  47. X   You may get some messages about unreachable code. This is OK.
  48. X
  49. X   If your compiler doesn't support:        add flag:
  50. X    signed char (eg pcc)            -DNO_SC
  51. X    unsigned char                -DNO_UC
  52. X    unsigned short and long            -DNO_UI
  53. X    void                    -DNO_VOID
  54. X    signal(), or setjmp/longjmp()        -DNO_SIG
  55. X
  56. X   Try to compile first with no flags, and see if you get any errors - 
  57. X   you might be surprised. (Most non-ANSI compilers need -DNO_SC, though.)
  58. X   Some compilers need a -f flag for floating point.
  59. X
  60. X   If your C preprocessor doesn't have the predefined __FILE__ macro, and
  61. X   you don't want to call this file config.c but, say, params.c, add the
  62. X   flag -D__FILE__=\"params.c\" .
  63. X
  64. X   Some naughty compilers define __STDC__, but don't really support it
  65. X   (typically they define __STDC__ as 0). If this is the case for you,
  66. X   add flag -DNO_STDC. (To those compiler writers: for shame).
  67. X
  68. X   Some bad compilers won't accept the line "#include __FILE__" or
  69. X   "#ifdef __FILE__". Add flag -DNO_FILE. In that case, this file *must*
  70. X   be called config.c.
  71. X
  72. X   Don't use any optimisation flags: the program may not work if you do.
  73. X   Though "while (a+1.0-a-1.0 == 0.0)" may look like "while(1)" to an
  74. X   optimiser, to a floating-point unit there's a world of difference.
  75. X
  76. X   Some compilers offer various flags for different floating point
  77. X   modes; it's worth trying all possible combinations of these.
  78. X
  79. X   Add -DID=\"name\" if you want the machine/flags identified in the output.
  80. X
  81. X   While it is not our policy to support defective compilers, pity has been
  82. X   taken on people with compilers that can't produce object files bigger than
  83. X   32k (especially since it was an easy addition). Compile the program
  84. X   into separate parts like this:
  85. X       cc -DSEP -DPASS0 -o p0.o <other flags> config.c
  86. X       cc -DSEP -DPASS1 -o p1.o <other flags> config.c
  87. X       cc -DSEP -DPASS2 -o p2.o <other flags> config.c
  88. X       cc -DSEP -DPASS3 -o p3.o <other flags> config.c
  89. X       cc -o config p0.o p1.o p2.o p3.o
  90. X
  91. X   SYSTEM DEPENDENCIES
  92. X   You may possibly need to add some calls to signal() for other sorts of
  93. X   exception on your machine than SIGFPE, and SIGOVER.  See lines beginning
  94. X   #ifdef SIGxxx in main() (and communicate the differences to me!).
  95. X
  96. X   OUTPUT
  97. X   Run without argument to get the information as English text.  If run
  98. X   with argument -l (e.g. config -l), output is a series of #define's for
  99. X   the ANSI standard limits.h include file, excluding MB_MAX_CHAR.  If run
  100. X   with argument -f, output is a series of #define's for the ANSI standard
  101. X   float.h include file (according to ANSI C Draft of May 13, 1988).
  102. X   Flag -v gives verbose output: output includes the English text above
  103. X   as C comments.  The program exit(0)'s if everything went ok, otherwise
  104. X   it exits with a positive number, telling how many problems there were.
  105. X
  106. X   VERIFYING THE COMPILER
  107. X   If, having produced the float.h and limits.h header files, you want to
  108. X   verify that the compiler reads them back correctly (there are a lot of
  109. X   boundary cases, of course, like minimum and maximum numbers), you can
  110. X   recompile config.c with -DVERIFY set (plus the other flags that you used
  111. X   when compiling the version that produced the header files).  This then
  112. X   recompiles the program so that it #includes "limits.h" and "float.h",
  113. X   and checks that the constants it finds there are the same as the
  114. X   constants it produces. Run the resulting program with config -fl.
  115. X   Very few compilers have passed without error.
  116. X
  117. X   You can also use this option if your compiler already has both files,
  118. X   and you want to confirm that this program produces the right results.
  119. X
  120. X   TROUBLESHOOTING.
  121. X   This program is now quite trustworthy, and suspicious and wrong output
  122. X   may well be caused by bugs in the compiler, not in the program (however
  123. X   of course, this is not guaranteed, and no responsibility can be
  124. X   accepted, etc.)
  125. X
  126. X   The program only works if overflows are ignored by the C system or
  127. X   are catchable with signal().
  128. X
  129. X   If the program fails to run to completion (often with the error message
  130. X   "Unexpected signal at point x"), this often turns out to be a bug in the
  131. X   C compiler's run-time system. Check what was about to be printed, and
  132. X   try to narrow the problem down.
  133. X
  134. X   Another possible problem is that you have compiled the program to produce
  135. X   loss-of-precision arithmetic traps. The program cannot cope with these,
  136. X   and you should re-compile without them. (They should never be the default).
  137. X
  138. X   Make sure you compiled with optimisation turned off.
  139. X
  140. X   Output preceded by *** WARNING: identifies behaviour of the C system
  141. X   deemed incorrect by the program. Likely problems are that printf or
  142. X   scanf don't cope properly with certain boundary numbers: this program
  143. X   goes to a lot of trouble to calculate its values, and these values
  144. X   are mostly boundary numbers.  Experience has shown that often printf
  145. X   cannot cope with these values, and so in an attempt to increase
  146. X   confidence in the output, for each float and double that is printed,
  147. X   the printed value is checked by using sscanf to read it back.
  148. X   Care is taken that numbers are printed with enough digits to uniquely
  149. X   identify them, and therefore that they can be read back identically.
  150. X   If the number read back is different, then there is probably a bug in
  151. X   printf or sscanf, and the program prints the warning message.
  152. X   If the two numbers in the warning look identical, then printf is more
  153. X   than likely rounding the last digit(s) incorrectly. To put you at ease
  154. X   that the two really are different, the bit patterns of the two numbers
  155. X   are also printed.  The difference is very likely in the last bit.
  156. X   Many scanf's read the minimum double back as 0.0, and similarly cause
  157. X   overflow when reading the maximum double.  The program quite ruthlessly
  158. X   declares all these behaviours faulty. The point is that if you get
  159. X   one of these warnings, the output may be wrong, so you should check
  160. X   the result carefully if you intend to use the results. Of course, printf
  161. X   and sscanf may both be wrong, and cancel each other out, so you should
  162. X   check the output carefully anyway.
  163. X
  164. X   The warning that "a cast didn't work" refers to cases like this:
  165. X
  166. X      float f;
  167. X      #define C 1.234567890123456789
  168. X      f= C;
  169. X      if (f != (float) C) printf ("Wrong!");
  170. X
  171. X   A faulty compiler will widen f to double and ignore the cast to float,
  172. X   and because there is more accuracy in a double than a float, fail to
  173. X   recognise that they are the same. In the actual case in point, f and C
  174. X   are passed as parameters to a function that discovers they are not equal,
  175. X   so it's just possible that the error was in the parameter passing,
  176. X   not in the cast (see function Validate()).
  177. X   For ANSI C, which has float constants, the error message is "constant has
  178. X   wrong precision".
  179. X
  180. X   REPORTING PROBLEMS
  181. X   If the program doesn't work for you for any reason that can't be
  182. X   narrowed down to a problem in the C compiler, or it has to be changed in
  183. X   order to get it to compile, or it produces suspicious output (like a very
  184. X   low maximum float, for instance), please mail the problem and an example
  185. X   of the incorrect output to steven@cwi.nl or ..!hp4nl!cwi.nl!steven, so that
  186. X   improvements can be worked into future versions; cwi.nl is the European
  187. X   backbone, and is connected to uunet and other fine hosts.
  188. X
  189. X   The program tries to catch and diagnose bugs in the compiler/run-time
  190. X   system. I would be especially pleased to have reports of failures so
  191. X   that I can improve this service.
  192. X
  193. X   I apologise unreservedly for the contorted use of the preprocessor...
  194. X
  195. X   THE SMALL PRINT
  196. X   You may copy and distribute verbatim copies of this source file.
  197. X
  198. X   You may modify this source file, and copy and distribute such
  199. X   modified versions, provided that you leave the copyright notice
  200. X   at the top of the file and also cause the modified file to carry
  201. X   prominent notices stating that you changed the files and the date
  202. X   of any change; and cause the whole of any work that you distribute
  203. X   or publish, that in whole or in part contains or is a derivative of
  204. X   this program or any part thereof, to be licensed at no charge to
  205. X   all third parties on terms identical to those here.
  206. X
  207. X   If you do have a fix to any problem, please send it to me, so that
  208. X   other people can have the benefits.
  209. X
  210. X   While every effort has been taken to make this program as reliable as
  211. X   possible, no responsibility can be taken for the correctness of the
  212. X   output, or suitability for any particular use.
  213. X
  214. X   ACKNOWLEDGEMENTS
  215. X   Many people have given time and ideas to making this program what it is.
  216. X   To all of them thanks, and apologies for not mentioning them by name.
  217. X
  218. X   HISTORY
  219. X   4.0 Added -f and -l options, and warnings
  220. X   4.1 Added VERIFY
  221. X   4.2 Added SEP
  222. X       Fixed eps/epsneg
  223. X       Added check for pseudo-unsigned chars
  224. X       Added description for each #define output
  225. X       Added check for absence of defines during verify
  226. X       Added prototypes
  227. X       Added NO_STDC and NO_FILE
  228. X       Fixed alignments output
  229. X*/
  230. X
  231. X#ifndef NO_FILE
  232. X#ifndef __FILE__
  233. X#define __FILE__ "config.c"
  234. X#endif
  235. X#endif
  236. X
  237. X/* If PASS isn't defined, then this is the first pass over this file. */
  238. X#ifndef PASS
  239. X#ifndef SEP
  240. X#define PASS 1
  241. X#define PASS0 1
  242. X#define PASS1 1
  243. X#endif /* SEP */
  244. X
  245. X/* A description of the ANSI constants */
  246. X#define D_CHAR_BIT "Number of bits in a storage unit"
  247. X#define D_CHAR_MAX "Maximum char"
  248. X#define D_CHAR_MIN "Minimum char"
  249. X#define D_SCHAR_MAX "Maximum signed char"
  250. X#define D_SCHAR_MIN "Minimum signed char"
  251. X#define D_UCHAR_MAX "Maximum unsigned char (minimum is always 0)"
  252. X
  253. X#define D_INT_MAX "Maximum %s"
  254. X#define D_INT_MIN "Minimum %s"
  255. X#define D_UINT_MAX "Maximum unsigned %s (minimum is always 0)"
  256. X
  257. X#define D_FLT_ROUNDS "Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown"
  258. X#define D_FLT_RADIX "Radix of exponent representation"
  259. X#define D_MANT_DIG "Number of base-FLT_RADIX digits in the mantissa of a %s"
  260. X#define D_DIG "Number of decimal digits of precision in a %s"
  261. X#define D_MIN_EXP "Minimum int x such that FLT_RADIX**(x-1) is a normalised %s"
  262. X#define D_MIN_10_EXP "Minimum int x such that 10**x is a normalised %s"
  263. X#define D_MAX_EXP "Maximum int x such that FLT_RADIX**(x-1) is a representable %s"
  264. X#define D_MAX_10_EXP "Maximum int x such that 10**x is a representable %s"
  265. X#define D_MAX "Maximum %s"
  266. X#define D_EPSILON "Minimum %s x such that 1.0+x != 1.0"
  267. X#define D_MIN "Minimum normalised %s"
  268. X
  269. X/* Procedure just marks the functions that don't return a result */
  270. X#ifdef NO_VOID
  271. X#define Procedure int
  272. X#else
  273. X#define Procedure void
  274. X#endif
  275. X
  276. X/* Some bad compilers define __STDC__, when they don't support it.
  277. X   Compile with -DNO_STDC to get round this.
  278. X*/
  279. X#ifndef NO_STDC
  280. X#ifdef __STDC__
  281. X#define STDC
  282. X#endif
  283. X#endif
  284. X
  285. X/* Stuff different for ANSI C, and old C:
  286. X   ARGS and NOARGS are used for function prototypes.
  287. X   Volatile is used to reduce the chance of optimisation,
  288. X      and to prevent variables being put in registers (when setjmp/longjmp
  289. X      wouldn't work as we want)
  290. X   Long_double is the longest floating point type available.
  291. X   stdc is used in tests like "if (stdc)", which is less ugly than #ifdef.
  292. X   U is output after unsigned constants.
  293. X */
  294. X#ifdef STDC
  295. X
  296. X#define ARGS(x) x
  297. X#define NOARGS (void)
  298. X#define Volatile volatile
  299. X#define Long_double long double
  300. X#define stdc 1
  301. X#define U "U"
  302. X
  303. X#else /* Old style C */
  304. X
  305. X#define ARGS(x) ()
  306. X#define NOARGS ()
  307. X#define Volatile static
  308. X#define Long_double double
  309. X#define stdc 0
  310. X#define U ""
  311. X
  312. X#endif /* STDC */
  313. X
  314. X/* include files */
  315. X#include <stdio.h>
  316. X
  317. X#ifdef NO_SIG
  318. X#define jmp_buf int
  319. X#else
  320. X#include <signal.h>
  321. X#include <setjmp.h>
  322. X#endif
  323. X
  324. X#ifdef VERIFY
  325. X#include "limits.h"
  326. X#include "float.h"
  327. X#endif
  328. X
  329. X#define Vprintf if (V) printf
  330. X#define Unexpected(place) if (setjmp(lab)!=0) croak(place)
  331. X#define fabs(x) (((x)<0.0)?(-x):(x))
  332. X
  333. X#endif /* PASS */
  334. X
  335. X#ifdef PASS0
  336. X
  337. X/* Prototypes for what's to come: */
  338. X
  339. Xchar *malloc ARGS((unsigned size));
  340. XProcedure exit ARGS((int status));
  341. X
  342. Xchar *f_rep ARGS((int precision, Long_double val));
  343. X
  344. Xint cprop NOARGS;
  345. Xint basic NOARGS;
  346. XProcedure sprop NOARGS;
  347. XProcedure iprop NOARGS;
  348. XProcedure lprop NOARGS;
  349. XProcedure usprop NOARGS;
  350. XProcedure uiprop NOARGS;
  351. XProcedure ulprop NOARGS;
  352. Xint fprop ARGS((int bits_per_byte));
  353. Xint dprop ARGS((int bits_per_byte));
  354. Xint ldprop ARGS((int bits_per_byte));
  355. XProcedure efprop ARGS((int fprec, int dprec, int lprec));
  356. XProcedure edprop ARGS((int fprec, int dprec, int lprec));
  357. XProcedure eldprop ARGS((int fprec, int dprec, int lprec));
  358. X
  359. Xint setmode ARGS((char *s));
  360. XProcedure farewell ARGS((int bugs));
  361. XProcedure describe ARGS((char *description, char *extra));
  362. XProcedure check_defines NOARGS;
  363. XProcedure bitpattern ARGS((char *p, unsigned int size));
  364. Xint ceil_log ARGS((int base, Long_double x));
  365. XProcedure croak ARGS((int place));
  366. XProcedure eek_a_bug ARGS((char *problem));
  367. XProcedure endian ARGS((int bits_per_byte));
  368. Xint exponent ARGS((Long_double x, double *fract, int *exp));
  369. Xint floor_log ARGS((int base, Long_double x));
  370. XProcedure f_define ARGS((char *desc, char *extra, char *sort, char *name,
  371. X             int prec, Long_double val, char *mark));
  372. XProcedure i_define ARGS((char *desc, char *extra, char *sort, char *name,
  373. X             long val, long req, char *mark));
  374. XProcedure u_define ARGS((char *desc, char *extra, char *sort, char *name,
  375. X             unsigned long val, unsigned long req, char *mark));
  376. X
  377. X#ifdef NO_SIG  /* There's no signal(), or setjmp/longjmp() */
  378. X
  379. X    /* Dummy routines instead */
  380. X
  381. X    Procedure setjmp ARGS((int lab));
  382. X
  383. X    int lab=1;
  384. X    int setjmp(lab) int lab; { return(0); }
  385. X    Procedure signal(i, p) int i, (*p)(); {}
  386. X
  387. X#else
  388. X    jmp_buf lab;
  389. X    Procedure overflow(sig) int sig; { /* what to do on over/underflow */
  390. X        signal(sig, overflow);
  391. X        longjmp(lab, 1);
  392. X    }
  393. X
  394. X#endif /*NO_SIG*/
  395. X
  396. Xint V= 0,    /* verbose */
  397. X    L= 0,    /* produce limits.h */
  398. X    F= 0,    /* produce float.h  */
  399. X    bugs=0;    /* The number of (possible) bugs in the output */
  400. X
  401. Xchar co[4], oc[4]; /* Comment starter and ender symbols */
  402. X
  403. Xint bits_per_byte; /* the number of bits per unit returned by sizeof() */
  404. Xint flt_rounds;    /* The calculated value of FLT_ROUNDS */
  405. Xint flt_radix;     /* The calculated value of FLT_RADIX */
  406. X
  407. X#ifdef TEST
  408. X/* Set the fp modes on a SUN with 68881 chip, to check that different
  409. X   rounding modes etc. get properly detected.
  410. X   Compile with additional flag -DTEST, and run with additional parameter
  411. X   +hex-number, to set the 68881 mode register to hex-number
  412. X*/
  413. X
  414. X/* Bits 0x30 = rounding mode: */
  415. X#define ROUND_BITS    0x30
  416. X#define TO_NEAREST    0x00
  417. X#define TO_ZERO        0x10
  418. X#define TO_MINUS_INF    0x20
  419. X#define TO_PLUS_INF    0x30 /* The SUN FP user's guide seems to be wrong here */
  420. X
  421. X/* Bits 0xc0 = extended rounding: */
  422. X#define EXT_BITS    0xc0
  423. X#define ROUND_EXTENDED    0x00
  424. X#define ROUND_SINGLE     0x40
  425. X#define ROUND_DOUBLE    0x80
  426. X
  427. X/* Enabled traps: */
  428. X#define EXE_INEX1  0x100
  429. X#define EXE_INEX2  0x200
  430. X#define EXE_DZ       0x400
  431. X#define EXE_UNFL   0x800
  432. X#define EXE_OVFL  0x1000
  433. X#define EXE_OPERR 0x2000
  434. X#define EXE_SNAN  0x4000
  435. X#define EXE_BSUN  0x8000
  436. X
  437. X/* Only used for testing, on a Sun with 68881 chip */
  438. X/* Print the FP mode */
  439. Xprintmode(new) unsigned new; {
  440. X    fpmode_(&new);
  441. X    printf("New fp mode:\n");
  442. X    printf("  Round toward ");
  443. X    switch (new & ROUND_BITS) {
  444. X          case TO_NEAREST:   printf("nearest"); break;
  445. X          case TO_ZERO:      printf("zero"); break;
  446. X          case TO_MINUS_INF: printf("minus infinity"); break;
  447. X          case TO_PLUS_INF:  printf("plus infinity"); break;
  448. X          default: printf("???"); break;
  449. X    }
  450. X
  451. X    printf("\n  Extended rounding precision: ");
  452. X
  453. X    switch (new & EXT_BITS) {
  454. X          case ROUND_EXTENDED: printf("extended"); break;
  455. X          case ROUND_SINGLE:   printf("single"); break;
  456. X          case ROUND_DOUBLE:   printf("double"); break;
  457. X          default: printf("???"); break;
  458. X    }
  459. X
  460. X    printf("\n  Enabled exceptions:");
  461. X    if (new & (unsigned) EXE_INEX1) printf(" inex1");
  462. X    if (new & (unsigned) EXE_INEX2) printf(" inex2");
  463. X    if (new & (unsigned) EXE_DZ)    printf(" dz"); 
  464. X    if (new & (unsigned) EXE_UNFL)  printf(" unfl"); 
  465. X    if (new & (unsigned) EXE_OVFL)  printf(" ovfl"); 
  466. X    if (new & (unsigned) EXE_OPERR) printf(" operr"); 
  467. X    if (new & (unsigned) EXE_SNAN)  printf(" snan"); 
  468. X    if (new & (unsigned) EXE_BSUN)  printf(" bsun"); 
  469. X    printf("\n");
  470. X}
  471. X
  472. X/* Only used for testing, on a Sun with 68881 chip */
  473. X/* Set the FP mode */
  474. Xint setmode(s) char *s; {
  475. X    unsigned mode=0, dig;
  476. X    char c;
  477. X
  478. X    while (*s) {
  479. X        c= *s++;
  480. X        if  (c>='0' && c<='9') dig= c-'0';
  481. X        else if (c>='a' && c<='f') dig= c-'a'+10;
  482. X        else if (c>='A' && c<='F') dig= c-'A'+10;
  483. X        else return 1;
  484. X        mode= mode<<4 | dig;
  485. X    }
  486. X    printmode(mode);
  487. X    return 0;
  488. X}
  489. X#else
  490. Xint setmode(s) char *s; {
  491. X    fprintf(stderr, "Can't set mode: not compiled with TEST\n");
  492. X    return(1);
  493. X}
  494. X#endif
  495. X
  496. XProcedure farewell(bugs) int bugs; {
  497. X    if (bugs > 0) {
  498. X        printf("\n%sFor hints on dealing with the problems above", co);
  499. X        printf("\n   see the section 'TROUBLESHOOTING' in the file ");
  500. X        printf("%s%s\n", __FILE__, oc);
  501. X    }
  502. X    exit(bugs);
  503. X}
  504. X
  505. X/* The program has received a signal where it wasn't expecting one */
  506. XProcedure croak(place) int place; {
  507. X    printf("*** Unexpected signal at point %d\n", place);
  508. X    farewell(bugs+1); /* An exit isn't essential here, but avoids loops */
  509. X}
  510. X
  511. Xmain(argc, argv) int argc; char *argv[]; {
  512. X    int dprec, fprec, lprec;
  513. X    unsigned int size;
  514. X    long total;
  515. X    int i; char *s; int bad;
  516. X
  517. X#ifdef SIGFPE
  518. X    signal(SIGFPE, overflow);
  519. X#endif
  520. X#ifdef SIGOVER
  521. X    signal(SIGOVER, overflow);
  522. X#endif
  523. X/* Add more calls as necessary */
  524. X
  525. X    Unexpected(1);
  526. X
  527. X    bad=0;
  528. X    for (i=1; i < argc; i++) {
  529. X        s= argv[i];
  530. X        if (*s == '-') {
  531. X            s++;
  532. X            while (*s) {
  533. X                switch (*(s++)) {
  534. X                      case 'v': V=1; break;
  535. X                      case 'l': L=1; break;
  536. X                      case 'f': F=1; break;
  537. X                      default: bad=1; break;
  538. X                }
  539. X            }
  540. X        } else if (*s == '+') {
  541. X            s++;
  542. X            bad= setmode(s);
  543. X        } else bad= 1;
  544. X    }
  545. X    if (bad) {
  546. X        fprintf(stderr,
  547. X            "Usage: %s [-vlf]\n  v=Verbose l=Limits.h f=Float.h\n",
  548. X            argv[0]);
  549. X        exit(1);
  550. X    }
  551. X    if (L || F) {
  552. X        co[0]= '/'; oc[0]= ' ';
  553. X        co[1]= '*'; oc[1]= '*';
  554. X        co[2]= ' '; oc[2]= '/';
  555. X        co[3]= '\0'; oc[3]= '\0';
  556. X    } else {
  557. X        co[0]= '\0'; oc[0]= '\0';
  558. X        V=1;
  559. X    }
  560. X
  561. X    if (L) printf("%slimits.h%s\n", co, oc);
  562. X    if (F) printf("%sfloat.h%s\n", co, oc);
  563. X#ifdef ID
  564. X    printf("%sProduced on %s by config version %s, CWI, Amsterdam%s\n",
  565. X           co, ID, VERSION, oc);
  566. X#else
  567. X    printf("%sProduced by config version %s, CWI, Amsterdam%s\n",
  568. X           co, VERSION, oc);
  569. X#endif
  570. X
  571. X#ifdef VERIFY
  572. X    printf("%sVerification phase%s\n", co, oc);
  573. X#endif
  574. X
  575. X#ifdef NO_SIG
  576. X    Vprintf("%sCompiled without signal(): %s%s\n",
  577. X        co,
  578. X        "there's nothing that can be done if overflow occurs",
  579. X        oc);
  580. X#endif
  581. X#ifdef NO_SC
  582. X    Vprintf("%sCompiled without signed char%s\n", co, oc);
  583. X#endif
  584. X#ifdef NO_UC
  585. X    Vprintf("%Compiled without unsigned char%s\n", co, oc);
  586. X#endif
  587. X#ifdef NO_UI
  588. X    Vprintf("%Compiled without unsigned short or long%s\n", co, oc);
  589. X#endif
  590. X#ifdef __STDC__
  591. X    Vprintf("%sCompiler claims to be ANSI C level %d%s\n",
  592. X        co, __STDC__, oc);
  593. X#else
  594. X    Vprintf("%sCompiler does not claim to be ANSI C%s\n", co, oc);
  595. X#endif
  596. X    printf("\n");
  597. X    check_defines();
  598. X
  599. X    bits_per_byte= basic();
  600. X    Vprintf("\n");
  601. X    if (F||V) {
  602. X        fprec= fprop(bits_per_byte);
  603. X        dprec= dprop(bits_per_byte);
  604. X        lprec= ldprop(bits_per_byte);
  605. X        efprop(fprec, dprec, lprec);
  606. X        edprop(fprec, dprec, lprec);
  607. X        eldprop(fprec, dprec, lprec);
  608. X    }
  609. X    if (V) {
  610. X        /* An extra goody: the approximate amount of data-space */
  611. X        /* Allocate store until no more available */
  612. X        size=1<<((bits_per_byte*sizeof(int))-2);
  613. X        total=0;
  614. X        while (size!=0) {
  615. X            while (malloc(size)!=(char *)NULL) total+=(size/2);
  616. X            size/=2;
  617. X        }
  618. X
  619. X        Vprintf("%sMemory mallocatable ~= %ld Kbytes%s\n",
  620. X            co, (total+511)/512, oc);
  621. X    }
  622. X    farewell(bugs);
  623. X    return bugs; /* To keep compilers and lint happy */
  624. X}
  625. X
  626. XProcedure eek_a_bug(problem) char *problem; {
  627. X    /* The program has discovered a problem */
  628. X    printf("\n%s*** WARNING: %s%s\n", co, problem, oc);
  629. X    bugs++;
  630. X}
  631. X
  632. XProcedure describe(description, extra) char *description, *extra; {
  633. X    /* Produce the description for a #define */
  634. X    printf("   %s", co);
  635. X    printf(description, extra);
  636. X    printf("%s\n", oc);
  637. X}
  638. X
  639. XProcedure i_define(desc, extra, sort, name, val, req, mark)
  640. X     char *desc, *extra, *sort, *name; long val, req; char *mark; {
  641. X    /* Produce a #define for a signed int type */
  642. X    describe(desc, extra);
  643. X    if (val >= 0) {
  644. X        printf("#define %s%s %ld%s\n", sort, name, val, mark);
  645. X    } else {
  646. X        printf("#define %s%s (%ld%s)\n", sort, name, val, mark);
  647. X    }
  648. X    if (val != req) {
  649. X        printf("%s*** Verify failed for above #define!\n", co);
  650. X        printf("       Compiler has %ld for value%s\n\n", req, oc);
  651. X        bugs++;
  652. X    }
  653. X    Vprintf("\n");
  654. X}
  655. X
  656. XProcedure u_define(desc, extra, sort, name, val, req, mark)
  657. X     char *desc, *extra, *sort, *name; unsigned long val, req; char *mark; {
  658. X    /* Produce a #define for an unsigned value */
  659. X    describe(desc, extra);
  660. X    printf("#define %s%s %lu%s%s\n", sort, name, val, U, mark);
  661. X    if (val != req) {
  662. X        printf("%s*** Verify failed for above #define!\n", co);
  663. X        printf("       Compiler has %lu for value%s\n\n", req, oc);
  664. X        bugs++;
  665. X    }
  666. X    Vprintf("\n");
  667. X}
  668. X
  669. XProcedure f_define(desc, extra, sort, name, precision, val, mark)
  670. X     char *desc, *extra, *sort, *name; int precision;
  671. X     Long_double val; char *mark; {
  672. X    /* Produce a #define for a float/double/long double */
  673. X    describe(desc, extra);
  674. X    if (stdc) {
  675. X        printf("#define %s%s %s%s\n",
  676. X               sort, name, f_rep(precision, val), mark);
  677. X    } else if (*mark == 'F') {
  678. X        /* non-ANSI C has no float constants, so cast the constant */
  679. X        printf("#define %s%s ((float)%s)\n",
  680. X               sort, name, f_rep(precision, val));
  681. X    } else {
  682. X        printf("#define %s%s %s\n", sort, name, f_rep(precision, val));
  683. X    }
  684. X    Vprintf("\n");
  685. X}
  686. X
  687. Xint floor_log(base, x) int base; Long_double x; {
  688. X    /* return floor(log base(x)) */
  689. X    int r=0;
  690. X    while (x>=base) { r++; x/=base; }
  691. X    return r;
  692. X}
  693. X
  694. Xint ceil_log(base, x) int base; Long_double x; {
  695. X    int r=0;
  696. X    while (x>1.0) { r++; x/=base; }
  697. X    return r;
  698. X}
  699. X
  700. Xint exponent(x, fract, exp) Long_double x; double *fract; int *exp; {
  701. X    /* Split x into a fraction and a power of ten;
  702. X       returns 0 if x is unusable, 1 otherwise.
  703. X       Only used for error messages about faulty output.
  704. X    */
  705. X    int r=0, neg=0;
  706. X    Long_double old;
  707. X    *fract=0.0; *exp=0;
  708. X    if (x<0.0) {
  709. X        x= -x;
  710. X        neg= 1;
  711. X    }
  712. X    if (x==0.0) return 1;
  713. X    if (x>=10.0) {
  714. X        while (x>=10.0) {
  715. X            old=x; r++; x/=10.0;
  716. X            if (old==x) return 0;
  717. X        }
  718. X    } else {
  719. X        while (x<1.0) {
  720. X            old=x; r--; x*=10.0;
  721. X            if (old==x) return 0;
  722. X        }
  723. X    }
  724. X    if (neg) *fract= -x;
  725. X    else *fract=x;
  726. X    *exp=r;
  727. X    return 1;
  728. X}
  729. X
  730. Xchar *f_rep(precision, val) int precision; Long_double val; {
  731. X    /* Return the floating representation of val */
  732. X    static char buf[1024];
  733. X    char *f1;
  734. X    if (sizeof(double) == sizeof(Long_double)) {
  735. X        /* Assume they're the same, and use non-stdc format */
  736. X        /* This is for stdc compilers using non-stdc libraries */
  737. X        f1= "%.*e";
  738. X    } else {
  739. X        /* It had better support Le then */
  740. X        f1= "%.*Le";
  741. X    }
  742. X    sprintf(buf, f1, precision, val);
  743. X    return buf;
  744. X}
  745. X
  746. XProcedure bitpattern(p, size) char *p; unsigned int size; {
  747. X    /* Printf the bit-pattern of p */
  748. X    char c;
  749. X    int i, j;
  750. X
  751. X    for (i=1; i<=size; i++) {
  752. X        c= *p;
  753. X        p++;
  754. X        for (j=bits_per_byte-1; j>=0; j--)
  755. X            printf("%c", (c>>j)&1 ? '1' : '0');
  756. X        if (i!=size) printf(" ");
  757. X    }
  758. X}
  759. X
  760. X#define Order(x, px, mode)\
  761. X   printf("%s    %s ", co, mode); for (i=0; i<sizeof(x); i++) px[i]= c[i]; \
  762. X   for (i=1; i<=sizeof(x); i++) { putchar((char)((x>>(bits_per_byte*(sizeof(x)-i)))&mask)); }\
  763. X   printf("%s\n", oc);
  764. X
  765. XProcedure endian(bits_per_byte) int bits_per_byte; {
  766. X    /* Printf the byte-order used on this machine */
  767. X    /*unsigned*/ short s=0;
  768. X    /*unsigned*/ int j=0;
  769. X    /*unsigned*/ long l=0;
  770. X
  771. X    char *ps= (char *) &s,
  772. X         *pj= (char *) &j,
  773. X         *pl= (char *) &l,
  774. X         *c= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  775. X    unsigned int mask, i;
  776. X
  777. X    mask=0;
  778. X    for (i=1; i<=(unsigned)bits_per_byte; i++) mask= (mask<<1)|1;
  779. X
  780. X    if (V) {
  781. X        printf("%sCharacter order:%s\n", co, oc);
  782. X        Order(s, ps, "short:");
  783. X        Order(j, pj, "int:  ");
  784. X        Order(l, pl, "long: ");
  785. X    }
  786. X}
  787. X
  788. XProcedure check_defines() {
  789. X    /* ensure that all the #defines are present */
  790. X#ifdef VERIFY
  791. X    if (L) {
  792. X#ifndef CHAR_BIT
  793. X    printf("%s*** CHAR_BIT missing from limits.h%s\n", co, oc); bugs++;
  794. X#endif
  795. X#ifndef CHAR_MAX
  796. X    printf("%s*** CHAR_MAX missing from limits.h%s\n", co, oc); bugs++;
  797. X#endif
  798. X#ifndef CHAR_MIN
  799. X    printf("%s*** CHAR_MIN missing from limits.h%s\n", co, oc); bugs++;
  800. X#endif
  801. X#ifndef SCHAR_MAX
  802. X    printf("%s*** SCHAR_MAX missing from limits.h%s\n", co, oc); bugs++;
  803. X#endif
  804. X#ifndef SCHAR_MIN
  805. X    printf("%s*** SCHAR_MIN missing from limits.h%s\n", co, oc); bugs++;
  806. X#endif
  807. X#ifndef UCHAR_MAX
  808. X    printf("%s*** UCHAR_MAX missing from limits.h%s\n", co, oc); bugs++;
  809. X#endif
  810. X#ifndef SHRT_MAX
  811. X    printf("%s*** SHRT_MAX missing from limits.h%s\n", co, oc); bugs++;
  812. X#endif
  813. X#ifndef SHRT_MIN
  814. X    printf("%s*** SHRT_MIN missing from limits.h%s\n", co, oc); bugs++;
  815. X#endif
  816. X#ifndef INT_MAX
  817. X    printf("%s*** INT_MAX missing from limits.h%s\n", co, oc); bugs++;
  818. X#endif
  819. X#ifndef INT_MIN
  820. X    printf("%s*** INT_MIN missing from limits.h%s\n", co, oc); bugs++;
  821. X#endif
  822. X#ifndef LONG_MAX
  823. X    printf("%s*** LONG_MAX missing from limits.h%s\n", co, oc); bugs++;
  824. X#endif
  825. X#ifndef LONG_MIN
  826. X    printf("%s*** LONG_MIN missing from limits.h%s\n", co, oc); bugs++;
  827. X#endif
  828. X#ifndef USHRT_MAX
  829. X    printf("%s*** USHRT_MAX missing from limits.h%s\n", co, oc); bugs++;
  830. X#endif
  831. X#ifndef UINT_MAX
  832. X    printf("%s*** UINT_MAX missing from limits.h%s\n", co, oc); bugs++;
  833. X#endif
  834. X#ifndef ULONG_MAX
  835. X    printf("%s*** ULONG_MAX missing from limits.h%s\n", co, oc); bugs++;
  836. X#endif
  837. X    } /* if (L) */
  838. X
  839. X    if (F) {
  840. X#ifndef FLT_RADIX
  841. X    printf("%s*** FLT_RADIX missing from float.h%s\n", co, oc); bugs++;
  842. X#endif
  843. X#ifndef FLT_MANT_DIG
  844. X    printf("%s*** FLT_MANT_DIG missing from float.h%s\n", co, oc); bugs++;
  845. X#endif
  846. X#ifndef FLT_DIG
  847. X    printf("%s*** FLT_DIG missing from float.h%s\n", co, oc); bugs++;
  848. X#endif
  849. X#ifndef FLT_ROUNDS
  850. X    printf("%s*** FLT_ROUNDS missing from float.h%s\n", co, oc); bugs++;
  851. X#endif
  852. X#ifndef FLT_EPSILON
  853. X    printf("%s*** FLT_EPSILON missing from float.h%s\n", co, oc); bugs++;
  854. X#endif
  855. X#ifndef FLT_MIN_EXP
  856. X    printf("%s*** FLT_MIN_EXP missing from float.h%s\n", co, oc); bugs++;
  857. X#endif
  858. X#ifndef FLT_MIN
  859. X    printf("%s*** FLT_MIN missing from float.h%s\n", co, oc); bugs++;
  860. X#endif
  861. X#ifndef FLT_MIN_10_EXP
  862. X    printf("%s*** FLT_MIN_10_EXP missing from float.h%s\n", co, oc); bugs++;
  863. X#endif
  864. X#ifndef FLT_MAX_EXP
  865. X    printf("%s*** FLT_MAX_EXP missing from float.h%s\n", co, oc); bugs++;
  866. X#endif
  867. X#ifndef FLT_MAX
  868. X    printf("%s*** FLT_MAX missing from float.h%s\n", co, oc); bugs++;
  869. X#endif
  870. X#ifndef FLT_MAX_10_EXP
  871. X    printf("%s*** FLT_MAX_10_EXP missing from float.h%s\n", co, oc); bugs++;
  872. X#endif
  873. X#ifndef DBL_MANT_DIG
  874. X    printf("%s*** DBL_MANT_DIG missing from float.h%s\n", co, oc); bugs++;
  875. X#endif
  876. X#ifndef DBL_DIG
  877. X    printf("%s*** DBL_DIG missing from float.h%s\n", co, oc); bugs++;
  878. X#endif
  879. X#ifndef DBL_EPSILON
  880. X    printf("%s*** DBL_EPSILON missing from float.h%s\n", co, oc); bugs++;
  881. X#endif
  882. X#ifndef DBL_MIN_EXP
  883. X    printf("%s*** DBL_MIN_EXP missing from float.h%s\n", co, oc); bugs++;
  884. X#endif
  885. X#ifndef DBL_MIN
  886. X    printf("%s*** DBL_MIN missing from float.h%s\n", co, oc); bugs++;
  887. X#endif
  888. X#ifndef DBL_MIN_10_EXP
  889. X    printf("%s*** DBL_MIN_10_EXP missing from float.h%s\n", co, oc); bugs++;
  890. X#endif
  891. X#ifndef DBL_MAX_EXP
  892. X    printf("%s*** DBL_MAX_EXP missing from float.h%s\n", co, oc); bugs++;
  893. X#endif
  894. X#ifndef DBL_MAX
  895. X    printf("%s*** DBL_MAX missing from float.h%s\n", co, oc); bugs++;
  896. X#endif
  897. X#ifndef DBL_MAX_10_EXP
  898. X    printf("%s*** DBL_MAX_10_EXP missing from float.h%s\n", co, oc); bugs++;
  899. X#endif
  900. X#ifdef STDC
  901. X#ifndef LDBL_MANT_DIG
  902. X    printf("%s*** LDBL_MANT_DIG missing from float.h%s\n", co, oc); bugs++;
  903. X#endif
  904. X#ifndef LDBL_DIG
  905. X    printf("%s*** LDBL_DIG missing from float.h%s\n", co, oc); bugs++;
  906. X#endif
  907. X#ifndef LDBL_EPSILON
  908. X    printf("%s*** LDBL_EPSILON missing from float.h%s\n", co, oc); bugs++;
  909. X#endif
  910. X#ifndef LDBL_MIN_EXP
  911. X    printf("%s*** LDBL_MIN_EXP missing from float.h%s\n", co, oc); bugs++;
  912. X#endif
  913. X#ifndef LDBL_MIN
  914. X    printf("%s*** LDBL_MIN missing from float.h%s\n", co, oc); bugs++;
  915. X#endif
  916. X#ifndef LDBL_MIN_10_EXP
  917. X    printf("%s*** LDBL_MIN_10_EXP missing from float.h%s\n", co, oc); bugs++;
  918. X#endif
  919. X#ifndef LDBL_MAX_EXP
  920. X    printf("%s*** LDBL_MAX_EXP missing from float.h%s\n", co, oc); bugs++;
  921. X#endif
  922. X#ifndef LDBL_MAX
  923. X    printf("%s*** LDBL_MAX missing from float.h%s\n", co, oc); bugs++;
  924. X#endif
  925. X#ifndef LDBL_MAX_10_EXP
  926. X    printf("%s*** LDBL_MAX_10_EXP missing from float.h%s\n", co, oc); bugs++;
  927. X#endif
  928. X#endif /* STDC */
  929. X    } /* if (F) */
  930. X#endif /* VERIFY */
  931. X}
  932. X
  933. X#ifdef VERIFY
  934. X#ifndef SCHAR_MAX
  935. X#define SCHAR_MAX    char_max
  936. X#endif
  937. X#ifndef SCHAR_MIN
  938. X#define SCHAR_MIN    char_min
  939. X#endif
  940. X#ifndef UCHAR_MAX
  941. X#define UCHAR_MAX    char_max
  942. X#endif
  943. X#endif /* VERIFY */
  944. X
  945. X#ifndef CHAR_BIT
  946. X#define CHAR_BIT    char_bit
  947. X#endif
  948. X#ifndef CHAR_MAX
  949. X#define CHAR_MAX    char_max
  950. X#endif
  951. X#ifndef CHAR_MIN
  952. X#define CHAR_MIN    char_min
  953. X#endif
  954. X#ifndef SCHAR_MAX
  955. X#define SCHAR_MAX    char_max
  956. X#endif
  957. X#ifndef SCHAR_MIN
  958. X#define SCHAR_MIN    char_min
  959. X#endif
  960. X#ifndef UCHAR_MAX
  961. X#define UCHAR_MAX    char_max
  962. X#endif
  963. X
  964. Xint cprop() {
  965. X    /* Properties of type char */
  966. X    Volatile char c, char_max, char_min;
  967. X    Volatile int bits_per_byte, is_signed;
  968. X    long char_bit;
  969. X
  970. X    Unexpected(2);
  971. X
  972. X    /* Calculate number of bits per character *************************/
  973. X    c=1; bits_per_byte=0;
  974. X    do { c=c<<1; bits_per_byte++; } while(c!=0);
  975. X    c= (char)(-1);
  976. X    if (((int)c)<0) is_signed=1;
  977. X    else is_signed=0;
  978. X    Vprintf("%sChar = %d bits, %ssigned%s\n",
  979. X        co, (int)sizeof(c)*bits_per_byte, (is_signed?"":"un"), oc);
  980. X    char_bit=(long)(sizeof(c)*bits_per_byte);
  981. X    if (L) i_define(D_CHAR_BIT, "",
  982. X            "CHAR", "_BIT", char_bit, (long) CHAR_BIT, "");
  983. X
  984. X    c=0; char_max=0;
  985. X    c++;
  986. X    if (setjmp(lab)==0) { /* Yields char_max */
  987. X        while (c>char_max) {
  988. X            char_max=c;
  989. X            c++;
  990. X        }
  991. X    } else {
  992. X        Vprintf("%sCharacter overflow generates a trap!%s\n", co, oc);
  993. X    }
  994. X    c=0; char_min=0;
  995. X    c--;
  996. X    if (setjmp(lab)==0) { /* Yields char_min */
  997. X        while (c<char_min) {
  998. X            char_min=c;
  999. X            c--;
  1000. X        }
  1001. X    }
  1002. X    if (is_signed && char_min == 0) {
  1003. X        Vprintf("%sBEWARE! Chars are pseudo-unsigned:%s\n", co, oc);
  1004. X        Vprintf("%s   %s%s%s\n",
  1005. X            "They contain only nonnegative values, ",
  1006. X            "but sign extend when used as integers.", co, oc);
  1007. X    }
  1008. X    Unexpected(3);
  1009. X
  1010. X    if (L) {
  1011. X        i_define(D_CHAR_MAX, "",
  1012. X             "CHAR", "_MAX", (long) char_max, (long) CHAR_MAX, "");
  1013. X        i_define(D_CHAR_MIN, "",
  1014. X             "CHAR", "_MIN", (long) char_min, (long) CHAR_MIN, "");
  1015. X        if (is_signed) {
  1016. X            i_define(D_SCHAR_MAX, "",
  1017. X                 "SCHAR", "_MAX", (long) char_max,
  1018. X                 (long) SCHAR_MAX, "");
  1019. X            i_define(D_SCHAR_MIN, "",
  1020. X                 "SCHAR", "_MIN", (long) char_min,
  1021. X                 (long) SCHAR_MIN, "");
  1022. X        } else {
  1023. X            i_define(D_UCHAR_MAX, "",
  1024. X                 "UCHAR", "_MAX", (long) char_max,
  1025. X                 (long) UCHAR_MAX, "");
  1026. X        }
  1027. X
  1028. X        if (is_signed) {
  1029. X#ifndef NO_UC
  1030. X            Volatile unsigned char c, char_max;
  1031. X            c=0; char_max=0;
  1032. X            c++;
  1033. X            if (setjmp(lab)==0) { /* Yields char_max */
  1034. X                while (c>char_max) {
  1035. X                    char_max=c;
  1036. X                    c++;
  1037. X                }
  1038. X            }
  1039. X            Unexpected(4);
  1040. X            i_define(D_UCHAR_MAX, "",
  1041. X                 "UCHAR", "_MAX", (long) char_max,
  1042. X                 (long) UCHAR_MAX, "");
  1043. X#endif
  1044. X        } else {
  1045. X#ifndef NO_SC /* Define NO_SC if the next line gives a syntax error */
  1046. X            Volatile signed char c, char_max, char_min;
  1047. X            c=0; char_max=0;
  1048. X            c++;
  1049. X            if (setjmp(lab)==0) { /* Yields char_max */
  1050. X                while (c>char_max) {
  1051. X                    char_max=c;
  1052. X                    c++;
  1053. X                }
  1054. X            }
  1055. X            c=0; char_min=0;
  1056. X            c--;
  1057. X            if (setjmp(lab)==0) { /* Yields char_min */
  1058. X                while (c<char_min) {
  1059. X                    char_min=c;
  1060. X                    c--;
  1061. X                }
  1062. X            }
  1063. X            Unexpected(5);
  1064. X            i_define(D_SCHAR_MIN, "",
  1065. X                 "SCHAR", "_MIN", (long) char_min,
  1066. X                 (long) SCHAR_MIN, "");
  1067. X            i_define(D_SCHAR_MAX, "",
  1068. X                 "SCHAR", "_MAX", (long) char_max,
  1069. X                 (long) SCHAR_MAX, "");
  1070. X#endif /* NO_SC */
  1071. X        }
  1072. X    }
  1073. X    return bits_per_byte;
  1074. X}
  1075. X
  1076. Xint basic() {
  1077. X    /* The properties of the basic types.
  1078. X       Returns number of bits per sizeof unit */
  1079. X    Volatile int bits_per_byte;
  1080. X    struct{char i1; char c1;} schar;
  1081. X    struct{short i2; char c2;} sshort;
  1082. X    struct{int i3; char c3;} sint;
  1083. X    struct{long i4; char c4;} slong;
  1084. X
  1085. X    bits_per_byte= cprop();
  1086. X
  1087. X    /* Shorts, ints and longs *****************************************/
  1088. X    Vprintf("%sShort=%d int=%d long=%d float=%d double=%d bits %s\n",
  1089. X        co,
  1090. X        (int) sizeof(short)*bits_per_byte,
  1091. X        (int) sizeof(int)*bits_per_byte,
  1092. X        (int) sizeof(long)*bits_per_byte,
  1093. X        (int) sizeof(float)*bits_per_byte,
  1094. X        (int) sizeof(double)*bits_per_byte, oc);
  1095. X    if (stdc) {
  1096. X        Vprintf("%sLong double=%d bits%s\n",
  1097. X            co, (int) sizeof(Long_double)*bits_per_byte, oc);
  1098. X    }
  1099. X    Vprintf("%sChar pointers = %d bits%s%s\n",
  1100. X        co, (int)sizeof(char *)*bits_per_byte,
  1101. X        sizeof(char *)>sizeof(int)?" BEWARE! larger than int!":"",
  1102. X        oc);
  1103. X    Vprintf("%sInt pointers = %d bits%s%s\n",
  1104. X        co, (int)sizeof(int *)*bits_per_byte,
  1105. X        sizeof(int *)>sizeof(int)?" BEWARE! larger than int!":"",
  1106. X        oc);
  1107. X
  1108. X    /* Alignment constants ********************************************/
  1109. X    Vprintf("%sAlignments used for char=%ld short=%ld int=%ld long=%ld%s\n",
  1110. X        co,
  1111. X        ((long)&schar.c1)-((long)&schar.i1),
  1112. X        ((long)&sshort.c2)-((long)&sshort.i2),
  1113. X        ((long)&sint.c3)-((long)&sint.i3),
  1114. X        ((long)&slong.c4)-((long)&slong.i4),
  1115. X        oc);
  1116. X
  1117. X    /* Ten little endians *********************************************/
  1118. X
  1119. X    endian(bits_per_byte);
  1120. X
  1121. X    /* Pointers *******************************************************/
  1122. X    if (V) {
  1123. X        if ("abcd"=="abcd")
  1124. X            printf("%sStrings are shared%s\n", co, oc);
  1125. X        else printf("%sStrings are not shared%s\n", co, oc);
  1126. X    }
  1127. X
  1128. X    sprop();
  1129. X    iprop();
  1130. X    lprop();
  1131. X    usprop();
  1132. X    uiprop();
  1133. X    ulprop();
  1134. X
  1135. X    Unexpected(6);
  1136. X
  1137. X    return bits_per_byte;
  1138. X}
  1139. X
  1140. X#else /* not PASS0 */
  1141. X
  1142. X#ifdef SEP
  1143. Xextern jmp_buf lab;
  1144. Xextern int V, L, F, bugs, bits_per_byte;
  1145. Xextern char co[], oc[];
  1146. Xextern char *f_rep();
  1147. X#endif /* SEP */
  1148. X#endif /* ifdef PASS0 */
  1149. X
  1150. X/* As I said, I apologise for the contortions below. The functions are
  1151. X   expanded by the preprocessor twice or three times (for float and double,
  1152. X   and maybe for long double, and for short, int and long). That way,
  1153. X   I never make a change to one that I forget to make to the other.
  1154. X   You can look on it as C's fault for not supporting multi-line macro's.
  1155. X   This whole file is read 3 times by the preprocessor, with PASSn set for
  1156. X   n=1, 2 or 3, to decide which parts to reprocess.
  1157. X*/
  1158. X
  1159. X/* #undef on an already undefined thing is (wrongly) flagged as an error
  1160. X   by some compilers, therefore the #ifdef that follows: 
  1161. X*/
  1162. X#ifdef Number
  1163. X#undef Number
  1164. X#undef THING
  1165. X#undef Thing
  1166. X#undef thing
  1167. X#undef FPROP
  1168. X#undef Fname
  1169. X#undef Store
  1170. X#undef Sum
  1171. X#undef Diff
  1172. X#undef Mul
  1173. X#undef Div
  1174. X#undef ZERO
  1175. X#undef HALF
  1176. X#undef ONE
  1177. X#undef TWO
  1178. X#undef THREE
  1179. X#undef FOUR
  1180. X#undef Self
  1181. X#undef F_check
  1182. X#undef Validate
  1183. X#undef EPROP
  1184. X#undef MARK
  1185. X
  1186. X/* These are the float.h constants */
  1187. X#undef F_RADIX
  1188. X#undef F_MANT_DIG
  1189. X#undef F_DIG
  1190. X#undef F_ROUNDS
  1191. X#undef F_EPSILON
  1192. X#undef F_MIN_EXP
  1193. X#undef F_MIN
  1194. X#undef F_MIN_10_EXP
  1195. X#undef F_MAX_EXP
  1196. X#undef F_MAX
  1197. X#undef F_MAX_10_EXP
  1198. X#endif
  1199. X
  1200. X#ifdef Integer
  1201. X#undef Integer
  1202. X#undef INT
  1203. X#undef IPROP
  1204. X#undef Iname
  1205. X#undef UPROP
  1206. X#undef Uname
  1207. X#undef OK_UI
  1208. X#undef IMARK
  1209. X
  1210. X#undef I_MAX
  1211. X#undef I_MIN
  1212. X#undef U_MAX
  1213. X#endif
  1214. X
  1215. X#ifdef PASS1
  1216. X
  1217. X/* Define the things we're going to use this pass */
  1218. X
  1219. X#define Number    float
  1220. X#define THING    "FLOAT"
  1221. X#define Thing    "Float"
  1222. X#define thing    "float"
  1223. X#define Fname    "FLT"
  1224. X#define FPROP    fprop
  1225. X#define Store    fStore
  1226. X#define Sum    fSum
  1227. X#define Diff    fDiff
  1228. X#define Mul    fMul
  1229. X#define Div    fDiv
  1230. X#define ZERO    0.0
  1231. X#define HALF    0.5
  1232. X#define ONE    1.0
  1233. X#define TWO    2.0
  1234. X#define THREE    3.0
  1235. X#define FOUR    4.0
  1236. X#define Self    fSelf
  1237. X#define F_check    fCheck
  1238. X#define MARK    "F"
  1239. X#ifdef VERIFY
  1240. X#define Validate(prec, val, req, same) fValidate(prec, val, req, same)
  1241. X#endif
  1242. X
  1243. X#define EPROP    efprop
  1244. X
  1245. X#define Integer    short
  1246. X#define INT    "short"
  1247. X#define IPROP    sprop
  1248. X#define Iname    "SHRT"
  1249. X#ifndef NO_UI
  1250. X#define OK_UI 1
  1251. X#endif
  1252. X#define IMARK    ""
  1253. X
  1254. X#define UPROP    usprop
  1255. X#define Uname    "USHRT"
  1256. X
  1257. X#ifdef VERIFY
  1258. X#ifdef SHRT_MAX
  1259. X#define I_MAX        SHRT_MAX
  1260. X#endif
  1261. X#ifdef SHRT_MIN
  1262. X#define I_MIN        SHRT_MIN
  1263. X#endif
  1264. X#ifdef USHRT_MAX
  1265. X#define U_MAX        USHRT_MAX
  1266. X#endif
  1267. X
  1268. X#ifdef FLT_RADIX
  1269. X#define F_RADIX        FLT_RADIX
  1270. X#endif
  1271. X#ifdef FLT_MANT_DIG
  1272. X#define F_MANT_DIG    FLT_MANT_DIG
  1273. X#endif
  1274. X#ifdef FLT_DIG
  1275. X#define F_DIG        FLT_DIG
  1276. X#endif
  1277. X#ifdef FLT_ROUNDS
  1278. X#define F_ROUNDS    FLT_ROUNDS
  1279. X#endif
  1280. X#ifdef FLT_EPSILON
  1281. X#define F_EPSILON    FLT_EPSILON
  1282. X#endif
  1283. X#ifdef FLT_MIN_EXP
  1284. X#define F_MIN_EXP    FLT_MIN_EXP
  1285. X#endif
  1286. X#ifdef FLT_MIN
  1287. X#define F_MIN        FLT_MIN
  1288. X#endif
  1289. X#ifdef FLT_MIN_10_EXP
  1290. X#define F_MIN_10_EXP    FLT_MIN_10_EXP
  1291. X#endif
  1292. X#ifdef FLT_MAX_EXP
  1293. X#define F_MAX_EXP    FLT_MAX_EXP
  1294. X#endif
  1295. X#ifdef FLT_MAX
  1296. X#define F_MAX        FLT_MAX
  1297. X#endif
  1298. X#ifdef FLT_MAX_10_EXP
  1299. X#define F_MAX_10_EXP    FLT_MAX_10_EXP
  1300. X#endif
  1301. X#endif /* VERIFY */
  1302. X
  1303. X#endif /* PASS1 */
  1304. X
  1305. X#ifdef PASS2
  1306. X
  1307. X#define Number    double
  1308. X#define THING    "DOUBLE"
  1309. X#define Thing    "Double"
  1310. X#define thing    "double"
  1311. X#define Fname    "DBL"
  1312. X#define FPROP    dprop
  1313. X#define Store    dStore
  1314. X#define Sum    dSum
  1315. X#define Diff    dDiff
  1316. X#define Mul    dMul
  1317. X#define Div    dDiv
  1318. X#define ZERO    0.0
  1319. X#define HALF    0.5
  1320. X#define ONE    1.0
  1321. X#define TWO    2.0
  1322. X#define THREE    3.0
  1323. X#define FOUR    4.0
  1324. X#define Self    dSelf
  1325. X#define F_check    dCheck
  1326. X#define MARK    ""
  1327. X#ifdef VERIFY
  1328. X#define Validate(prec, val, req, same) dValidate(prec, val, req, same)
  1329. X#endif
  1330. X
  1331. X#define EPROP    edprop
  1332. X
  1333. X#define Integer    int
  1334. X#define INT    "int"
  1335. X#define IPROP    iprop
  1336. X#define Iname    "INT"
  1337. X#define OK_UI    1 /* Unsigned int is always possible */
  1338. X#define IMARK    ""
  1339. X
  1340. X#define UPROP    uiprop
  1341. X#define Uname    "UINT"
  1342. X
  1343. X#ifdef VERIFY
  1344. X#ifdef INT_MAX
  1345. X#define I_MAX        INT_MAX
  1346. X#endif
  1347. X#ifdef INT_MIN
  1348. X#define I_MIN        INT_MIN
  1349. X#endif
  1350. X#ifdef UINT_MAX
  1351. X#define U_MAX        UINT_MAX
  1352. X#endif
  1353. X
  1354. X#ifdef DBL_MANT_DIG
  1355. X#define F_MANT_DIG    DBL_MANT_DIG
  1356. X#endif
  1357. X#ifdef DBL_DIG
  1358. X#define F_DIG        DBL_DIG
  1359. X#endif
  1360. X#ifdef DBL_EPSILON
  1361. X#define F_EPSILON    DBL_EPSILON
  1362. X#endif
  1363. X#ifdef DBL_MIN_EXP
  1364. X#define F_MIN_EXP    DBL_MIN_EXP
  1365. X#endif
  1366. X#ifdef DBL_MIN
  1367. X#define F_MIN        DBL_MIN
  1368. X#endif
  1369. X#ifdef DBL_MIN_10_EXP
  1370. X#define F_MIN_10_EXP    DBL_MIN_10_EXP
  1371. X#endif
  1372. X#ifdef DBL_MAX_EXP
  1373. X#define F_MAX_EXP    DBL_MAX_EXP
  1374. X#endif
  1375. X#ifdef DBL_MAX
  1376. X#define F_MAX        DBL_MAX
  1377. X#endif
  1378. X#ifdef DBL_MAX_10_EXP
  1379. X#define F_MAX_10_EXP    DBL_MAX_10_EXP
  1380. X#endif
  1381. X#endif /* VERIFY */
  1382. X
  1383. X#endif /* PASS2 */
  1384. X
  1385. X#ifdef PASS3
  1386. X
  1387. X#ifdef STDC
  1388. X#define Number    long double
  1389. X#endif
  1390. X
  1391. X#define THING    "LONG DOUBLE"
  1392. X#define Thing    "Long double"
  1393. X#define thing    "long double"
  1394. X#define Fname    "LDBL"
  1395. X#define FPROP    ldprop
  1396. X#define Store    ldStore
  1397. X#define Sum    ldSum
  1398. X#define Diff    ldDiff
  1399. X#define Mul    ldMul
  1400. X#define Div    ldDiv
  1401. X#define ZERO    0.0L
  1402. X#define HALF    0.5L
  1403. X#define ONE    1.0L
  1404. X#define TWO    2.0L
  1405. X#define THREE    3.0L
  1406. X#define FOUR    4.0L
  1407. X#define Self    ldSelf
  1408. X#define F_check    ldCheck
  1409. X#define MARK    "L"
  1410. X#ifdef VERIFY
  1411. X#define Validate(prec, val, req, same) ldValidate(prec, val, req, same)
  1412. X#endif
  1413. X
  1414. X#define EPROP    eldprop
  1415. X
  1416. X#define Integer    long
  1417. X#define INT    "long"
  1418. X#define IPROP    lprop
  1419. X#define Iname    "LONG"
  1420. X#ifndef NO_UI
  1421. X#define OK_UI    1
  1422. X#endif
  1423. X#define IMARK    "L"
  1424. X
  1425. X#define UPROP    ulprop
  1426. X#define Uname    "ULONG"
  1427. X
  1428. X#ifdef VERIFY
  1429. X#ifdef LONG_MAX
  1430. X#define I_MAX    LONG_MAX
  1431. X#endif
  1432. X#ifdef LONG_MIN
  1433. X#define I_MIN    LONG_MIN
  1434. X#endif
  1435. X#ifdef ULONG_MAX
  1436. X#define U_MAX    ULONG_MAX
  1437. X#endif
  1438. X
  1439. X#ifdef LDBL_MANT_DIG
  1440. X#define F_MANT_DIG    LDBL_MANT_DIG
  1441. X#endif
  1442. X#ifdef LDBL_DIG
  1443. X#define F_DIG        LDBL_DIG
  1444. X#endif
  1445. X#ifdef LDBL_EPSILON
  1446. X#define F_EPSILON    LDBL_EPSILON
  1447. X#endif
  1448. X#ifdef LDBL_MIN_EXP
  1449. X#define F_MIN_EXP    LDBL_MIN_EXP
  1450. X#endif
  1451. X#ifdef LDBL_MIN
  1452. X#define F_MIN        LDBL_MIN
  1453. X#endif
  1454. X#ifdef LDBL_MIN_10_EXP
  1455. X#define F_MIN_10_EXP    LDBL_MIN_10_EXP
  1456. X#endif
  1457. X#ifdef LDBL_MAX_EXP
  1458. X#define F_MAX_EXP    LDBL_MAX_EXP
  1459. X#endif
  1460. X#ifdef LDBL_MAX
  1461. X#define F_MAX        LDBL_MAX
  1462. X#endif
  1463. X#ifdef LDBL_MAX_10_EXP
  1464. X#define F_MAX_10_EXP    LDBL_MAX_10_EXP
  1465. X#endif
  1466. X#endif /* VERIFY */
  1467. X
  1468. X#endif /* PASS3 */
  1469. X
  1470. X#ifndef I_MAX
  1471. X#define I_MAX    int_max
  1472. X#endif
  1473. X#ifndef I_MIN
  1474. X#define I_MIN    int_min
  1475. X#endif
  1476. X#ifndef U_MAX
  1477. X#define U_MAX    int_max
  1478. X#endif
  1479. X
  1480. X#ifndef F_RADIX
  1481. X#define F_RADIX        f_radix
  1482. X#endif
  1483. X#ifndef F_MANT_DIG
  1484. X#define F_MANT_DIG    f_mant_dig
  1485. X#endif
  1486. X#ifndef F_DIG
  1487. X#define F_DIG        f_dig
  1488. X#endif
  1489. X#ifndef F_ROUNDS
  1490. X#define F_ROUNDS    f_rounds
  1491. X#endif
  1492. X#ifndef F_EPSILON
  1493. X#define F_EPSILON    f_epsilon
  1494. X#endif
  1495. X#ifndef F_MIN_EXP
  1496. X#define F_MIN_EXP    f_min_exp
  1497. X#endif
  1498. X#ifndef F_MIN
  1499. X#define F_MIN        f_min
  1500. X#endif
  1501. X#ifndef F_MIN_10_EXP
  1502. X#define F_MIN_10_EXP    f_min_10_exp
  1503. X#endif
  1504. X#ifndef F_MAX_EXP
  1505. X#define F_MAX_EXP    f_max_exp
  1506. X#endif
  1507. X#ifndef F_MAX
  1508. X#define F_MAX        f_max
  1509. X#endif
  1510. X#ifndef F_MAX_10_EXP
  1511. X#define F_MAX_10_EXP    f_max_10_exp
  1512. X#endif
  1513. X
  1514. X#ifndef VERIFY
  1515. X#define Validate(prec, val, req, same) {;}
  1516. X#endif
  1517. X
  1518. X#ifdef Integer
  1519. X
  1520. XProcedure IPROP() {
  1521. X    /* the properties of short, int, and long */
  1522. X    Volatile Integer newi, int_max, maxeri, int_min, minneri;
  1523. X    Volatile int ibits, ipower, two=2;
  1524. X
  1525. X    /* Calculate max short/int/long ***********************************/
  1526. X    /* Calculate 2**n-1 until overflow - then use the previous value  */
  1527. X
  1528. X    newi=1; int_max=0;
  1529. X
  1530. X    if (setjmp(lab)==0) { /* Yields int_max */
  1531. X        for(ipower=0; newi>int_max; ipower++) {
  1532. X            int_max=newi;
  1533. X            newi=newi*two+1;
  1534. X        }
  1535. X        Vprintf("%sOverflow of a%s %s does not generate a trap%s\n",
  1536. X            co, INT[0]=='i'?"n":"", INT, oc);
  1537. X    } else {
  1538. X        Vprintf("%sOverflow of a%s %s generates a trap%s\n",
  1539. X            co, INT[0]=='i'?"n":"", INT, oc);
  1540. X    }
  1541. X    Unexpected(7);
  1542. X
  1543. X    /* Minimum value: assume either two's or one's complement *********/
  1544. X    int_min= -int_max;
  1545. X    if (setjmp(lab)==0) { /* Yields int_min */
  1546. X        if (int_min-1 < int_min) int_min--;
  1547. X    }
  1548. X    Unexpected(8);
  1549. X
  1550. X    /* Now for those daft Cybers: */
  1551. X
  1552. X    maxeri=0; newi=int_max;
  1553. X
  1554. X    if (setjmp(lab)==0) { /* Yields maxeri */
  1555. X        for(ibits=ipower; newi>maxeri; ibits++) {
  1556. X            maxeri=newi;
  1557. X            newi=newi+newi+1;
  1558. X        }
  1559. X    }
  1560. X    Unexpected(9);
  1561. X
  1562. X    minneri= -maxeri;
  1563. X    if (setjmp(lab)==0) { /* Yields minneri */
  1564. X        if (minneri-1 < minneri) minneri--;
  1565. X    }
  1566. X    Unexpected(10);
  1567. X
  1568. X    Vprintf("%sMaximum %s = %ld (= 2**%d-1)%s\n",
  1569. X        co, INT, (long)int_max, ipower, oc);
  1570. X    Vprintf("%sMinimum %s = %ld%s\n", co, INT, (long)int_min, oc);
  1571. X
  1572. X    if (L) i_define(D_INT_MAX, INT,
  1573. X            Iname, "_MAX", (long) int_max, (long) I_MAX, IMARK);
  1574. X    if (L) i_define(D_INT_MIN, INT,
  1575. X            Iname, "_MIN", (long) int_min, (long) I_MIN, IMARK);
  1576. X
  1577. X    if (maxeri>int_max) {
  1578. X        Vprintf("%sThere is a larger %s, %ld (= 2**%d-1), %s %s%s\n",
  1579. X            co, INT, (long)maxeri, ibits, 
  1580. X            "but only for addition, not multiplication",
  1581. X            "(I smell a Cyber!)",
  1582. X            oc);
  1583. X    }
  1584. X
  1585. X    if (minneri<int_min) {
  1586. X        Vprintf("%sThere is a smaller %s, %ld, %s %s%s\n",
  1587. X            co, INT, (long)minneri, 
  1588. X            "but only for addition, not multiplication",
  1589. X            "(I smell a Cyber!)",
  1590. X            oc);
  1591. X    }
  1592. X}
  1593. X
  1594. XProcedure UPROP () {
  1595. X    /* The properties of unsigned short/int/long */
  1596. X#ifdef OK_UI
  1597. X    Volatile unsigned Integer int_max, newi, two;
  1598. X    newi=1; int_max=0; two=2;
  1599. X
  1600. X    if (setjmp(lab)==0) { /* Yields int_max */
  1601. X        while(newi>int_max) {
  1602. X            int_max=newi;
  1603. X            newi=newi*two+1;
  1604. X        }
  1605. X    }
  1606. X    Unexpected(11);
  1607. X    Vprintf("%sMaximum unsigned %s = %lu%s\n",
  1608. X        co, INT, (unsigned long) int_max, oc);
  1609. X    if (L) u_define(D_UINT_MAX, INT,
  1610. X            Uname, "_MAX", (unsigned long) int_max,
  1611. X            (unsigned long) U_MAX, IMARK);
  1612. X#endif
  1613. X}
  1614. X
  1615. X#endif /* Integer */
  1616. X
  1617. X#ifdef Number
  1618. X
  1619. X/* The following routines are intended to defeat any attempt at optimisation
  1620. X   or use of extended precision, and to defeat faulty narrowing casts.
  1621. X   The weird prototypes are because of widening incompatibilities.
  1622. X*/
  1623. X#ifdef STDC
  1624. X#define ARGS1(atype, a) (atype a)
  1625. X#define ARGS2(atype, a, btype, b) (atype a, btype b)
  1626. X#else
  1627. X#define ARGS1(atype, a) (a) atype a;
  1628. X#define ARGS2(atype, a, btype, b) (a, b) atype a; btype b;
  1629. X#endif
  1630. X
  1631. XProcedure Store ARGS2(Number, a, Number *, b) { *b=a; }
  1632. XNumber Sum ARGS2(Number, a, Number, b) {Number r; Store(a+b, &r); return (r); }
  1633. XNumber Diff ARGS2(Number, a, Number, b){Number r; Store(a-b, &r); return (r); }
  1634. XNumber Mul ARGS2(Number, a, Number, b) {Number r; Store(a*b, &r); return (r); }
  1635. XNumber Div ARGS2(Number, a, Number, b) {Number r; Store(a/b, &r); return (r); }
  1636. XNumber Self ARGS1(Number, a)           {Number r; Store(a,   &r); return (r); }
  1637. X
  1638. XProcedure F_check ARGS((int precision, Long_double val1));
  1639. X
  1640. XProcedure F_check(precision, val1) int precision; Long_double val1; {
  1641. X    /* You don't think I'm going to go to all the trouble of writing
  1642. X       a program that works out what all sorts of values are, only to
  1643. X       have printf go and print the wrong values out, do you?
  1644. X       No, you're right, so this function tries to see if printf
  1645. X       has written the right value, by reading it back again.
  1646. X       This introduces a new problem of course: suppose printf writes
  1647. X       the correct value, and scanf reads it back wrong... oh well.
  1648. X       But I'm adamant about this: the precision given is enough
  1649. X       to uniquely identify the printed number, therefore I insist
  1650. X       that sscanf read the number back identically. Harsh yes, but
  1651. X       sometimes you've got to be cruel to be kind.
  1652. X    */
  1653. X    Long_double new1;
  1654. X    Number val, new, diff;
  1655. X    double rem;
  1656. X    int e;
  1657. X    char *rep;
  1658. X    char *f2;
  1659. X
  1660. X    if (sizeof(double) == sizeof(Long_double)) {
  1661. X        /* Assume they're the same, and use non-stdc format */
  1662. X        /* This is for stdc compilers using non-stdc libraries */
  1663. X        f2= "%le";   /* Input */
  1664. X    } else {
  1665. X        /* It had better support Le then */
  1666. X        f2= "%Le";
  1667. X    }
  1668. X    val= val1;
  1669. X    rep= f_rep(precision, (Long_double) val);
  1670. X    if (setjmp(lab)==0) {
  1671. X        sscanf(rep, f2, &new1);
  1672. X    } else {
  1673. X        eek_a_bug("sscanf caused a trap");
  1674. X        printf("%s    scanning: %s format: %s%s\n\n", co, rep, f2, oc);
  1675. X        Unexpected(12);
  1676. X        return;
  1677. X    }
  1678. X
  1679. X    if (setjmp(lab)==0) { /* See if new is usable */
  1680. X        new= new1;
  1681. X        if (new != 0.0) {
  1682. X            diff= val/new - 1.0;
  1683. X            if (diff < 0.1) diff= 1.0;
  1684. X            /* That should be enough to generate a trap */
  1685. X        }
  1686. X    } else {
  1687. X        eek_a_bug("sscanf returned an unusable number");
  1688. X        printf("%s    scanning: %s with format: %s%s\n\n",
  1689. X               co, rep, f2, oc);
  1690. X        Unexpected(13);
  1691. X        return;
  1692. X    }
  1693. X
  1694. X    Unexpected(14);
  1695. X    if (new != val) {
  1696. X        eek_a_bug("Possibly bad output from printf above");
  1697. X        if (!exponent((Long_double)val, &rem, &e)) {
  1698. X            printf("%s    but value was an unusable number%s\n\n",
  1699. X                   co, oc);
  1700. X            return;
  1701. X        }
  1702. X        printf("%s    expected value around %.*fe%d, bit pattern:\n    ",
  1703. X               co, precision, rem, e);
  1704. X        bitpattern((char *) &val, sizeof(val));
  1705. X        printf ("%s\n", oc);
  1706. X        printf("%s    sscanf gave           %s, bit pattern:\n    ",
  1707. X               co, f_rep(precision, (Long_double) new));
  1708. X        bitpattern((char *) &new, sizeof(new));
  1709. X        printf ("%s\n", oc);
  1710. X        if (setjmp(lab) == 0) {
  1711. X            diff= val-new;
  1712. X            printf("%s    difference= %s%s\n\n", 
  1713. X                   co, f_rep(precision, (Long_double) diff), oc);
  1714. X        } /* else forget it */
  1715. X        Unexpected(15);
  1716. X    }
  1717. X}
  1718. X
  1719. X#ifdef VERIFY
  1720. XProcedure Validate(prec, val, req, same) int prec, same; Long_double val, req; {
  1721. X    /* Check that the compiler has read a #define value correctly */
  1722. X    Unexpected(16);
  1723. X    if (!same) {
  1724. X        printf("%s*** Verify failed for above #define!\n", co);
  1725. X        if (setjmp(lab) == 0) { /* for the case that req == nan */
  1726. X            printf("       Compiler has %s for value%s\n", 
  1727. X                   f_rep(prec, req), oc);
  1728. X        } else {
  1729. X            printf("       Compiler has %s for value%s\n",
  1730. X                   "an unusable number", oc);
  1731. X        }
  1732. X        if (setjmp(lab) == 0) {
  1733. X            F_check(prec, (Long_double) req);
  1734. X        } /*else forget it*/
  1735. X        if (setjmp(lab) == 0) {        
  1736. X            if (req > 0.0 && val > 0.0) {
  1737. X                printf("%s    difference= %s%s\n",
  1738. X                       co, f_rep(prec, val-req), oc);
  1739. X            }
  1740. X        } /*else forget it*/
  1741. X        Unexpected(17);
  1742. X        printf("\n");
  1743. X        bugs++;
  1744. X    } else if (val != req) {
  1745. X        if (stdc) {
  1746. X            printf("%s*** Verify failed for above #define!\n", co);
  1747. X            printf("       Constant has the wrong precision%s\n",
  1748. X                   oc);
  1749. X        } else eek_a_bug("the cast didn't work");
  1750. X        printf("\n");
  1751. X        bugs++;
  1752. X    }
  1753. X}
  1754. X#endif /* VERIFY */
  1755. X
  1756. Xint FPROP(bits_per_byte) int bits_per_byte; {
  1757. X    /* Properties of floating types, using algorithms by Cody and Waite
  1758. X       from MA Malcolm, as modified by WM Gentleman and SB Marovich.
  1759. X       Further extended by S Pemberton.
  1760. X
  1761. X       Returns the number of digits in the fraction.
  1762. X    */
  1763. X
  1764. X    Volatile int
  1765. X        i, f_radix, iexp, irnd, mrnd, f_rounds, f_mant_dig,
  1766. X        iz, k, inf, machep, f_max_exp, f_min_exp, mx, negeps,
  1767. X        mantbits, digs, f_dig, trap,
  1768. X        hidden, normal, f_min_10_exp, f_max_10_exp;
  1769. X    Volatile Number
  1770. X        a, b, base, basein, basem1, f_epsilon, epsneg,
  1771. X        eps, epsp1, etop, ebot,
  1772. X        f_max, newxmax, f_min, xminner, y, y1, z, z1, z2;
  1773. X
  1774. X    Unexpected(18);
  1775. X
  1776. X    Vprintf("%sPROPERTIES OF %s:%s\n", co, THING, oc);
  1777. X
  1778. X    /* Base and size of mantissa **************************************/
  1779. X    /* First repeatedly double until adding 1 has no effect.      */
  1780. X    /* For instance, if base is 10, with 3 significant digits      */
  1781. X    /* it will try 1, 2, 4, 8, ... 512, 1024, and stop there,      */
  1782. X    /* since 1024 is only representable as 1020.              */
  1783. X    a=1.0;
  1784. X    if (setjmp(lab)==0) { /* inexact trap? */
  1785. X        do { a=Sum(a, a); }
  1786. X        while (Diff(Diff(Sum(a, ONE), a), ONE) == ZERO);
  1787. X    } else {
  1788. X        fprintf(stderr, "*** Program got loss-of-precision trap!\n");
  1789. X        /* And supporting those is just TOO much trouble! */
  1790. X        farewell(bugs+1);
  1791. X    }
  1792. X    Unexpected(19);
  1793. X    /* Now double until you find a number that can be added to the      */
  1794. X    /* above number. For 1020 this is 8 or 16, depending whether the  */
  1795. X    /* result is rounded or truncated.                  */
  1796. X    /* In either case the result is 1030. 1030-1020= the base, 10.      */
  1797. X    b=1.0;
  1798. X    do { b=Sum(b, b); } while ((base=Diff(Sum(a, b), a)) == ZERO);
  1799. X    f_radix=base;
  1800. X    Vprintf("%sBase = %d%s\n", co, f_radix, oc);
  1801. X
  1802. X    /* Sanity check; if base<2, I can't guarantee the rest will work  */
  1803. X    if (f_radix < 2) {
  1804. X        eek_a_bug("Function return or parameter passing faulty? (This is a guess.)");
  1805. X        printf("\n");
  1806. X        return(0);
  1807. X    }
  1808. X
  1809. X#ifdef PASS1 /* only for FLT */
  1810. X    flt_radix= f_radix;
  1811. X    if (F) i_define(D_FLT_RADIX, "",
  1812. X            "FLT", "_RADIX", (long) f_radix, (long) F_RADIX, "");
  1813. X#else
  1814. X    if (f_radix != flt_radix) {
  1815. X        printf("\n%s*** WARNING: %s %s (%d) %s%s\n",
  1816. X               co, thing, "arithmetic has a different radix",
  1817. X               f_radix, "from float", oc);
  1818. X        bugs++;
  1819. X    }
  1820. X#endif
  1821. X
  1822. X    /* Now the number of digits precision: */
  1823. X    f_mant_dig=0; b=1.0;
  1824. X    do { f_mant_dig++; b=Mul(b, base); }
  1825. X    while (Diff(Diff(Sum(b, ONE), b), ONE) == ZERO);
  1826. X    f_dig=floor_log(10, (Long_double)(b/base)) + (base==10?1:0);
  1827. X    Vprintf("%sSignificant base digits = %d %s %d %s%s\n",
  1828. X        co, f_mant_dig, "(= at least", f_dig, "decimal digits)", oc);
  1829. X    if (F) i_define(D_MANT_DIG, thing,
  1830. X            Fname, "_MANT_DIG", (long) f_mant_dig,
  1831. X            (long) F_MANT_DIG, "");
  1832. X    if (F) i_define(D_DIG, thing,
  1833. X            Fname, "_DIG", (long) f_dig, (long) F_DIG, "");
  1834. X    digs= ceil_log(10, (Long_double)b); /* the number of digits to printf */
  1835. X
  1836. X    /* Rounding *******************************************************/
  1837. X    basem1=Diff(base, HALF);
  1838. X    if (Diff(Sum(a, basem1), a) != ZERO) {
  1839. X        if (f_radix == 2) basem1=0.375;
  1840. X        else basem1=1.0;
  1841. X        if (Diff(Sum(a, basem1), a) != ZERO) irnd=2; /* away from 0 */
  1842. X        else irnd=1; /* to nearest */
  1843. X    } else irnd=0; /* towards 0 */
  1844. X
  1845. X    basem1=Diff(base, HALF);
  1846. X
  1847. X    if (Diff(Diff(-a, basem1), -a) != ZERO) {
  1848. X        if (f_radix == 2) basem1=0.375;
  1849. X        else basem1=1.0;
  1850. X        if (Diff(Diff(-a, basem1), -a) != ZERO) mrnd=2; /* away from 0*/
  1851. X        else mrnd=1; /* to nearest */
  1852. X    } else mrnd=0; /* towards 0 */
  1853. X
  1854. X    f_rounds= -1; /* Unknown rounding */
  1855. X    if (irnd==0 && mrnd==0) f_rounds=0; /* zero = chops */
  1856. X    if (irnd==1 && mrnd==1) f_rounds=1; /* nearest */
  1857. X    if (irnd==2 && mrnd==0) f_rounds=2; /* +inf */
  1858. X    if (irnd==0 && mrnd==2) f_rounds=3; /* -inf */
  1859. X
  1860. X    if (f_rounds != -1) {
  1861. X        Vprintf("%sArithmetic rounds towards ", co);
  1862. X        switch (f_rounds) {
  1863. X              case 0: Vprintf("zero (i.e. it chops)"); break;
  1864. X              case 1: Vprintf("nearest"); break;
  1865. X              case 2: Vprintf("+infinity"); break;
  1866. X              case 3: Vprintf("-infinity"); break;
  1867. X              default: Vprintf("???"); break;
  1868. X        }
  1869. X        Vprintf("%s\n", oc);
  1870. X    } else { /* Hmm, try to give some help here: */
  1871. X        Vprintf("%sArithmetic rounds oddly: %s\n", co, oc);
  1872. X        Vprintf("%s    Negative numbers %s%s\n",
  1873. X            co, mrnd==0 ? "towards zero" :
  1874. X                mrnd==1 ? "to nearest" :
  1875. X                      "away from zero",
  1876. X            oc);
  1877. X        Vprintf("%s    Positive numbers %s%s\n",
  1878. X            co, irnd==0 ? "towards zero" :
  1879. X                irnd==1 ? "to nearest" :
  1880. X                      "away from zero",
  1881. X            oc);
  1882. X    }
  1883. X    /* An extra goody */
  1884. X    if (f_radix == 2 && f_rounds == 1) {
  1885. X        if (Diff(Sum(a, ONE), a) != ZERO) {
  1886. X            Vprintf("%s   Tie breaking rounds up%s\n", co, oc);
  1887. X        } else if (Diff(Sum(a, THREE), a) == FOUR) {
  1888. X            Vprintf("%s   Tie breaking rounds to even%s\n", co, oc);
  1889. X        } else {
  1890. X            Vprintf("%s   Tie breaking rounds down%s\n", co, oc);
  1891. X        }
  1892. X    }
  1893. X#ifdef PASS1 /* only for FLT */
  1894. X    flt_rounds= f_rounds;
  1895. X    if (F)
  1896. X      i_define(D_FLT_ROUNDS, "",
  1897. X           "FLT", "_ROUNDS", (long) f_rounds, (long) F_ROUNDS, "");
  1898. X#else
  1899. X    if (f_rounds != flt_rounds) {
  1900. X        printf("\n%s*** WARNING: %s %s (%d) %s%s\n",
  1901. X               co, thing, "arithmetic rounds differently",
  1902. X               f_rounds, "from float", oc);
  1903. X        bugs++;
  1904. X    }
  1905. X#endif
  1906. X
  1907. X    /* Various flavours of epsilon ************************************/
  1908. X    negeps=f_mant_dig+f_mant_dig;
  1909. X    basein=1.0/base;
  1910. X    a=1.0;
  1911. X    for(i=1; i<=negeps; i++) a*=basein;
  1912. X
  1913. X    b=a;
  1914. X    while (Diff(Diff(ONE, a), ONE) == ZERO) {
  1915. X        a*=base;
  1916. X        negeps--;
  1917. X    }
  1918. X    negeps= -negeps;
  1919. X    Vprintf("%sSmallest x such that 1.0-base**x != 1.0 = %d%s\n",
  1920. X        co, negeps, oc);
  1921. X
  1922. X    etop = ONE;
  1923. X    ebot = ZERO;
  1924. X    eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
  1925. X    while (eps != ebot && eps != etop) {
  1926. X        epsp1 = Diff(ONE, eps);
  1927. X        if (epsp1 < ONE) etop = eps;
  1928. X        else ebot = eps;
  1929. X        eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
  1930. X    }
  1931. X    /* Sanity check */
  1932. X    if (Diff(ONE, etop) >= ONE || Diff(ONE, ebot) != ONE) {
  1933. X        eek_a_bug("internal error calculating epsneg");
  1934. X    }
  1935. X    Vprintf("%sSmallest x such that 1.0-x != 1.0 = %s%s\n",
  1936. X        co, f_rep(digs, (Long_double) eps), oc);
  1937. X    if (V) F_check(digs, (Long_double) eps);
  1938. X
  1939. X    epsneg=a;
  1940. X    if ((f_radix!=2) && irnd) {
  1941. X    /*    a=(a*(1.0+a))/(1.0+1.0); => */
  1942. X        a=Div(Mul(a, Sum(ONE, a)), Sum(ONE, ONE));
  1943. X    /*    if ((1.0-a)-1.0 != 0.0) epsneg=a; => */
  1944. X        if (Diff(Diff(ONE, a), ONE) != ZERO) epsneg=a;
  1945. X    }
  1946. X    /* epsneg is used later */
  1947. X    Unexpected(20);
  1948. X
  1949. X    machep= -f_mant_dig-f_mant_dig;
  1950. X    a=b;
  1951. X    while (Diff(Sum(ONE, a), ONE) == ZERO) { a*=base; machep++; }
  1952. X    Vprintf("%sSmallest x such that 1.0+base**x != 1.0 = %d%s\n",
  1953. X        co, machep, oc);
  1954. X
  1955. X    etop = ONE;
  1956. X    ebot = ZERO;
  1957. X    eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
  1958. X    while (eps != ebot && eps != etop) {
  1959. X        epsp1 = Sum(ONE, eps);
  1960. X        if (epsp1 > ONE) etop = eps;
  1961. X        else ebot = eps;
  1962. X        eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
  1963. X    }
  1964. X    /* Sanity check */
  1965. X    if (Sum(ONE, etop) <= ONE || Sum(ONE, ebot) != ONE) {
  1966. X        eek_a_bug("internal error calculating eps");
  1967. X    }
  1968. X    f_epsilon=etop;
  1969. X
  1970. X    Vprintf("%sSmallest x such that 1.0+x != 1.0 = %s%s\n",
  1971. X        co, f_rep(digs, (Long_double) f_epsilon), oc);
  1972. X    /* Possible loss of precision warnings here from non-stdc compilers: */
  1973. X    if (F) f_define(D_EPSILON, thing,
  1974. X            Fname, "_EPSILON", digs, (Long_double) f_epsilon, MARK);
  1975. X    if (V || F) F_check(digs, (Long_double) f_epsilon);
  1976. X    Unexpected(21);
  1977. X    if (F) Validate(digs, (Long_double) f_epsilon, (Long_double) F_EPSILON,
  1978. X            f_epsilon == Self(F_EPSILON));
  1979. X    Unexpected(22);
  1980. X
  1981. X    /* Extra chop info *************************************************/
  1982. X    if (f_rounds == 0) {
  1983. X        if (Diff(Mul(Sum(ONE,f_epsilon),ONE),ONE) !=  ZERO) {
  1984. X            Vprintf("%sAlthough arithmetic chops, it uses guard digits%s\n", co, oc);
  1985. X        }
  1986. X    }
  1987. X
  1988. X    /* Size of and minimum normalised exponent ************************/
  1989. X    y=0; i=0; k=1; z=basein; z1=(1.0+f_epsilon)/base;
  1990. X
  1991. X    /* Coarse search for the largest power of two */
  1992. X    if (setjmp(lab)==0) { /* for underflow trap */ /* Yields i, k, y, y1 */
  1993. X        do {
  1994. X            y=z; y1=z1;
  1995. X            z=Mul(y,y); z1=Mul(z1, y);
  1996. X            a=Mul(z,ONE);
  1997. X            z2=Div(z1,y);
  1998. X            if (z2 != y1) break;
  1999. X            if ((Sum(a,a) == ZERO) || (fabs(z) >= y)) break;
  2000. X            i++;
  2001. X            k+=k;
  2002. X        } while(1);
  2003. X    } else {
  2004. X        Vprintf("%s%s underflow generates a trap%s\n", co, Thing, oc);
  2005. X    }
  2006. X    Unexpected(23);
  2007. X
  2008. X    if (f_radix != 10) {
  2009. X        iexp=i+1; /* for the sign */
  2010. X        mx=k+k;
  2011. X    } else {
  2012. X        iexp=2;
  2013. X        iz=f_radix;
  2014. X        while (k >= iz) { iz*=f_radix; iexp++; }
  2015. X        mx=iz+iz-1;
  2016. X    }
  2017. X
  2018. X    /* Fine tune starting with y and y1 */
  2019. X    if (setjmp(lab)==0) { /* for underflow trap */ /* Yields k, f_min */
  2020. X        do {
  2021. X            f_min=y; z1=y1;
  2022. X            y=Div(y,base); y1=Div(y1,base);
  2023. X            a=Mul(y,ONE);
  2024. X            z2=Mul(y1,base);
  2025. X            if (z2 != z1) break;
  2026. X            if ((Sum(a,a) == ZERO) || (fabs(y) >= f_min)) break;
  2027. X            k++;
  2028. X        } while (1);
  2029. X    }
  2030. X    Unexpected(24);
  2031. X
  2032. X    f_min_exp=(-k)+1;
  2033. X
  2034. X    if ((mx <= k+k-3) && (f_radix != 10)) { mx+=mx; iexp+=1; }
  2035. X    Vprintf("%sNumber of bits used for exponent = %d%s\n", co, iexp, oc);
  2036. X    Vprintf("%sMinimum normalised exponent = %d%s\n", co, f_min_exp, oc);
  2037. X    if (F)
  2038. X      i_define(D_MIN_EXP, thing,
  2039. X           Fname, "_MIN_EXP", (long) f_min_exp, (long) F_MIN_EXP, "");
  2040. X
  2041. X    if (setjmp(lab)==0) {
  2042. X        Vprintf("%sMinimum normalised positive number = %s%s\n",
  2043. X            co, f_rep(digs, (Long_double) f_min), oc);
  2044. X    } else {
  2045. X        eek_a_bug("printf can't print the smallest normalised number");
  2046. X        printf("\n");
  2047. X    }
  2048. X    Unexpected(25);
  2049. X    /* Possible loss of precision warnings here from non-stdc compilers: */
  2050. X    if (setjmp(lab) == 0) {
  2051. X        if (F) f_define(D_MIN, thing,
  2052. X                Fname, "_MIN", digs, (Long_double) f_min, MARK);
  2053. X        if (V || F) F_check(digs, (Long_double) f_min);
  2054. X    } else {
  2055. X        eek_a_bug("xxx_MIN caused a trap");
  2056. X        printf("\n");
  2057. X    }
  2058. X
  2059. X    if (setjmp(lab) == 0) {
  2060. X        if (F) Validate(digs, (Long_double) f_min, (Long_double) F_MIN,
  2061. X                f_min == Self(F_MIN));
  2062. X    } else {
  2063. X        printf("%s*** Verify failed for above #define!\n    %s %s\n\n",
  2064. X               co, "Compiler has an unusable number for value", oc);
  2065. X        bugs++;
  2066. X    }
  2067. X    Unexpected(26);
  2068. X
  2069. X    a=1.0; f_min_10_exp=0;
  2070. X    while (a > f_min*10.0) { a/=10.0; f_min_10_exp--; }
  2071. X    if (F) i_define(D_MIN_10_EXP, thing,
  2072. X            Fname, "_MIN_10_EXP", (long) f_min_10_exp,
  2073. X            (long) F_MIN_10_EXP, "");
  2074. X
  2075. X    /* Minimum exponent ************************************************/
  2076. X    if (setjmp(lab)==0) { /* for underflow trap */ /* Yields xminner */
  2077. X        do {
  2078. X            xminner=y;
  2079. X            y=Div(y,base);
  2080. X            a=Mul(y,ONE);
  2081. X            if ((Sum(a,a) == ZERO) || (fabs(y) >= xminner)) break;
  2082. X        } while (1);
  2083. X    }
  2084. X    Unexpected(27);
  2085. X
  2086. X    if (xminner != 0.0 && xminner != f_min) {
  2087. X        normal= 0;
  2088. X        Vprintf("%sThe smallest numbers are not kept normalised%s\n",
  2089. X            co, oc);
  2090. X        if (setjmp(lab)==0) {
  2091. X            Vprintf("%sSmallest unnormalised positive number = %s%s\n",
  2092. X                co, f_rep(digs, (Long_double) xminner), oc);
  2093. X            if (V) F_check(digs, (Long_double) xminner);
  2094. X        } else {
  2095. X            eek_a_bug("printf can't print the smallest unnormalised number.");
  2096. X            printf("\n");
  2097. X        }
  2098. X        Unexpected(28);
  2099. X    } else {
  2100. X        normal= 1;
  2101. X        Vprintf("%sThe smallest numbers are normalised%s\n", co, oc);
  2102. X    }
  2103. X
  2104. X    /* Maximum exponent ************************************************/
  2105. X    f_max_exp=2; f_max=1.0; newxmax=base+1.0;
  2106. X    inf=0; trap=0;
  2107. X    while (f_max<newxmax) {
  2108. X        f_max=newxmax;
  2109. X        if (setjmp(lab) == 0) { /* Yields inf, f_max_exp */
  2110. X            newxmax=Mul(newxmax, base);
  2111. X        } else {
  2112. X            trap=1;
  2113. X            break;
  2114. X        }
  2115. X        if (Div(newxmax, base) != f_max) {
  2116. X            inf=1; /* ieee infinity */
  2117. X            break;
  2118. X        }
  2119. X        f_max_exp++;
  2120. X    }
  2121. X    Unexpected(29);
  2122. X    if (trap) {
  2123. X        Vprintf("%s%s overflow generates a trap%s\n", co, Thing, oc);
  2124. X    }
  2125. X
  2126. X    if (inf) Vprintf("%sThere is an 'infinite' value%s\n", co, oc);
  2127. X    Vprintf("%sMaximum exponent = %d%s\n", co, f_max_exp, oc);
  2128. X    if (F) i_define(D_MAX_EXP, thing,
  2129. X            Fname, "_MAX_EXP", (long) f_max_exp,
  2130. X            (long) F_MAX_EXP, "");
  2131. X
  2132. X    /* Largest number ***************************************************/
  2133. X    f_max=Diff(ONE, epsneg);
  2134. X    if (Mul(f_max,ONE) != f_max) f_max=Diff(ONE, Mul(base,epsneg));
  2135. X    for (i=1; i<=f_max_exp; i++) f_max=Mul(f_max, base);
  2136. X
  2137. X    if (setjmp(lab)==0) {
  2138. X        Vprintf("%sMaximum number = %s%s\n",
  2139. X            co, f_rep(digs, (Long_double) f_max), oc);
  2140. X    } else {
  2141. X        eek_a_bug("printf can't print the largest double.");
  2142. X        printf("\n");
  2143. X    }
  2144. X    if (setjmp(lab)==0) {
  2145. X    /* Possible loss of precision warnings here from non-stdc compilers: */
  2146. X        if (F) f_define(D_MAX, thing,
  2147. X                Fname, "_MAX", digs, (Long_double) f_max, MARK);
  2148. X        if (V || F) F_check(digs, (Long_double) f_max);
  2149. X    } else {
  2150. X        eek_a_bug("xxx_MAX caused a trap");
  2151. X        printf("\n");
  2152. X    }
  2153. X    if (setjmp(lab)==0) {
  2154. X        if (F) Validate(digs, (Long_double) f_max, (Long_double) F_MAX,
  2155. X                f_max == Self(F_MAX));
  2156. X    } else {
  2157. X        printf("%s*** Verify failed for above #define!\n    %s %s\n\n",
  2158. X               co, "Compiler has an unusable number for value", oc);
  2159. X        bugs++;
  2160. X    }
  2161. X    Unexpected(30);
  2162. X
  2163. X    a=1.0; f_max_10_exp=0;
  2164. X    while (a < f_max/10.0) { a*=10.0; f_max_10_exp++; }
  2165. X    if (F) i_define(D_MAX_10_EXP, thing,
  2166. X            Fname, "_MAX_10_EXP", (long) f_max_10_exp,
  2167. X            (long) F_MAX_10_EXP, "");
  2168. X
  2169. X    /* Hidden bit + sanity check ****************************************/
  2170. X    if (f_radix != 10) {
  2171. X        hidden=0;
  2172. X        mantbits=floor_log(2, (Long_double)f_radix)*f_mant_dig;
  2173. X        if (mantbits+iexp == (int)sizeof(Number)*bits_per_byte) {
  2174. X            hidden=1;
  2175. X            Vprintf("%sArithmetic uses a hidden bit%s\n", co, oc);
  2176. X        } else if (mantbits+iexp+1 == (int)sizeof(Number)*bits_per_byte) {
  2177. X            Vprintf("%sArithmetic doesn't use a hidden bit%s\n",
  2178. X                co, oc);
  2179. X        } else {
  2180. X            printf("\n%s%s\n    %s %s %s!%s\n\n",
  2181. X                   co,
  2182. X                   "*** Something fishy here!",
  2183. X                   "Exponent size + mantissa size doesn't match",
  2184. X                   "with the size of a", thing,
  2185. X                   oc);
  2186. X        }
  2187. X        if (hidden && f_radix == 2 && f_max_exp+f_min_exp==3) {
  2188. X            Vprintf("%sIt looks like %s length IEEE format%s\n",
  2189. X                co, f_mant_dig==24 ? "single" :
  2190. X                    f_mant_dig==53 ? "double" :
  2191. X                    f_mant_dig >53 ? "extended" :
  2192. X                        "some", oc);
  2193. X            if (f_rounds != 1 || normal) {
  2194. X                Vprintf("%s   though ", co);
  2195. X                if (f_rounds != 1) {
  2196. X                    Vprintf("the rounding is unusual");
  2197. X                    if (normal) Vprintf(" and ");
  2198. X                }
  2199. X                if (normal) Vprintf("the normalisation is unusual");
  2200. X                Vprintf("%s\n", oc);
  2201. X            }
  2202. X        } else {
  2203. X            Vprintf("%sIt doesn't look like IEEE format%s\n",
  2204. X                co, oc);
  2205. X        }
  2206. X    }
  2207. X    printf("\n"); /* regardless of verbosity */
  2208. X    return f_mant_dig;
  2209. X}
  2210. X
  2211. XProcedure EPROP(fprec, dprec, lprec) int fprec, dprec, lprec; {
  2212. X    /* See if expressions are evaluated in extended precision.
  2213. X       Some compilers optimise even if you don't want it,
  2214. X       and then this function fails to produce the right result.
  2215. X       We try to diagnose this if it happens.
  2216. X    */
  2217. X    Volatile int eprec;
  2218. X    Volatile double a, b, base, old;
  2219. X    Volatile Number d, oldd, dbase, one, zero;
  2220. X    Volatile int bad=0;
  2221. X
  2222. X    /* Size of mantissa **************************************/
  2223. X    a=1.0;
  2224. X    if (setjmp(lab) == 0) { /* Yields nothing */
  2225. X        do { old=a; a=a+a; }
  2226. X        while ((((a+1.0)-a)-1.0) == 0.0 && a>old);
  2227. X    } else bad=1;
  2228. X    if (a <= old) bad=1;
  2229. X
  2230. X    if (!bad) {
  2231. X        b=1.0;
  2232. X        if (setjmp(lab) == 0) { /* Yields nothing */
  2233. X            do { old=b; b=b+b; }
  2234. X            while ((base=((a+b)-a)) == 0.0 && b>old);
  2235. X            if (b <= old) bad=1;
  2236. X        } else bad=1;
  2237. X    }
  2238. X
  2239. X    if (!bad) {
  2240. X        eprec=0; d=1.0; dbase=base; one=1.0; zero=0.0;
  2241. X        if (setjmp(lab) == 0) { /* Yields nothing */
  2242. X            do { eprec++; oldd=d; d=d*dbase; }
  2243. X            while ((((d+one)-d)-one) == zero && d>oldd);
  2244. X            if (d <= oldd) bad=1;
  2245. X        } else bad=1;
  2246. X    }
  2247. X
  2248. X    Unexpected(31);
  2249. X
  2250. X    if (bad) {
  2251. X      Vprintf("%sCan't determine precision for %s expressions:\n%s%s\n", 
  2252. X         co, thing, "   check that you compiled without optimisation!",
  2253. X         oc);
  2254. X    } else if (eprec==dprec) {
  2255. X      Vprintf("%s%s expressions are evaluated in double precision%s\n",
  2256. X          co, Thing, oc);
  2257. X    } else if (eprec==fprec) {
  2258. X      Vprintf("%s%s expressions are evaluated in float precision%s\n",
  2259. X          co, Thing, oc);
  2260. X    } else if (eprec==lprec) {
  2261. X      Vprintf("%s%s expressions are evaluated in long double precision%s\n",
  2262. X          co, Thing, oc);
  2263. X    } else {
  2264. X        Vprintf("%s%s expressions are evaluated in a %s %s %d %s%s\n",
  2265. X            co, Thing, eprec>dprec ? "higher" : "lower",
  2266. X            "precision than double,\n   using",
  2267. X            eprec, "base digits",
  2268. X                oc);
  2269. X    }
  2270. X}
  2271. X
  2272. X#else /* not Number */
  2273. X
  2274. X#ifdef FPROP
  2275. X/* ARGSUSED */
  2276. Xint FPROP(bits_per_byte) int bits_per_byte; { return 0; }
  2277. X#endif
  2278. X#ifdef EPROP
  2279. X/* ARGSUSED */
  2280. XProcedure EPROP(fprec, dprec, lprec) int fprec, dprec, lprec; {}
  2281. X#endif
  2282. X
  2283. X#endif /* ifdef Number */
  2284. X
  2285. X#ifdef PASS3
  2286. X#undef PASS
  2287. X#endif
  2288. X
  2289. X#ifdef PASS2
  2290. X#undef PASS2
  2291. X#define PASS3 1
  2292. X#endif
  2293. X
  2294. X#ifdef PASS1
  2295. X#undef PASS1
  2296. X#define PASS2 1
  2297. X#endif
  2298. X
  2299. X#ifdef PASS0
  2300. X#undef PASS0
  2301. X#endif
  2302. X
  2303. X#ifdef PASS /* then rescan this file */
  2304. X#ifdef NO_FILE
  2305. X#include "config.c"
  2306. X#else /* if the next line fails to compile, define NO_FILE */
  2307. X#include __FILE__
  2308. X#endif
  2309. X#endif /* PASS */
  2310. EOF
  2311. fi
  2312. echo 'Part 01 out of 01 of pack.out complete.'
  2313. exit 0
  2314.  
  2315.