#ifndef VERSION
#define VERSION "4.3"
#endif
#ifndef FILENAME
#ifdef NO_FILE
#define FILENAME "enquire.c"
#else
#ifdef __FILE__
#define FILENAME __FILE__
#else
#define FILENAME "enquire.c"
#endif
#endif
#endif
#ifndef PASS
#ifndef SEP
#define PASS 1
#define PASS0 1
#define PASS1 1
#endif
#define D_CHAR_BIT "Number of bits in a storage unit"
#define D_CHAR_MAX "Maximum char"
#define D_CHAR_MIN "Minimum char"
#define D_SCHAR_MAX "Maximum signed char"
#define D_SCHAR_MIN "Minimum signed char"
#define D_UCHAR_MAX "Maximum unsigned char (minimum is always 0)"
#define D_INT_MAX "Maximum %s"
#define D_INT_MIN "Minimum %s"
#define D_UINT_MAX "Maximum unsigned %s (minimum is always 0)"
#define D_FLT_ROUNDS "Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown"
#define D_FLT_RADIX "Radix of exponent representation"
#define D_MANT_DIG "Number of base-FLT_RADIX digits in the significand of a %s"
#define D_DIG "Number of decimal digits of precision in a %s"
#define D_MIN_EXP "Minimum int x such that FLT_RADIX**(x-1) is a normalised %s"
#define D_MIN_10_EXP "Minimum int x such that 10**x is a normalised %s"
#define D_MAX_EXP "Maximum int x such that FLT_RADIX**(x-1) is a representable %s"
#define D_MAX_10_EXP "Maximum int x such that 10**x is a representable %s"
#define D_MAX "Maximum %s"
#define D_EPSILON "Difference between 1.0 and the minimum %s greater than 1.0"
#define D_MIN "Minimum normalised %s"
#ifdef NO_VOID
#define Procedure int
#else
#define Procedure void
#endif
#ifndef NO_STDC
#ifdef __STDC__
#if __STDC__
#define STDC
#endif
#endif
#endif
#ifdef STDC
#define ARGS(x) x
#define NOARGS (void)
#define Volatile volatile
#define Long_double long double
#define stdc 1
#define U "U"
#else
#define ARGS(x) ()
#define NOARGS ()
#define Volatile static
#define Long_double double
#define stdc 0
#define U ""
#endif
#define __GCC_FLOAT_NOT_NEEDED
#include <stdio.h>
#ifdef STDC
#ifndef NO_STDDEF
#include <stddef.h>
#endif
#endif
#ifdef NO_SIG
#define jmp_buf int
#else
#include <sys/types.h>
#include <signal.h>
#include <setjmp.h>
#endif
#ifdef CHAR_BIT
#undef CHAR_BIT
#undef CHAR_MAX
#undef CHAR_MIN
#undef SCHAR_MAX
#undef SCHAR_MIN
#undef UCHAR_MAX
#undef UCHAR_MIN
#endif
#ifdef VERIFY
#include "limits.h"
#endif
#ifndef SYS_FLOAT_H_WRAP
#define SYS_FLOAT_H_WRAP 0
#endif
#if SYS_FLOAT_H_WRAP || defined VERIFY
#include "float.h"
#endif
#define Vprintf if (V) printf
#define Unexpected(place) if (setjmp(lab)!=0) croak(place)
#define fabs(x) (((x)<0.0)?(-x):(x))
#endif
#ifdef PASS0
int false NOARGS;
#ifdef NO_STDDEF
char *malloc ();
#else
char *malloc ARGS((size_t size));
#endif
Procedure exit ARGS((int status));
char *f_rep ARGS((int precision, Long_double val));
char *fake_f_rep ARGS((char *type, Long_double val));
int maximum_int NOARGS;
int cprop NOARGS;
int basic NOARGS;
Procedure sprop NOARGS;
Procedure iprop NOARGS;
Procedure lprop NOARGS;
Procedure usprop NOARGS;
Procedure uiprop NOARGS;
Procedure ulprop NOARGS;
int fprop ARGS((int bits_per_byte));
int dprop ARGS((int bits_per_byte));
int ldprop ARGS((int bits_per_byte));
Procedure efprop ARGS((int fprec, int dprec, int lprec));
Procedure edprop ARGS((int fprec, int dprec, int lprec));
Procedure eldprop ARGS((int fprec, int dprec, int lprec));
int setmode ARGS((char *s));
Procedure farewell ARGS((int bugs));
Procedure describe ARGS((char *description, char *extra));
Procedure missing ARGS((char *s));
Procedure fmissing ARGS((char *s));
Procedure check_defines NOARGS;
Procedure bitpattern ARGS((char *p, unsigned int size));
int ceil_log ARGS((int base, Long_double x));
Procedure croak ARGS((int place));
Procedure eek_a_bug ARGS((char *problem));
Procedure endian ARGS((int bits_per_byte));
int exponent ARGS((Long_double x, double *fract, int *exp));
int floor_log ARGS((int base, Long_double x));
Procedure f_define ARGS((char *desc, char *extra, char *sort, char *name,
int prec, Long_double val, Long_double req,
char *mark));
Procedure i_define ARGS((char *desc, char *extra, char *sort, char *name,
long val, long lim, long req, char *mark));
Procedure u_define ARGS((char *desc, char *extra, char *sort, char *name,
unsigned long val, unsigned long req, char *mark));
#ifdef NO_SIG
int setjmp ARGS((int lab));
int lab=1;
int setjmp(lab) int lab; { return(0); }
Procedure signal(i, p) int i, (*p)(); {}
#else
jmp_buf lab;
Procedure overflow(sig) int sig; {
signal(sig, overflow);
longjmp(lab, 1);
}
#endif
int V= 0,
L= 0,
F= 0,
bugs=0;
char co[4], oc[4];
int bits_per_byte;
int flt_rounds;
int flt_radix;
#ifdef TEST
#define ROUND_BITS 0x30
#define TO_NEAREST 0x00
#define TO_ZERO 0x10
#define TO_MINUS_INF 0x20
#define TO_PLUS_INF 0x30
#define EXT_BITS 0xc0
#define ROUND_EXTENDED 0x00
#define ROUND_SINGLE 0x40
#define ROUND_DOUBLE 0x80
#define EXE_INEX1 0x100
#define EXE_INEX2 0x200
#define EXE_DZ 0x400
#define EXE_UNFL 0x800
#define EXE_OVFL 0x1000
#define EXE_OPERR 0x2000
#define EXE_SNAN 0x4000
#define EXE_BSUN 0x8000
printmode(new) unsigned new; {
fpmode_(&new);
printf("New fp mode:\n");
printf(" Round toward ");
switch (new & ROUND_BITS) {
case TO_NEAREST: printf("nearest"); break;
case TO_ZERO: printf("zero"); break;
case TO_MINUS_INF: printf("minus infinity"); break;
case TO_PLUS_INF: printf("plus infinity"); break;
default: printf("???"); break;
}
printf("\n Extended rounding precision: ");
switch (new & EXT_BITS) {
case ROUND_EXTENDED: printf("extended"); break;
case ROUND_SINGLE: printf("single"); break;
case ROUND_DOUBLE: printf("double"); break;
default: printf("???"); break;
}
printf("\n Enabled exceptions:");
if (new & (unsigned) EXE_INEX1) printf(" inex1");
if (new & (unsigned) EXE_INEX2) printf(" inex2");
if (new & (unsigned) EXE_DZ) printf(" dz");
if (new & (unsigned) EXE_UNFL) printf(" unfl");
if (new & (unsigned) EXE_OVFL) printf(" ovfl");
if (new & (unsigned) EXE_OPERR) printf(" operr");
if (new & (unsigned) EXE_SNAN) printf(" snan");
if (new & (unsigned) EXE_BSUN) printf(" bsun");
printf("\n");
}
int setmode(s) char *s; {
unsigned mode=0, dig;
char c;
while (*s) {
c= *s++;
if (c>='0' && c<='9') dig= c-'0';
else if (c>='a' && c<='f') dig= c-'a'+10;
else if (c>='A' && c<='F') dig= c-'A'+10;
else return 1;
mode= mode<<4 | dig;
}
printmode(mode);
return 0;
}
#else
int setmode(s) char *s; {
fprintf(stderr, "Can't set mode: not compiled with TEST\n");
return(1);
}
#endif
Procedure farewell(bugs) int bugs; {
if (bugs == 0) exit(0);
printf("\n%sFor hints on dealing with the ", co);
if (bugs == 1) printf("problem");
else printf("%d problems", bugs);
printf(" above\n see the section 'TROUBLESHOOTING' in the file ");
printf("%s%s\n", FILENAME, oc);
exit(bugs);
}
Procedure croak(place) int place; {
printf("*** Unexpected signal at point %d\n", place);
farewell(bugs+1);
}
char *xmalloc(size) unsigned size; {
char *value = (char *)malloc(size);
if (value == 0) {
fprintf(stderr, "Virtual memory exceeded\n");
exit(bugs+1);
}
return value;
}
int maxint;
int maximum_int() {
Volatile int newi, int_max, two=2;
newi=1; int_max=0;
if (setjmp(lab)==0) {
while(newi>int_max) {
int_max=newi;
newi=newi*two+1;
}
}
Unexpected(0);
return int_max;
}
int main(argc, argv) int argc; char *argv[]; {
int dprec, fprec, lprec;
int i; char *s; int bad;
#ifdef SIGFPE
signal(SIGFPE, overflow);
#endif
#ifdef SIGOVER
signal(SIGOVER, overflow);
#endif
Unexpected(1);
bad=0;
for (i=1; i < argc; i++) {
s= argv[i];
if (*s == '-') {
s++;
while (*s) {
switch (*(s++)) {
case 'v': V=1; break;
case 'l': L=1; break;
case 'f': F=1; break;
default: bad=1; break;
}
}
} else if (*s == '+') {
s++;
bad= setmode(s);
} else bad= 1;
}
if (bad) {
fprintf(stderr,
"Usage: %s [-vlf]\n v=Verbose l=Limits.h f=Float.h\n",
argv[0]);
exit(1);
}
if (L || F) {
co[0]= '/'; oc[0]= ' ';
co[1]= '*'; oc[1]= '*';
co[2]= ' '; oc[2]= '/';
co[3]= '\0'; oc[3]= '\0';
} else {
co[0]= '\0'; oc[0]= '\0';
V=1;
}
if (L) printf("%slimits.h%s\n", co, oc);
if (F) printf("%sfloat.h%s\n", co, oc);
if (F) {
printf ("#ifndef _FLOAT_H___\n");
printf ("#define _FLOAT_H___\n");
if (SYS_FLOAT_H_WRAP)
printf ("#include_next <float.h>\n");
}
#ifdef ID
printf("%sProduced on %s by enquire version %s, CWI, Amsterdam%s\n",
co, ID, VERSION, oc);
#else
printf("%sProduced by enquire version %s, CWI, Amsterdam%s\n",
co, VERSION, oc);
#endif
#ifdef VERIFY
printf("%sVerification phase%s\n", co, oc);
#endif
#ifdef NO_SIG
Vprintf("%sCompiled without signal(): %s%s\n",
co,
"there's nothing that can be done if overflow occurs",
oc);
#endif
#ifdef NO_SC
Vprintf("%sCompiled without signed char%s\n", co, oc);
#endif
#ifdef NO_UC
Vprintf("%Compiled without unsigned char%s\n", co, oc);
#endif
#ifdef NO_UI
Vprintf("%Compiled without unsigned short or long%s\n", co, oc);
#endif
#ifdef __STDC__
Vprintf("%sCompiler claims to be ANSI C level %d%s\n",
co, __STDC__, oc);
#else
Vprintf("%sCompiler does not claim to be ANSI C%s\n", co, oc);
#endif
printf("\n");
check_defines();
maxint= maximum_int();
bits_per_byte= basic();
Vprintf("\n");
if (F||V) {
fprec= fprop(bits_per_byte);
dprec= dprop(bits_per_byte);
lprec= ldprop(bits_per_byte);
efprop(fprec, dprec, lprec);
edprop(fprec, dprec, lprec);
eldprop(fprec, dprec, lprec);
}
#ifndef NO_MEM
if (V) {
unsigned int size;
long total;
size=1<<((bits_per_byte*sizeof(int))-2);
total=0;
while (size!=0) {
while ( malloc((false()?sizeof(int):size)) !=
(char *)NULL
) {
total+=(size/2);
}
size/=2;
}
Vprintf("%sMemory allocable ~= %ld Kbytes%s\n",
co, (total+511)/512, oc);
}
#endif
if (F) {
printf ("#endif %s _FLOAT_H___%s\n", co, oc);
}
farewell(bugs);
return bugs;
}
Procedure eek_a_bug(problem) char *problem; {
printf("\n%s*** WARNING: %s%s\n", co, problem, oc);
bugs++;
}
Procedure describe(description, extra) char *description, *extra; {
printf(" %s", co);
printf(description, extra);
printf("%s\n", oc);
}
Procedure i_define(desc, extra, sort, name, val, lim, req, mark)
char *desc, *extra, *sort, *name; long val, lim, req; char *mark; {
if (SYS_FLOAT_H_WRAP && F && val == req)
return;
describe(desc, extra);
printf("#undef %s%s\n", sort, name);
if (val >= 0) {
printf("#define %s%s %ld%s\n", sort, name, val, mark);
} else if (val + lim < 0) {
printf("#define %s%s (%ld%s%ld%s)\n",
sort, name, -lim, mark, val+lim, mark);
} else {
printf("#define %s%s (%ld%s)\n", sort, name, val, mark);
}
#ifdef VERIFY
if (val != req) {
printf("%s*** Verify failed for above #define!\n", co);
printf(" Compiler has %ld for value%s\n\n", req, oc);
bugs++;
}
#endif
Vprintf("\n");
}
Procedure u_define(desc, extra, sort, name, val, req, mark)
char *desc, *extra, *sort, *name; unsigned long val, req; char *mark; {
describe(desc, extra);
printf("#undef %s%s\n", sort, name);
printf("#define %s%s %lu%s%s\n", sort, name, val, U, mark);
#ifdef VERIFY
if (val != req) {
printf("%s*** Verify failed for above #define!\n", co);
printf(" Compiler has %lu for value%s\n\n", req, oc);
bugs++;
}
#endif
Vprintf("\n");
}
Procedure f_define(desc, extra, sort, name, precision, val, req, mark)
char *desc, *extra, *sort, *name; int precision;
Long_double val, req; char *mark; {
if (SYS_FLOAT_H_WRAP && F && val == req)
return;
describe(desc, extra);
printf ("#undef %s%s\n", sort, name);
if (stdc) {
#ifdef NO_LONG_DOUBLE_IO
static int union_defined = 0;
if (sizeof(double) != sizeof(Long_double)
&& !strcmp(sort, "LDBL")) {
if (!union_defined) {
printf("#ifndef __LDBL_UNION__\n");
printf("#define __LDBL_UNION__\n");
printf("union __convert_long_double {\n");
printf(" unsigned __convert_long_double_i[4];\n");
printf(" long double __convert_long_double_d;\n");
printf("};\n");
printf("#endif\n");
union_defined = 1;
}
printf("#define %s%s %s\n",
sort, name, fake_f_rep("long double", val));
} else {
printf("#define %s%s %s%s\n",
sort, name, f_rep(precision, val), mark);
}
#else
printf("#define %s%s %s%s\n",
sort, name, f_rep(precision, val), mark);
#endif
} else if (*mark == 'F') {
printf("#define %s%s ((float)%s)\n",
sort, name, f_rep(precision, val));
} else {
printf("#define %s%s %s\n", sort, name, f_rep(precision, val));
}
Vprintf("\n");
}
int floor_log(base, x) int base; Long_double x; {
int r=0;
while (x>=base) { r++; x/=base; }
return r;
}
int ceil_log(base, x) int base; Long_double x; {
int r=0;
while (x>1.0) { r++; x/=base; }
return r;
}
int exponent(x, fract, exp) Long_double x; double *fract; int *exp; {
int r=0, neg=0;
Long_double old;
*fract=0.0; *exp=0;
if (x<0.0) {
x= -x;
neg= 1;
}
if (x==0.0) return 1;
if (x>=10.0) {
while (x>=10.0) {
old=x; r++; x/=10.0;
if (old==x) return 0;
}
} else {
while (x<1.0) {
old=x; r--; x*=10.0;
if (old==x) return 0;
}
}
if (neg) *fract= (double) -x;
else *fract=(double) x;
*exp=r;
return 1;
}
char *fake_f_rep(type, val) char *type; Long_double val; {
static char buf[1024];
union { unsigned int i[4]; Long_double ld;} u;
u.i[0] = u.i[1] = u.i[2] = u.i[3] = 0;
u.ld = val;
sprintf(buf, "(__extension__ ((union __convert_long_double) {__convert_long_double_i: {0x%x, 0x%x, 0x%x, 0x%x}}).__convert_long_double_d)",
u.i[0], u.i[1], u.i[2], u.i[3]);
return buf;
}
char *f_rep(precision, val) int precision; Long_double val; {
static char buf[1024];
#ifdef NO_LONG_DOUBLE_IO
if (1)
#else
if (sizeof(double) == sizeof(Long_double))
#endif
{
double d = val;
sprintf(buf, "%.*e", precision, d);
} else {
sprintf(buf, "%.*Le", precision, val);
}
return buf;
}
Procedure bitpattern(p, size) char *p; unsigned int size; {
char c;
unsigned int i;
int j;
for (i=1; i<=size; i++) {
c= *p;
p++;
for (j=bits_per_byte-1; j>=0; j--)
printf("%c", (c>>j)&1 ? '1' : '0');
if (i!=size) printf(" ");
}
}
#define Order(x, px, mode)\
printf("%s%s ", co, mode); for (i=0; i<sizeof(x); i++) px[i]= ab[i]; \
for (i=1; i<=sizeof(x); i++) { c=((x>>(bits_per_byte*(sizeof(x)-i)))&mask);\
putchar(c==0 ? '?' : (char)c); }\
printf("%s\n", oc);
Procedure endian(bits_per_byte) int bits_per_byte; {
short s=0;
int j=0;
long l=0;
char *ps= (char *) &s,
*pj= (char *) &j,
*pl= (char *) &l,
*ab= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
unsigned int mask, i, c;
mask=0;
for (i=1; i<=(unsigned)bits_per_byte; i++) mask= (mask<<1)|1;
if (V) {
printf("%sCHARACTER ORDER%s\n", co, oc);
Order(s, ps, "short:");
Order(j, pj, "int: ");
Order(l, pl, "long: ");
}
}
Procedure missing(s) char *s; {
printf("%s*** #define %s missing from limits.h%s\n", co, s, oc);
bugs++;
}
Procedure fmissing(s) char *s; {
printf("%s*** #define %s missing from float.h%s\n", co, s, oc);
bugs++;
}
int false() { return 0; }
#define Promoted(x) (false()?(x):(-1))
#define is_signed(x) (Promoted(x) < 0)
#define sign_of(x) ((x)?"signed":"unsigned")
#define Signed 1
#define Unsigned 0
#define sgn(x) ((is_signed(x))?Signed:Unsigned)
#define showtype(t, x) Vprintf("%s%s %s %s%s\n", co, t, sign_of(is_signed(x)), type_of(sizeof(x)), oc)
char *type_of(x) int x; {
if (x == sizeof(char)) {
if (sizeof(char) == sizeof(int)) return "char/short/int";
if (sizeof(char) == sizeof(short)) return "char/short";
return "char";
}
if (x == sizeof(short)) {
if (sizeof(short) == sizeof(int)) return "short/int";
return "short";
}
if (x == sizeof(int)) {
if (sizeof(int) == sizeof(long)) return "int/long";
return "int";
}
if (x == sizeof(long)) return "long";
return "unknown-type";
}
char *ftype_of(x) int x; {
if (x == sizeof(float)) {
return "float";
}
if (x == sizeof(double)) {
if (sizeof(double) == sizeof(Long_double))
return "(long)double";
return "double";
}
if (x == sizeof(Long_double)) {
return "long double";
}
return "unknown-type";
}
Procedure typerr(name, esign, esize, sign, size)
char *name; int esign, esize, sign, size;
{
Vprintf("*** %s has wrong type: expected %s %s, found %s %s\n",
name, sign_of(esign), type_of(esize),
sign_of(sign), type_of(size));
}
Procedure ftyperr(name, esize, size) char *name; int esize, size; {
Vprintf("*** %s has wrong type: expected %s, found %s\n",
name, ftype_of(esize), ftype_of(size));
}
int promotions() {
int si = 0; long sl = 0;
unsigned int ui; unsigned long ul;
short ss; unsigned short us;
Vprintf("\n%sPROMOTIONS%s\n", co, oc);
if (
(sizeof(Promoted(si)) != sizeof(int)) ||
(sizeof(Promoted(sl)) != sizeof(long)) ||
(sizeof(Promoted(ss)) != sizeof(int)) ||
(sizeof(Promoted(ui)) != sizeof(int)) ||
(sizeof(Promoted(ul)) != sizeof(long)) ||
(sizeof(Promoted(us)) != sizeof(int)) ||
is_signed(ui) || is_signed(ul) ||
!is_signed(si) || !is_signed(sl)
)
{
eek_a_bug("promotions don't work properly in conditional expressions\n");
}
showtype("unsigned short promotes to", Promoted((unsigned short) 0));
showtype("long+unsigned gives", sl+ui);
return 0;
}
#define checktype(x, n, s, t) if((sgn(x)!=s)||(sizeof(x)!=sizeof(t))) typerr(n, s, sizeof(t), sign_of(x), sizeof(x));
#define fchecktype(x, n, t) if (sizeof(x) != sizeof(t)) ftyperr(n, sizeof(x), sizeof(t));
Procedure check_defines() {
#ifdef VERIFY
int usign;
#ifdef NO_UI
usign= Signed;
#else
usign= is_signed((unsigned short) 0);
#endif
if (L) {
#ifdef CHAR_BIT
checktype(CHAR_BIT, "CHAR_BIT", Signed, int);
#else
missing("CHAR_BIT");
#endif
#ifdef CHAR_MAX
checktype(CHAR_MAX, "CHAR_MAX", Signed, int);
#else
missing("CHAR_MAX");
#endif
#ifdef CHAR_MIN
checktype(CHAR_MIN, "CHAR_MIN", Signed, int);
#else
missing("CHAR_MIN");
#endif
#ifdef SCHAR_MAX
checktype(SCHAR_MAX, "SCHAR_MAX", Signed, int);
#else
missing("SCHAR_MAX");
#endif
#ifdef SCHAR_MIN
checktype(SCHAR_MIN, "SCHAR_MIN", Signed, int);
#else
missing("SCHAR_MIN");
#endif
#ifdef UCHAR_MAX
checktype(UCHAR_MAX, "UCHAR_MAX", Signed, int);
#else
missing("UCHAR_MAX");
#endif
#ifdef SHRT_MAX
checktype(SHRT_MAX, "SHRT_MAX", Signed, int);
#else
missing("SHRT_MAX");
#endif
#ifdef SHRT_MIN
checktype(SHRT_MIN, "SHRT_MIN", Signed, int);
#else
missing("SHRT_MIN");
#endif
#ifdef INT_MAX
checktype(INT_MAX, "INT_MAX", Signed, int);
#else
missing("INT_MAX");
#endif
#ifdef INT_MIN
checktype(INT_MIN, "INT_MIN", Signed, int);
#else
missing("INT_MIN");
#endif
#ifdef LONG_MAX
checktype(LONG_MAX, "LONG_MAX", Signed, long);
#else
missing("LONG_MAX");
#endif
#ifdef LONG_MIN
checktype(LONG_MIN, "LONG_MIN", Signed, long);
#else
missing("LONG_MIN");
#endif
#ifdef USHRT_MAX
checktype(USHRT_MAX, "USHRT_MAX", usign, int);
#else
missing("USHRT_MAX");
#endif
#ifdef UINT_MAX
checktype(UINT_MAX, "UINT_MAX", Unsigned, int);
#else
missing("UINT_MAX");
#endif
#ifdef ULONG_MAX
checktype(ULONG_MAX, "ULONG_MAX", Unsigned, long);
#else
missing("ULONG_MAX");
#endif
}
if (F) {
#ifdef FLT_RADIX
checktype(FLT_RADIX, "FLT_RADIX", Signed, int);
#else
fmissing("FLT_RADIX");
#endif
#ifdef FLT_MANT_DIG
checktype(FLT_MANT_DIG, "FLT_MANT_DIG", Signed, int);
#else
fmissing("FLT_MANT_DIG");
#endif
#ifdef FLT_DIG
checktype(FLT_DIG, "FLT_DIG", Signed, int);
#else
fmissing("FLT_DIG");
#endif
#ifdef FLT_ROUNDS
checktype(FLT_ROUNDS, "FLT_ROUNDS", Signed, int);
#else
fmissing("FLT_ROUNDS");
#endif
#ifdef FLT_EPSILON
fchecktype(FLT_EPSILON, "FLT_EPSILON", float);
#else
fmissing("FLT_EPSILON");
#endif
#ifdef FLT_MIN_EXP
checktype(FLT_MIN_EXP, "FLT_MIN_EXP", Signed, int);
#else
fmissing("FLT_MIN_EXP");
#endif
#ifdef FLT_MIN
fchecktype(FLT_MIN, "FLT_MIN", float);
#else
fmissing("FLT_MIN");
#endif
#ifdef FLT_MIN_10_EXP
checktype(FLT_MIN_10_EXP, "FLT_MIN_10_EXP", Signed, int);
#else
fmissing("FLT_MIN_10_EXP");
#endif
#ifdef FLT_MAX_EXP
checktype(FLT_MAX_EXP, "FLT_MAX_EXP", Signed, int);
#else
fmissing("FLT_MAX_EXP");
#endif
#ifdef FLT_MAX
fchecktype(FLT_MAX, "FLT_MAX", float);
#else
fmissing("FLT_MAX");
#endif
#ifdef FLT_MAX_10_EXP
checktype(FLT_MAX_10_EXP, "FLT_MAX_10_EXP", Signed, int);
#else
fmissing("FLT_MAX_10_EXP");
#endif
#ifdef DBL_MANT_DIG
checktype(DBL_MANT_DIG, "DBL_MANT_DIG", Signed, int);
#else
fmissing("DBL_MANT_DIG");
#endif
#ifdef DBL_DIG
checktype(DBL_DIG, "DBL_DIG", Signed, int);
#else
fmissing("DBL_DIG");
#endif
#ifdef DBL_EPSILON
fchecktype(DBL_EPSILON, "DBL_EPSILON", double);
#else
fmissing("DBL_EPSILON");
#endif
#ifdef DBL_MIN_EXP
checktype(DBL_MIN_EXP, "DBL_MIN_EXP", Signed, int);
#else
fmissing("DBL_MIN_EXP");
#endif
#ifdef DBL_MIN
fchecktype(DBL_MIN, "DBL_MIN", double);
#else
fmissing("DBL_MIN");
#endif
#ifdef DBL_MIN_10_EXP
checktype(DBL_MIN_10_EXP, "DBL_MIN_10_EXP", Signed, int);
#else
fmissing("DBL_MIN_10_EXP");
#endif
#ifdef DBL_MAX_EXP
checktype(DBL_MAX_EXP, "DBL_MAX_EXP", Signed, int);
#else
fmissing("DBL_MAX_EXP");
#endif
#ifdef DBL_MAX
fchecktype(DBL_MAX, "DBL_MAX", double);
#else
fmissing("DBL_MAX");
#endif
#ifdef DBL_MAX_10_EXP
checktype(DBL_MAX_10_EXP, "DBL_MAX_10_EXP", Signed, int);
#else
fmissing("DBL_MAX_10_EXP");
#endif
#ifdef STDC
#ifdef LDBL_MANT_DIG
checktype(LDBL_MANT_DIG, "LDBL_MANT_DIG", Signed, int);
#else
fmissing("LDBL_MANT_DIG");
#endif
#ifdef LDBL_DIG
checktype(LDBL_DIG, "LDBL_DIG", Signed, int);
#else
fmissing("LDBL_DIG");
#endif
#ifdef LDBL_EPSILON
fchecktype(LDBL_EPSILON, "LDBL_EPSILON", long double);
#else
fmissing("LDBL_EPSILON");
#endif
#ifdef LDBL_MIN_EXP
checktype(LDBL_MIN_EXP, "LDBL_MIN_EXP", Signed, int);
#else
fmissing("LDBL_MIN_EXP");
#endif
#ifdef LDBL_MIN
fchecktype(LDBL_MIN, "LDBL_MIN", long double);
#else
fmissing("LDBL_MIN");
#endif
#ifdef LDBL_MIN_10_EXP
checktype(LDBL_MIN_10_EXP, "LDBL_MIN_10_EXP", Signed, int);
#else
fmissing("LDBL_MIN_10_EXP");
#endif
#ifdef LDBL_MAX_EXP
checktype(LDBL_MAX_EXP, "LDBL_MAX_EXP", Signed, int);
#else
fmissing("LDBL_MAX_EXP");
#endif
#ifdef LDBL_MAX
fchecktype(LDBL_MAX, "LDBL_MAX", long double);
#else
fmissing("LDBL_MAX");
#endif
#ifdef LDBL_MAX_10_EXP
checktype(LDBL_MAX_10_EXP, "LDBL_MAX_10_EXP", Signed, int);
#else
fmissing("LDBL_MAX_10_EXP");
#endif
#endif
}
#endif
}
#ifdef VERIFY
#ifndef SCHAR_MAX
#define SCHAR_MAX char_max
#endif
#ifndef SCHAR_MIN
#define SCHAR_MIN char_min
#endif
#ifndef UCHAR_MAX
#define UCHAR_MAX char_max
#endif
#endif
#ifndef CHAR_BIT
#define CHAR_BIT char_bit
#endif
#ifndef CHAR_MAX
#define CHAR_MAX char_max
#endif
#ifndef CHAR_MIN
#define CHAR_MIN char_min
#endif
#ifndef SCHAR_MAX
#define SCHAR_MAX char_max
#endif
#ifndef SCHAR_MIN
#define SCHAR_MIN char_min
#endif
#ifndef UCHAR_MAX
#define UCHAR_MAX char_max
#endif
int cprop() {
Volatile char c, char_max, char_min;
Volatile int bits_per_byte, c_signed;
long char_bit;
Unexpected(2);
c=1; bits_per_byte=0;
do { c=c<<1; bits_per_byte++; } while(c!=0);
c= (char)(-1);
if (((int)c)<0) c_signed=1;
else c_signed=0;
Vprintf("%schar = %d bits, %ssigned%s\n",
co, (int)sizeof(c)*bits_per_byte, (c_signed?"":"un"), oc);
char_bit=(long)(sizeof(c)*bits_per_byte);
if (L) i_define(D_CHAR_BIT, "", "CHAR", "_BIT",
char_bit, 0L, (long) CHAR_BIT, "");
c=0; char_max=0;
c++;
if (bits_per_byte <= 16) {
if (setjmp(lab)==0) {
while (c>char_max) {
char_max=c;
c++;
}
} else {
Vprintf("%sCharacter overflow generates a trap!%s\n",
co, oc);
}
c=0; char_min=0;
c--;
if (setjmp(lab)==0) {
while (c<char_min) {
char_min=c;
c--;
}
}
} else {
c = (1 << (bits_per_byte - 1)) - 1;
char_max = c;
c++;
if (c > char_max)
char_max = ~0;
c = 0;
char_min = 0;
c--;
if (c < char_min) {
c = (1 << (bits_per_byte - 1)) - 1;
c = -c;
char_min = c;
c--;
if (c < char_min)
char_min = c;
}
}
if (c_signed && char_min == 0) {
Vprintf("%sBEWARE! Chars are pseudo-unsigned:%s\n", co, oc);
Vprintf("%s %s%s%s\n",
"They contain only nonnegative values, ",
"but sign extend when used as integers.", co, oc);
}
Unexpected(3);
if (L) {
if ((sizeof(char) == sizeof(int)) && !c_signed) {
u_define(D_CHAR_MAX, "", "CHAR", "_MAX",
(long) char_max,
(long) CHAR_MAX, "");
} else {
i_define(D_CHAR_MAX, "", "CHAR", "_MAX",
(long) char_max, 0L,
(long) CHAR_MAX, "");
}
i_define(D_CHAR_MIN, "", "CHAR", "_MIN",
(long) char_min, (long) maxint,
(long) CHAR_MIN, "");
if (c_signed) {
i_define(D_SCHAR_MAX, "", "SCHAR", "_MAX",
(long) char_max, 0L,
(long) SCHAR_MAX, "");
i_define(D_SCHAR_MIN, "", "SCHAR", "_MIN",
(long) char_min, (long) maxint,
(long) SCHAR_MIN, "");
} else {
if (sizeof(char) == sizeof(int)) {
u_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",
(long) char_max,
(long) UCHAR_MAX, "");
} else {
i_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",
(long) char_max, 0L,
(long) UCHAR_MAX, "");
}
}
if (c_signed) {
#ifndef NO_UC
Volatile unsigned char c, char_max;
c=0; char_max=0;
c++;
if (setjmp(lab)==0) {
while (c>char_max) {
char_max=c;
c++;
}
}
Unexpected(4);
if (sizeof(char) == sizeof(int)) {
u_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",
(long) char_max,
(long) UCHAR_MAX, "");
} else {
i_define(D_UCHAR_MAX, "", "UCHAR", "_MAX",
(long) char_max, 0L,
(long) UCHAR_MAX, "");
}
#endif
} else {
#ifndef NO_SC
Volatile signed char c, char_max, char_min;
c=0; char_max=0;
c++;
if (setjmp(lab)==0) {
while (c>char_max) {
char_max=c;
c++;
}
}
c=0; char_min=0;
c--;
if (setjmp(lab)==0) {
while (c<char_min) {
char_min=c;
c--;
}
}
Unexpected(5);
i_define(D_SCHAR_MIN, "", "SCHAR", "_MIN",
(long) char_min, (long) maxint,
(long) SCHAR_MIN, "");
i_define(D_SCHAR_MAX, "", "SCHAR", "_MAX",
(long) char_max, 0L,
(long) SCHAR_MAX, "");
#endif
}
}
return bits_per_byte;
}
int basic() {
Volatile int bits_per_byte;
typedef int function ();
int variable;
int *p, *q;
Vprintf("%sSIZES%s\n", co, oc);
bits_per_byte= cprop();
Vprintf("%sshort=%d int=%d long=%d float=%d double=%d bits %s\n",
co,
(int) sizeof(short)*bits_per_byte,
(int) sizeof(int)*bits_per_byte,
(int) sizeof(long)*bits_per_byte,
(int) sizeof(float)*bits_per_byte,
(int) sizeof(double)*bits_per_byte, oc);
if (stdc) {
Vprintf("%slong double=%d bits%s\n",
co, (int) sizeof(Long_double)*bits_per_byte, oc);
}
Vprintf("%schar*=%d bits%s%s\n",
co, (int)sizeof(char *)*bits_per_byte,
sizeof(char *)>sizeof(int)?" BEWARE! larger than int!":"",
oc);
Vprintf("%sint* =%d bits%s%s\n",
co, (int)sizeof(int *)*bits_per_byte,
sizeof(int *)>sizeof(int)?" BEWARE! larger than int!":"",
oc);
Vprintf("%sfunc*=%d bits%s%s\n",
co, (int)sizeof(function *)*bits_per_byte,
sizeof(function *)>sizeof(int)?" BEWARE! larger than int!":"",
oc);
if (V) printf ("%s%s %s %s%s\n", co, "Type size_t is",
((((false()?( sizeof(int)):(-1)) < 0) )?
"signed":"unsigned") ,
type_of(sizeof(
sizeof(int)+0
)
),
oc);
showtype("Type size_t is", sizeof(0));
#define alignment(TYPE) \
((long)((char *)&((struct{char c; TYPE d;}*)0)->d - (char *) 0))
Vprintf("\n%sALIGNMENTS%s\n", co, oc);
Vprintf("%schar=%ld short=%ld int=%ld long=%ld%s\n",
co,
alignment(char), alignment(short),
alignment(int), alignment(long),
oc);
Vprintf("%sfloat=%ld double=%ld%s\n",
co,
alignment(float), alignment(double),
oc);
if (stdc) {
Vprintf("%slong double=%ld%s\n",
co,
alignment(Long_double),
oc);
}
Vprintf("%schar*=%ld int*=%ld func*=%ld%s\n",
co,
alignment(char *), alignment(int *), alignment(function *),
oc);
Vprintf("\n");
endian(bits_per_byte);
Vprintf("\n%sPROPERTIES OF POINTERS%s\n", co, oc);
if ((long) (char *) &variable == (long) (int *) &variable) {
Vprintf("%sChar and int pointer formats seem identical%s\n",
co, oc);
} else {
Vprintf("%sChar and int pointer formats are different%s\n",
co, oc);
}
if ((long) (char *) &variable == (long) (function *) &variable) {
Vprintf("%sChar and function pointer formats seem identical%s\n",
co, oc);
} else {
Vprintf("%sChar and function pointer formats are different%s\n",
co, oc);
}
if (V) {
if ("abcd"=="abcd")
printf("%sStrings are shared%s\n", co, oc);
else printf("%sStrings are not shared%s\n", co, oc);
}
p=0; q=0;
showtype("Type ptrdiff_t is", p-q);
Vprintf("\n%sPROPERTIES OF INTEGRAL TYPES%s\n", co, oc);
sprop();
iprop();
lprop();
usprop();
uiprop();
ulprop();
promotions();
Unexpected(6);
return bits_per_byte;
}
#else
#ifdef SEP
extern jmp_buf lab;
extern int V, L, F, bugs, bits_per_byte;
extern char co[], oc[];
extern char *f_rep();
#endif
#endif
#ifdef Number
#undef Number
#undef THING
#undef Thing
#undef thing
#undef FPROP
#undef Fname
#undef Store
#undef Sum
#undef Diff
#undef Mul
#undef Div
#undef ZERO
#undef HALF
#undef ONE
#undef TWO
#undef THREE
#undef FOUR
#undef Self
#undef F_check
#undef Validate
#undef EPROP
#undef MARK
#undef F_RADIX
#undef F_MANT_DIG
#undef F_DIG
#undef F_ROUNDS
#undef F_EPSILON
#undef F_MIN_EXP
#undef F_MIN
#undef F_MIN_10_EXP
#undef F_MAX_EXP
#undef F_MAX
#undef F_MAX_10_EXP
#endif
#ifdef Integer
#undef Integer
#undef INT
#undef IPROP
#undef Iname
#undef UPROP
#undef Uname
#undef OK_UI
#undef IMARK
#undef I_MAX
#undef I_MIN
#undef U_MAX
#endif
#ifdef PASS1
#define Number float
#define THING "FLOAT"
#define Thing "Float"
#define thing "float"
#define Fname "FLT"
#define FPROP fprop
#define Store fStore
#define Sum fSum
#define Diff fDiff
#define Mul fMul
#define Div fDiv
#define ZERO 0.0
#define HALF 0.5
#define ONE 1.0
#define TWO 2.0
#define THREE 3.0
#define FOUR 4.0
#define Self fSelf
#define F_check fCheck
#define MARK "F"
#ifdef VERIFY
#define Validate(prec, val, req, same) fValidate(prec, val, req, same)
#endif
#define EPROP efprop
#define Integer short
#define INT "short"
#define IPROP sprop
#define Iname "SHRT"
#ifndef NO_UI
#define OK_UI 1
#endif
#define IMARK ""
#define UPROP usprop
#define Uname "USHRT"
#ifdef SHRT_MAX
#define I_MAX SHRT_MAX
#endif
#ifdef SHRT_MIN
#define I_MIN SHRT_MIN
#endif
#ifdef USHRT_MAX
#define U_MAX USHRT_MAX
#endif
#ifdef FLT_RADIX
#define F_RADIX FLT_RADIX
#endif
#ifdef FLT_MANT_DIG
#define F_MANT_DIG FLT_MANT_DIG
#endif
#ifdef FLT_DIG
#define F_DIG FLT_DIG
#endif
#ifdef FLT_ROUNDS
#define F_ROUNDS FLT_ROUNDS
#endif
#ifdef FLT_EPSILON
#define F_EPSILON FLT_EPSILON
#endif
#ifdef FLT_MIN_EXP
#define F_MIN_EXP FLT_MIN_EXP
#endif
#ifdef FLT_MIN
#define F_MIN FLT_MIN
#endif
#ifdef FLT_MIN_10_EXP
#define F_MIN_10_EXP FLT_MIN_10_EXP
#endif
#ifdef FLT_MAX_EXP
#define F_MAX_EXP FLT_MAX_EXP
#endif
#ifdef FLT_MAX
#define F_MAX FLT_MAX
#endif
#ifdef FLT_MAX_10_EXP
#define F_MAX_10_EXP FLT_MAX_10_EXP
#endif
#endif
#ifdef PASS2
#define Number double
#define THING "DOUBLE"
#define Thing "Double"
#define thing "double"
#define Fname "DBL"
#define FPROP dprop
#define Store dStore
#define Sum dSum
#define Diff dDiff
#define Mul dMul
#define Div dDiv
#define ZERO 0.0
#define HALF 0.5
#define ONE 1.0
#define TWO 2.0
#define THREE 3.0
#define FOUR 4.0
#define Self dSelf
#define F_check dCheck
#define MARK ""
#ifdef VERIFY
#define Validate(prec, val, req, same) dValidate(prec, val, req, same)
#endif
#define EPROP edprop
#define Integer int
#define INT "int"
#define IPROP iprop
#define Iname "INT"
#define OK_UI 1
#define IMARK ""
#define UPROP uiprop
#define Uname "UINT"
#ifdef INT_MAX
#define I_MAX INT_MAX
#endif
#ifdef INT_MIN
#define I_MIN INT_MIN
#endif
#ifdef UINT_MAX
#define U_MAX UINT_MAX
#endif
#ifdef DBL_MANT_DIG
#define F_MANT_DIG DBL_MANT_DIG
#endif
#ifdef DBL_DIG
#define F_DIG DBL_DIG
#endif
#ifdef DBL_EPSILON
#define F_EPSILON DBL_EPSILON
#endif
#ifdef DBL_MIN_EXP
#define F_MIN_EXP DBL_MIN_EXP
#endif
#ifdef DBL_MIN
#define F_MIN DBL_MIN
#endif
#ifdef DBL_MIN_10_EXP
#define F_MIN_10_EXP DBL_MIN_10_EXP
#endif
#ifdef DBL_MAX_EXP
#define F_MAX_EXP DBL_MAX_EXP
#endif
#ifdef DBL_MAX
#define F_MAX DBL_MAX
#endif
#ifdef DBL_MAX_10_EXP
#define F_MAX_10_EXP DBL_MAX_10_EXP
#endif
#endif
#ifdef PASS3
#ifdef STDC
#define Number long double
#define ZERO 0.0L
#define HALF 0.5L
#define ONE 1.0L
#define TWO 2.0L
#define THREE 3.0L
#define FOUR 4.0L
#endif
#define THING "LONG DOUBLE"
#define Thing "Long double"
#define thing "long double"
#define Fname "LDBL"
#define FPROP ldprop
#define Store ldStore
#define Sum ldSum
#define Diff ldDiff
#define Mul ldMul
#define Div ldDiv
#define Self ldSelf
#define F_check ldCheck
#define MARK "L"
#ifdef VERIFY
#define Validate(prec, val, req, same) ldValidate(prec, val, req, same)
#endif
#define EPROP eldprop
#define Integer long
#define INT "long"
#define IPROP lprop
#define Iname "LONG"
#ifndef NO_UI
#define OK_UI 1
#endif
#define IMARK "L"
#define UPROP ulprop
#define Uname "ULONG"
#ifdef LONG_MAX
#define I_MAX LONG_MAX
#endif
#ifdef LONG_MIN
#define I_MIN LONG_MIN
#endif
#ifdef ULONG_MAX
#define U_MAX ULONG_MAX
#endif
#ifdef LDBL_MANT_DIG
#define F_MANT_DIG LDBL_MANT_DIG
#endif
#ifdef LDBL_DIG
#define F_DIG LDBL_DIG
#endif
#ifdef LDBL_EPSILON
#define F_EPSILON LDBL_EPSILON
#endif
#ifdef LDBL_MIN_EXP
#define F_MIN_EXP LDBL_MIN_EXP
#endif
#ifdef LDBL_MIN
#define F_MIN LDBL_MIN
#endif
#ifdef LDBL_MIN_10_EXP
#define F_MIN_10_EXP LDBL_MIN_10_EXP
#endif
#ifdef LDBL_MAX_EXP
#define F_MAX_EXP LDBL_MAX_EXP
#endif
#ifdef LDBL_MAX
#define F_MAX LDBL_MAX
#endif
#ifdef LDBL_MAX_10_EXP
#define F_MAX_10_EXP LDBL_MAX_10_EXP
#endif
#endif
#define UNDEFINED (-2)
#ifndef I_MAX
#define I_MAX ((unsigned long) UNDEFINED)
#endif
#ifndef I_MIN
#define I_MIN ((unsigned long) UNDEFINED)
#endif
#ifndef U_MAX
#define U_MAX ((unsigned long) UNDEFINED)
#endif
#ifndef F_RADIX
#define F_RADIX UNDEFINED
#endif
#ifndef F_MANT_DIG
#define F_MANT_DIG UNDEFINED
#endif
#ifndef F_DIG
#define F_DIG UNDEFINED
#endif
#ifndef F_ROUNDS
#define F_ROUNDS UNDEFINED
#endif
#ifndef F_EPSILON
#define F_EPSILON ((Number) UNDEFINED)
#endif
#ifndef F_MIN_EXP
#define F_MIN_EXP UNDEFINED
#endif
#ifndef F_MIN
#define F_MIN ((Number) UNDEFINED)
#endif
#ifndef F_MIN_10_EXP
#define F_MIN_10_EXP UNDEFINED
#endif
#ifndef F_MAX_EXP
#define F_MAX_EXP UNDEFINED
#endif
#ifndef F_MAX
#define F_MAX ((Number) UNDEFINED)
#endif
#ifndef F_MAX_10_EXP
#define F_MAX_10_EXP UNDEFINED
#endif
#ifndef VERIFY
#define Validate(prec, val, req, same) {;}
#endif
#ifdef Integer
Procedure IPROP() {
Volatile Integer newi, int_max, maxeri, int_min, minneri;
Volatile int ibits, ipower, two=2;
newi=1; int_max=0;
if (setjmp(lab)==0) {
for(ipower=0; newi>int_max; ipower++) {
int_max=newi;
newi=newi*two+1;
}
Vprintf("%sOverflow of a%s %s does not generate a trap%s\n",
co, INT[0]=='i'?"n":"", INT, oc);
} else {
Vprintf("%sOverflow of a%s %s generates a trap%s\n",
co, INT[0]=='i'?"n":"", INT, oc);
}
Unexpected(7);
int_min= -int_max;
if (setjmp(lab)==0) {
if (int_min-1 < int_min) int_min--;
}
Unexpected(8);
maxeri=0; newi=int_max;
if (setjmp(lab)==0) {
for(ibits=ipower; newi>maxeri; ibits++) {
maxeri=newi;
newi=newi+newi+1;
}
}
Unexpected(9);
minneri= -maxeri;
if (setjmp(lab)==0) {
if (minneri-1 < minneri) minneri--;
}
Unexpected(10);
Vprintf("%sMaximum %s = %ld (= 2**%d-1)%s\n",
co, INT, (long)int_max, ipower, oc);
Vprintf("%sMinimum %s = %ld%s\n", co, INT, (long)int_min, oc);
if (L) i_define(D_INT_MAX, INT, Iname, "_MAX",
(long) int_max, 0L,
(long) I_MAX, IMARK);
if (L) i_define(D_INT_MIN, INT, Iname, "_MIN",
(long) int_min, (long) (PASS==1?maxint:int_max),
(long) I_MIN, IMARK);
if(int_max < 0) {
eek_a_bug("signed integral comparison faulty?");
}
if (maxeri>int_max) {
Vprintf("%sThere is a larger %s, %ld (= 2**%d-1), %s %s%s\n",
co, INT, (long)maxeri, ibits,
"but only for addition, not multiplication",
"(I smell a Cyber!)",
oc);
}
if (minneri<int_min) {
Vprintf("%sThere is a smaller %s, %ld, %s %s%s\n",
co, INT, (long)minneri,
"but only for addition, not multiplication",
"(I smell a Cyber!)",
oc);
}
}
Procedure UPROP () {
#ifdef OK_UI
Volatile unsigned Integer u_max, newi, two;
newi=1; u_max=0; two=2;
if (setjmp(lab)==0) {
while(newi>u_max) {
u_max=newi;
newi=newi*two+1;
}
}
Unexpected(11);
Vprintf("%sMaximum unsigned %s = %lu%s\n",
co, INT, (unsigned long) u_max, oc);
if (L) {
if (PASS == 1 && sizeof(short) < sizeof(int)) {
i_define(D_UINT_MAX, INT, Uname, "_MAX",
(unsigned long) u_max, 0L,
(unsigned long) U_MAX, IMARK);
} else {
u_define(D_UINT_MAX, INT, Uname, "_MAX",
(unsigned long) u_max,
(unsigned long) U_MAX, IMARK);
}
}
#endif
}
#endif
#ifdef Number
#ifdef STDC
#define ARGS1(atype, a) (atype a)
#define ARGS2(atype, a, btype, b) (atype a, btype b)
#else
#define ARGS1(atype, a) (a) atype a;
#define ARGS2(atype, a, btype, b) (a, b) atype a; btype b;
#endif
Procedure Store ARGS2(Number, a, Number *, b) { *b=a; }
Number Sum ARGS2(Number, a, Number, b) {Number r; Store(a+b, &r); return (r); }
Number Diff ARGS2(Number, a, Number, b){Number r; Store(a-b, &r); return (r); }
Number Mul ARGS2(Number, a, Number, b) {Number r; Store(a*b, &r); return (r); }
Number Div ARGS2(Number, a, Number, b) {Number r; Store(a/b, &r); return (r); }
Number Self ARGS1(Number, a) {Number r; Store(a, &r); return (r); }
Procedure F_check ARGS((int precision, Long_double val1));
Procedure F_check(precision, val1) int precision; Long_double val1; {
Number val, new, diff;
double rem;
int e;
char *rep;
char *f2;
#ifdef NO_LONG_DOUBLE_IO
double new1;
f2= "%le";
if (sizeof (Number) > sizeof(double))
return;
#else
Long_double new1;
if (sizeof(double) == sizeof(Long_double)) {
f2= "%le";
} else {
f2= "%Le";
}
#endif
val= val1;
rep= f_rep(precision, (Long_double) val);
if (setjmp(lab)==0) {
sscanf(rep, f2, &new1);
} else {
eek_a_bug("sscanf caused a trap");
printf("%s scanning: %s format: %s%s\n\n", co, rep, f2, oc);
Unexpected(12);
return;
}
if (setjmp(lab)==0) {
new= new1;
if (new != 0.0) {
diff= val/new - 1.0;
if (diff < 0.1) diff= 1.0;
}
} else {
eek_a_bug("sscanf returned an unusable number");
printf("%s scanning: %s with format: %s%s\n\n",
co, rep, f2, oc);
Unexpected(13);
return;
}
Unexpected(14);
if (new != val) {
eek_a_bug("Possibly bad output from printf above");
if (!exponent((Long_double)val, &rem, &e)) {
printf("%s but value was an unusable number%s\n\n",
co, oc);
return;
}
printf("%s expected value around %.*fe%d, bit pattern:\n ",
co, precision, rem, e);
bitpattern((char *) &val, (unsigned)sizeof(val));
printf ("%s\n", oc);
printf("%s sscanf gave %s, bit pattern:\n ",
co, f_rep(precision, (Long_double) new));
bitpattern((char *) &new, (unsigned)sizeof(new));
printf ("%s\n", oc);
if (setjmp(lab) == 0) {
diff= val-new;
printf("%s difference= %s%s\n\n",
co, f_rep(precision, (Long_double) diff), oc);
}
Unexpected(15);
}
}
#ifdef VERIFY
Procedure Validate(prec, val, req, same) int prec, same; Long_double val, req; {
Unexpected(16);
if (!same) {
printf("%s*** Verify failed for above #define!\n", co);
if (setjmp(lab) == 0) {
printf(" Compiler has %s for value%s\n",
f_rep(prec, req), oc);
} else {
printf(" Compiler has %s for value%s\n",
"an unusable number", oc);
}
if (setjmp(lab) == 0) {
F_check(prec, (Long_double) req);
}
if (setjmp(lab) == 0) {
if (req > 0.0 && val > 0.0) {
printf("%s difference= %s%s\n",
co, f_rep(prec, val-req), oc);
}
}
Unexpected(17);
printf("\n");
bugs++;
} else if (val != req) {
if (stdc) eek_a_bug("constant has the wrong precision");
else eek_a_bug("the cast didn't work");
printf("\n");
}
}
#endif
int FPROP(bits_per_byte) int bits_per_byte; {
Volatile int
i, f_radix, iexp, irnd, mrnd, f_rounds, f_mant_dig,
iz, k, inf, machep, f_max_exp, f_min_exp, mx, negeps,
mantbits, digs, f_dig, trap,
hidden, normal, f_min_10_exp, f_max_10_exp;
Volatile Number
a, b, base, basein, basem1, f_epsilon, epsneg,
eps, epsp1, etop, ebot,
f_max, newxmax, f_min, xminner, y, y1, z, z1, z2;
Unexpected(18);
Vprintf("%sPROPERTIES OF %s%s\n", co, THING, oc);
a=1.0;
if (setjmp(lab)==0) {
do { a=Sum(a, a); }
while (Diff(Diff(Sum(a, ONE), a), ONE) == ZERO);
} else {
fprintf(stderr, "*** Program got loss-of-precision trap!\n");
farewell(bugs+1);
}
Unexpected(19);
b=1.0;
do { b=Sum(b, b); } while ((base=Diff(Sum(a, b), a)) == ZERO);
f_radix=base;
Vprintf("%sBase = %d%s\n", co, f_radix, oc);
if (f_radix < 2) {
eek_a_bug("Function return or parameter passing faulty? (This is a guess.)");
printf("\n");
return(0);
}
if (PASS == 1) {
flt_radix= f_radix;
if (F) i_define(D_FLT_RADIX, "", "FLT", "_RADIX",
(long) f_radix, 0L, (long) F_RADIX, "");
} else if (f_radix != flt_radix) {
printf("\n%s*** WARNING: %s %s (%d) %s%s\n",
co, thing, "arithmetic has a different radix",
f_radix, "from float", oc);
bugs++;
}
f_mant_dig=0; b=1.0;
do { f_mant_dig++; b=Mul(b, base); }
while (Diff(Diff(Sum(b, ONE), b), ONE) == ZERO);
f_dig=floor_log(10, (Long_double)(b/base)) + (base==10?1:0);
Vprintf("%sSignificant base digits = %d %s %d %s%s\n",
co, f_mant_dig, "(= at least", f_dig, "decimal digits)", oc);
if (F) i_define(D_MANT_DIG, thing, Fname, "_MANT_DIG",
(long) f_mant_dig, 0L, (long) F_MANT_DIG, "");
if (F) i_define(D_DIG, thing, Fname, "_DIG",
(long) f_dig, 0L, (long) F_DIG, "");
digs= ceil_log(10, (Long_double)b);
basem1=Diff(base, HALF);
if (Diff(Sum(a, basem1), a) != ZERO) {
if (f_radix == 2) basem1=0.375;
else basem1=1.0;
if (Diff(Sum(a, basem1), a) != ZERO) irnd=2;
else irnd=1;
} else irnd=0;
basem1=Diff(base, HALF);
if (Diff(Diff(-a, basem1), -a) != ZERO) {
if (f_radix == 2) basem1=0.375;
else basem1=1.0;
if (Diff(Diff(-a, basem1), -a) != ZERO) mrnd=2;
else mrnd=1;
} else mrnd=0;
f_rounds= -1;
if (irnd==0 && mrnd==0) f_rounds=0;
if (irnd==1 && mrnd==1) f_rounds=1;
if (irnd==2 && mrnd==0) f_rounds=2;
if (irnd==0 && mrnd==2) f_rounds=3;
if (f_rounds != -1) {
Vprintf("%sArithmetic rounds towards ", co);
switch (f_rounds) {
case 0: Vprintf("zero (i.e. it chops)"); break;
case 1: Vprintf("nearest"); break;
case 2: Vprintf("+infinity"); break;
case 3: Vprintf("-infinity"); break;
default: Vprintf("???"); break;
}
Vprintf("%s\n", oc);
} else {
Vprintf("%sArithmetic rounds oddly: %s\n", co, oc);
Vprintf("%s Negative numbers %s%s\n",
co, mrnd==0 ? "towards zero" :
mrnd==1 ? "to nearest" :
"away from zero",
oc);
Vprintf("%s Positive numbers %s%s\n",
co, irnd==0 ? "towards zero" :
irnd==1 ? "to nearest" :
"away from zero",
oc);
}
if (f_radix == 2 && f_rounds == 1) {
if (Diff(Sum(a, ONE), a) != ZERO) {
Vprintf("%s Tie breaking rounds up%s\n", co, oc);
} else if (Diff(Sum(a, THREE), a) == FOUR) {
Vprintf("%s Tie breaking rounds to even%s\n", co, oc);
} else {
Vprintf("%s Tie breaking rounds down%s\n", co, oc);
}
}
if (PASS == 1) {
flt_rounds= f_rounds;
if (F && (!SYS_FLOAT_H_WRAP || F_ROUNDS == UNDEFINED))
i_define(D_FLT_ROUNDS, "", "FLT", "_ROUNDS",
(long) f_rounds, 1L, (long) F_ROUNDS, "");
} else if (f_rounds != flt_rounds) {
printf("\n%s*** WARNING: %s %s (%d) %s%s\n",
co, thing, "arithmetic rounds differently",
f_rounds, "from float", oc);
bugs++;
}
negeps=f_mant_dig+f_mant_dig;
basein=1.0/base;
a=1.0;
for(i=1; i<=negeps; i++) a*=basein;
b=a;
while (Diff(Diff(ONE, a), ONE) == ZERO) {
a*=base;
negeps--;
}
negeps= -negeps;
Vprintf("%sSmallest x such that 1.0-base**x != 1.0 = %d%s\n",
co, negeps, oc);
etop = ONE;
ebot = ZERO;
eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
while (eps != ebot && eps != etop) {
epsp1 = Diff(ONE, eps);
if (epsp1 < ONE) etop = eps;
else ebot = eps;
eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
}
eps= etop;
if (Diff(ONE, etop) >= ONE || Diff(ONE, ebot) != ONE) {
eek_a_bug("internal error calculating epsneg");
}
Vprintf("%sSmallest x such that 1.0-x != 1.0 = %s%s\n",
co, f_rep(digs, (Long_double) eps), oc);
if (V) F_check(digs, (Long_double) eps);
epsneg=a;
if ((f_radix!=2) && irnd) {
a=Div(Mul(a, Sum(ONE, a)), Sum(ONE, ONE));
if (Diff(Diff(ONE, a), ONE) != ZERO) epsneg=a;
}
Unexpected(20);
machep= -f_mant_dig-f_mant_dig;
a=b;
while (Diff(Sum(ONE, a), ONE) == ZERO) { a*=base; machep++; }
Vprintf("%sSmallest x such that 1.0+base**x != 1.0 = %d%s\n",
co, machep, oc);
etop = ONE;
ebot = ZERO;
eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
while (eps != ebot && eps != etop) {
epsp1 = Sum(ONE, eps);
if (epsp1 > ONE) etop = eps;
else ebot = eps;
eps = Sum(ebot, Div(Diff(etop, ebot), TWO));
}
if (Sum(ONE, etop) <= ONE || Sum(ONE, ebot) != ONE) {
eek_a_bug("internal error calculating eps");
}
f_epsilon=etop;
Vprintf("%sSmallest x such that 1.0+x != 1.0 = %s%s\n",
co, f_rep(digs, (Long_double) f_epsilon), oc);
f_epsilon= Diff(Sum(ONE, f_epsilon), ONE);
Vprintf("%s(Above number + 1.0) - 1.0 = %s%s\n",
co, f_rep(digs, (Long_double) (f_epsilon)), oc);
if (F) f_define(D_EPSILON, thing,
Fname, "_EPSILON", digs,
(Long_double) f_epsilon,
(Long_double) F_EPSILON, MARK);
if (V || F) F_check(digs, (Long_double) f_epsilon);
Unexpected(21);
if (F) Validate(digs, (Long_double) f_epsilon, (Long_double) F_EPSILON,
f_epsilon == Self(F_EPSILON));
Unexpected(22);
if (f_rounds == 0) {
if (Diff(Mul(Sum(ONE,f_epsilon),ONE),ONE) != ZERO) {
Vprintf("%sAlthough arithmetic chops, it uses guard digits%s\n", co, oc);
}
}
y=0; i=0; k=1; z=basein; z1=(1.0+f_epsilon)/base;
if (setjmp(lab)==0) {
do {
y=z; y1=z1;
z=Mul(y,y); z1=Mul(z1, y);
a=Mul(z,ONE);
z2=Div(z1,y);
if (z2 != y1) break;
if ((Sum(a,a) == ZERO) || (fabs(z) >= y)) break;
i++;
k+=k;
} while(1);
} else {
Vprintf("%s%s underflow generates a trap%s\n", co, Thing, oc);
}
Unexpected(23);
if (f_radix != 10) {
iexp=i+1;
mx=k+k;
} else {
iexp=2;
iz=f_radix;
while (k >= iz) { iz*=f_radix; iexp++; }
mx=iz+iz-1;
}
if (setjmp(lab)==0) {
do {
f_min=y; z1=y1;
y=Div(y,base); y1=Div(y1,base);
a=Mul(y,ONE);
z2=Mul(y1,base);
if (z2 != z1) break;
if ((Sum(a,a) == ZERO) || (fabs(y) >= f_min)) break;
k++;
} while (1);
}
Unexpected(24);
f_min_exp=(-k)+1;
if ((mx <= k+k-3) && (f_radix != 10)) { mx+=mx; iexp+=1; }
Vprintf("%sNumber of bits used for exponent = %d%s\n", co, iexp, oc);
Vprintf("%sMinimum normalised exponent = %d%s\n", co, f_min_exp-1, oc);
if (F)
i_define(D_MIN_EXP, thing, Fname, "_MIN_EXP",
(long) f_min_exp, (long) maxint, (long) F_MIN_EXP, "");
if (setjmp(lab)==0) {
Vprintf("%sMinimum normalised positive number = %s%s\n",
co, f_rep(digs, (Long_double) f_min), oc);
} else {
eek_a_bug("printf can't print the smallest normalised number");
printf("\n");
}
Unexpected(25);
if (setjmp(lab) == 0) {
if (F) f_define(D_MIN, thing,
Fname, "_MIN", digs,
(Long_double) f_min,
(Long_double) F_MIN, MARK);
if (V || F) F_check(digs, (Long_double) f_min);
} else {
eek_a_bug("xxx_MIN caused a trap");
printf("\n");
}
if (setjmp(lab) == 0) {
if (F) Validate(digs, (Long_double) f_min, (Long_double) F_MIN,
f_min == Self(F_MIN));
} else {
printf("%s*** Verify failed for above #define!\n %s %s\n\n",
co, "Compiler has an unusable number for value", oc);
bugs++;
}
Unexpected(26);
a=1.0; f_min_10_exp=0;
while (a > f_min*10.0) { a/=10.0; f_min_10_exp--; }
if (F) i_define(D_MIN_10_EXP, thing, Fname, "_MIN_10_EXP",
(long) f_min_10_exp, (long) maxint,
(long) F_MIN_10_EXP, "");
if (setjmp(lab)==0) {
do {
xminner=y;
y=Div(y,base);
a=Mul(y,ONE);
if ((Sum(a,a) == ZERO) || (fabs(y) >= xminner)) break;
} while (1);
}
Unexpected(27);
if (xminner != 0.0 && xminner != f_min) {
normal= 0;
Vprintf("%sThe smallest numbers are not kept normalised%s\n",
co, oc);
if (setjmp(lab)==0) {
Vprintf("%sSmallest unnormalised positive number = %s%s\n",
co, f_rep(digs, (Long_double) xminner), oc);
if (V) F_check(digs, (Long_double) xminner);
} else {
eek_a_bug("printf can't print the smallest unnormalised number.");
printf("\n");
}
Unexpected(28);
} else {
normal= 1;
Vprintf("%sThe smallest numbers are normalised%s\n", co, oc);
}
f_max_exp=2; f_max=1.0; newxmax=base+1.0;
inf=0; trap=0;
while (f_max<newxmax) {
f_max=newxmax;
if (setjmp(lab) == 0) {
newxmax=Mul(newxmax, base);
} else {
trap=1;
break;
}
if (Div(newxmax, base) != f_max) {
inf=1;
break;
}
f_max_exp++;
}
Unexpected(29);
if (trap) {
Vprintf("%s%s overflow generates a trap%s\n", co, Thing, oc);
}
if (inf) Vprintf("%sThere is an 'infinite' value%s\n", co, oc);
Vprintf("%sMaximum exponent = %d%s\n", co, f_max_exp, oc);
if (F) i_define(D_MAX_EXP, thing, Fname, "_MAX_EXP",
(long) f_max_exp, 0L, (long) F_MAX_EXP, "");
f_max=Diff(ONE, epsneg);
if (Mul(f_max,ONE) != f_max) f_max=Diff(ONE, Mul(base,epsneg));
for (i=1; i<=f_max_exp; i++) f_max=Mul(f_max, base);
if (setjmp(lab)==0) {
Vprintf("%sMaximum number = %s%s\n",
co, f_rep(digs, (Long_double) f_max), oc);
} else {
eek_a_bug("printf can't print the largest double.");
printf("\n");
}
if (setjmp(lab)==0) {
if (F) f_define(D_MAX, thing,
Fname, "_MAX", digs,
(Long_double) f_max,
(Long_double) F_MAX, MARK);
if (V || F) F_check(digs, (Long_double) f_max);
} else {
eek_a_bug("xxx_MAX caused a trap");
printf("\n");
}
if (setjmp(lab)==0) {
if (F) Validate(digs, (Long_double) f_max, (Long_double) F_MAX,
f_max == Self(F_MAX));
} else {
printf("%s*** Verify failed for above #define!\n %s %s\n\n",
co, "Compiler has an unusable number for value", oc);
bugs++;
}
Unexpected(30);
a=1.0; f_max_10_exp=0;
while (a < f_max/10.0) { a*=10.0; f_max_10_exp++; }
if (F) i_define(D_MAX_10_EXP, thing, Fname, "_MAX_10_EXP",
(long) f_max_10_exp, 0L, (long) F_MAX_10_EXP, "");
if (f_radix != 10) {
hidden=0;
mantbits=floor_log(2, (Long_double)f_radix)*f_mant_dig;
if (mantbits == 64
&& iexp == 15
&& f_max_exp+f_min_exp > 0
&& mantbits+iexp+17 == (int)sizeof(Number)*bits_per_byte) {
Vprintf("%sArithmetic probably doesn't use a hidden bit%s\n", co, oc);
Vprintf("%sIt's probably 80387 or 68881 extended real%s\n", co, oc);
goto is_extended;
}
if (mantbits+iexp == (int)sizeof(Number)*bits_per_byte) {
hidden=1;
Vprintf("%sArithmetic uses a hidden bit%s\n", co, oc);
} else if (mantbits+iexp+1 == (int)sizeof(Number)*bits_per_byte) {
Vprintf("%sArithmetic doesn't use a hidden bit%s\n",
co, oc);
} else {
printf("\n%s%s\n %s %s %s!%s\n\n",
co,
"*** Something fishy here!",
"Exponent size + significand size doesn't match",
"with the size of a", thing,
oc);
}
if (hidden && f_radix == 2 && f_max_exp+f_min_exp==3) {
Vprintf("%sIt looks like %s length IEEE format%s\n",
co, f_mant_dig==24 ? "single" :
f_mant_dig==53 ? "double" :
f_mant_dig >53 ? "extended" :
"some", oc);
is_extended:
if (f_rounds != 1 || normal) {
Vprintf("%s though ", co);
if (f_rounds != 1) {
Vprintf("the rounding is unusual");
if (normal) Vprintf(" and ");
}
if (normal) Vprintf("the normalisation is unusual");
Vprintf("%s\n", oc);
}
} else {
Vprintf("%sIt doesn't look like IEEE format%s\n",
co, oc);
}
}
printf("\n");
return f_mant_dig;
}
Procedure EPROP(fprec, dprec, lprec) int fprec, dprec, lprec; {
Volatile int eprec;
Volatile double a, b, base, old;
Volatile Number d, oldd, dbase, one, zero;
Volatile int bad=0;
a=1.0;
if (setjmp(lab) == 0) {
do { old=a; a=a+a; }
while ((((a+1.0)-a)-1.0) == 0.0 && a>old);
} else bad=1;
if (!bad && (a <= old)) bad=1;
if (!bad) {
b=1.0;
if (setjmp(lab) == 0) {
do { old=b; b=b+b; }
while ((base=((a+b)-a)) == 0.0 && b>old);
if (b <= old) bad=1;
} else bad=1;
}
if (!bad) {
eprec=0; d=1.0; dbase=base; one=1.0; zero=0.0;
if (setjmp(lab) == 0) {
do { eprec++; oldd=d; d=d*dbase; }
while ((((d+one)-d)-one) == zero && d>oldd);
if (d <= oldd) bad=1;
} else bad=1;
}
Unexpected(31);
if (bad) {
Vprintf("%sCan't determine precision for %s expressions:\n%s%s\n",
co, thing, " check that you compiled without optimisation!",
oc);
} else if (eprec==dprec) {
Vprintf("%s%s expressions are evaluated in double precision%s\n",
co, Thing, oc);
} else if (eprec==fprec) {
Vprintf("%s%s expressions are evaluated in float precision%s\n",
co, Thing, oc);
} else if (eprec==lprec) {
Vprintf("%s%s expressions are evaluated in long double precision%s\n",
co, Thing, oc);
} else {
Vprintf("%s%s expressions are evaluated in a %s %s %d %s%s\n",
co, Thing, eprec>dprec ? "higher" : "lower",
"precision than double,\n using",
eprec, "base digits",
oc);
}
}
#else
#ifdef FPROP
int FPROP(bits_per_byte) int bits_per_byte; { return 0; }
#endif
#ifdef EPROP
Procedure EPROP(fprec, dprec, lprec) int fprec, dprec, lprec; {}
#endif
#endif
#undef PASS
#ifdef PASS2
#undef PASS2
#define PASS 3
#define PASS3 1
#endif
#ifdef PASS1
#undef PASS1
#define PASS 2
#define PASS2 1
#endif
#ifdef PASS0
#undef PASS0
#endif
#ifdef PASS
#ifdef NO_FILE
#include "enquire.c"
#else
#include FILENAME
#endif
#endif