3 set stdio FEATURE/isoc99
4 hdr float,limits,math,values
5 lib fpclassify,frexp,frexpl,ldexp,ldexpl,finite,finitel,isinf,isinfl,isnan,isnanl,signbit,copysign,copysignl FEATURE/isoc99 math.h -lm
7 tst ast_no_um2fm note{ no unsigned intmax => floatmax cast }end nolink{
8 #include "FEATURE/common"
13 unsigned _ast_intmax_t i = 0;
20 tst ast_mpy_overflow_fpe note{ fpe on mpy overflow }end noexecute{
34 } while (f != p && ++i < 1024);
39 tst ast_div_underflow_fpe note{ fpe on div underflow }end noexecute{
53 } while (f != p && ++i < 1024);
72 #if !defined(FLT_MIN_EXP) && defined(FMINEXP)
73 #define FLT_MIN_EXP FMINEXP
75 #if !defined(FLT_MIN) && defined(MINFLOAT)
76 #define FLT_MIN MINFLOAT
78 #if !defined(FLT_MAX_EXP) && defined(FMAXEXP)
79 #define FLT_MAX_EXP FMAXEXP
81 #if !defined(FLT_MAX) && defined(MAXFLOAT)
82 #define FLT_MAX MAXFLOAT
85 #if !defined(DBL_MIN_EXP) && defined(DMINEXP)
86 #define DBL_MIN_EXP DMINEXP
88 #if !defined(DBL_MIN) && defined(MINDOUBLE)
89 #define DBL_MIN MINDOUBLE
91 #if !defined(DBL_MAX_EXP) && defined(DMAXEXP)
92 #define DBL_MAX_EXP DMAXEXP
94 #if !defined(DBL_MAX) && defined(MAXDOUBLE)
95 #define DBL_MAX MAXDOUBLE
98 <<"#include <ast_common.h>">>
100 <<"#include <float.h>">>
103 <<"#include <math.h>">>
106 <<"#ifndef FLT_DIG">>
107 <<"#define FLT_DIG">> FLT_DIG
111 <<"#ifndef FLT_MAX">>
112 <<"#define FLT_MAX">> FLT_MAX
115 #ifdef FLT_MAX_10_EXP
116 <<"#ifndef FLT_MAX_10_EXP">>
117 <<"#define FLT_MAX_10_EXP">> FLT_MAX_10_EXP
121 <<"#ifndef FLT_MAX_EXP">>
122 <<"#define FLT_MAX_EXP">> FLT_MAX_EXP
126 <<"#ifndef FLT_MIN">>
127 <<"#define FLT_MIN">> FLT_MIN
130 #ifdef FLT_MIN_10_EXP
131 <<"#ifndef FLT_MIN_10_EXP">>
132 <<"#define FLT_MIN_10_EXP">> FLT_MIN_10_EXP
136 <<"#ifndef FLT_MIN_EXP">>
137 <<"#define FLT_MIN_EXP">> FLT_MIN_EXP
142 <<"#ifndef DBL_DIG">>
143 <<"#define DBL_DIG">> DBL_DIG
147 <<"#ifndef DBL_MAX">>
148 <<"#define DBL_MAX">> DBL_MAX
151 #ifdef DBL_MAX_10_EXP
152 <<"#ifndef DBL_MAX_10_EXP">>
153 <<"#define DBL_MAX_10_EXP">> DBL_MAX_10_EXP
157 <<"#ifndef DBL_MAX_EXP">>
158 <<"#define DBL_MAX_EXP">> DBL_MAX_EXP
162 <<"#ifndef DBL_MIN">>
163 <<"#define DBL_MIN">> DBL_MIN
166 #ifdef DBL_MIN_10_EXP
167 <<"#ifndef DBL_MIN_10_EXP">>
168 <<"#define DBL_MIN_10_EXP">> DBL_MIN_10_EXP
172 <<"#ifndef DBL_MIN_EXP">>
173 <<"#define DBL_MIN_EXP">> DBL_MIN_EXP
178 <<"#ifndef LDBL_DIG">>
179 <<"#define LDBL_DIG">> LDBL_DIG
183 <<"#ifndef LDBL_MAX">>
184 <<"#define LDBL_MAX">> LDBL_MAX
187 #ifdef LDBL_MAX_10_EXP
188 <<"#ifndef LDBL_MAX_10_EXP">>
189 <<"#define LDBL_MAX_10_EXP">> LDBL_MAX_10_EXP
193 <<"#ifndef LDBL_MAX_EXP">>
194 <<"#define LDBL_MAX_EXP">> LDBL_MAX_EXP
198 <<"#ifndef LDBL_MIN">>
199 <<"#define LDBL_MIN">> LDBL_MIN
202 #ifdef LDBL_MIN_10_EXP
203 <<"#ifndef LDBL_MIN_10_EXP">>
204 <<"#define LDBL_MIN_10_EXP">> LDBL_MIN_10_EXP
208 <<"#ifndef LDBL_MIN_EXP">>
209 <<"#define LDBL_MIN_EXP">> LDBL_MIN_EXP
214 tst - note{ missing floating point limits }end output{
215 #include "FEATURE/common"
231 static int caught = 0;
233 static void catch(int sig)
235 static void catch(sig) int sig;
238 signal(sig, SIG_IGN);
255 #if _ast_fltmax_double
267 unsigned _ast_intmax_t w;
268 unsigned _ast_intmax_t pw;
269 unsigned _ast_intmax_t x;
273 unsigned _ast_intmax_t uq;
276 signal(SIGFPE, catch);
285 printf("#define USHRT_DIG %d\n", i);
291 printf("#define UINT_DIG %d\n", i);
297 printf("#define ULONG_DIG %d\n", i);
298 if (sizeof(uq) > sizeof(ul))
305 printf("#define ULLONG_DIG %d\n", i);
306 printf("#define UINTMAX_DIG ULLONG_DIG\n");
309 printf("#define UINTMAX_DIG ULONG_DIG\n");
316 f = (_ast_intmax_t)w;
317 x = (_ast_intmax_t)f;
318 } while (w > pw && w == x);
323 printf("#define FLT_ULONG_MAX %lu.0F\n", u);
324 if (sizeof(w) > sizeof(u))
326 printf("#define FLT_ULLONG_MAX %llu.0F\n", w);
327 printf("#define FLT_UINTMAX_MAX FLT_ULLONG_MAX\n");
331 printf("#define FLT_ULLONG_MAX FLT_ULONG_MAX\n");
332 printf("#define FLT_UINTMAX_MAX FLT_ULONG_MAX\n");
336 printf("#define FLT_LONG_MAX %lu.0F\n", u);
337 if (sizeof(w) > sizeof(u))
339 printf("#define FLT_LLONG_MAX %llu.0F\n", w);
340 printf("#define FLT_INTMAX_MAX FLT_LLONG_MAX\n");
344 printf("#define FLT_LLONG_MAX FLT_LONG_MAX\n");
345 printf("#define FLT_INTMAX_MAX FLT_LONG_MAX\n");
349 printf("#define FLT_LONG_MIN (-%lu.0F)\n", u);
350 if (sizeof(w) > sizeof(u))
352 printf("#define FLT_LLONG_MIN (-%llu.0F)\n", w);
353 printf("#define FLT_INTMAX_MIN FLT_LLONG_MIN\n");
357 printf("#define FLT_LLONG_MIN FLT_LONG_MIN\n");
358 printf("#define FLT_INTMAX_MIN FLT_LONG_MIN\n");
369 } while (f != (f + pf));
371 #if defined(FLT_MIN) && defined(FLT_MIN_EXP)
392 printf("#ifndef FLT_DIG\n");
393 printf("#define FLT_DIG %d\n", s);
397 printf("#ifndef FLT_MIN\n");
398 printf("#define FLT_MIN %.*E%s\n", s + 1, mf, fs);
402 printf("#ifndef FLT_MIN_EXP\n");
403 printf("#define FLT_MIN_EXP (%d)\n", i);
407 #if defined(FLT_MAX) && defined(FLT_MAX_EXP)
434 } while (mf == (mf + f));
435 f = (mf - f) * 2.0 + f;
439 printf("#ifndef FLT_MAX\n");
440 printf("#define FLT_MAX %.*E%s\n", s + 1, f, fs);
444 printf("#ifndef FLT_MAX_EXP\n");
445 printf("#define FLT_MAX_EXP %d\n", i);
449 #ifdef FLT_MIN_10_EXP
461 #ifndef FLT_MIN_10_EXP
462 printf("#ifndef FLT_MIN_10_EXP\n");
463 printf("#define FLT_MIN_10_EXP (%d)\n", i);
467 #ifdef FLT_MAX_10_EXP
479 #ifndef FLT_MAX_10_EXP
480 printf("#ifndef FLT_MAX_10_EXP\n");
481 printf("#define FLT_MAX_10_EXP %d\n", i);
491 d = (_ast_intmax_t)w;
492 x = (_ast_intmax_t)d;
493 } while (w > pw && w == x);
498 printf("#define DBL_ULONG_MAX %lu.0\n", u);
499 if (sizeof(w) > sizeof(u))
501 printf("#define DBL_ULLONG_MAX %llu.0\n", w);
502 printf("#define DBL_UINTMAX_MAX DBL_ULLONG_MAX\n");
506 printf("#define DBL_ULLONG_MAX DBL_ULONG_MAX\n");
507 printf("#define DBL_UINTMAX_MAX DBL_ULONG_MAX\n");
511 printf("#define DBL_LONG_MAX %lu.0\n", u);
512 if (sizeof(w) > sizeof(u))
514 printf("#define DBL_LLONG_MAX %llu.0\n", w);
515 printf("#define DBL_INTMAX_MAX DBL_LLONG_MAX\n");
519 printf("#define DBL_LLONG_MAX DBL_LONG_MAX\n");
520 printf("#define DBL_INTMAX_MAX DBL_LONG_MAX\n");
524 printf("#define DBL_LONG_MIN (-%lu.0)\n", u);
525 if (sizeof(w) > sizeof(u))
527 printf("#define DBL_LLONG_MIN (-%llu.0)\n", w);
528 printf("#define DBL_INTMAX_MIN DBL_LLONG_MIN\n");
532 printf("#define DBL_LLONG_MIN DBL_LONG_MIN\n");
533 printf("#define DBL_INTMAX_MIN DBL_LONG_MIN\n");
544 } while (d != (d + pd));
546 #if defined(DBL_MIN) && defined(DBL_MIN_EXP)
567 printf("#ifndef DBL_DIG\n");
568 printf("#define DBL_DIG %d\n", s);
572 printf("#ifndef DBL_MIN\n");
573 printf("#define DBL_MIN %.*E%s\n", s + 1, md, ds);
577 printf("#ifndef DBL_MIN_EXP\n");
578 printf("#define DBL_MIN_EXP (%d)\n", i);
582 #if defined(DBL_MAX) && defined(DBL_MAX_EXP)
599 } while (md == (md + d));
600 d = (md - d) * 2.0 + d;
609 printf("#ifndef DBL_MAX\n");
610 printf("#define DBL_MAX %.*E%s\n", s + 1, d, ds);
614 printf("#ifndef DBL_MAX_EXP\n");
615 printf("#define DBL_MAX_EXP %d\n", i);
619 #ifdef DBL_MIN_10_EXP
631 #ifndef DBL_MIN_10_EXP
632 printf("#ifndef DBL_MIN_10_EXP\n");
633 printf("#define DBL_MIN_10_EXP (%d)\n", i);
637 #ifdef DBL_MAX_10_EXP
649 #ifndef DBL_MAX_10_EXP
650 printf("#ifndef DBL_MAX_10_EXP\n");
651 printf("#define DBL_MAX_10_EXP %d\n", i);
655 #if !_ast_fltmax_double
662 l = (_ast_intmax_t)w;
663 x = (_ast_intmax_t)l;
664 } while (w > pw && w == x);
669 printf("#define LDBL_ULONG_MAX %lu.0L\n", u);
670 if (sizeof(w) > sizeof(u))
672 printf("#define LDBL_ULLONG_MAX %llu.0L\n", w);
673 printf("#define LDBL_UINTMAX_MAX LDBL_ULLONG_MAX\n");
677 printf("#define LDBL_ULLONG_MAX LDBL_ULONG_MAX\n");
678 printf("#define LDBL_UINTMAX_MAX LDBL_ULONG_MAX\n");
682 printf("#define LDBL_LONG_MAX %lu.0L\n", u);
683 if (sizeof(w) > sizeof(u))
685 printf("#define LDBL_LLONG_MAX %llu.0L\n", w);
686 printf("#define LDBL_INTMAX_MAX LDBL_LLONG_MAX\n");
690 printf("#define LDBL_LLONG_MAX LDBL_LONG_MAX\n");
691 printf("#define LDBL_INTMAX_MAX LDBL_LONG_MAX\n");
695 printf("#define LDBL_LONG_MIN (-%lu.0L)\n", u);
696 if (sizeof(w) > sizeof(u))
698 printf("#define LDBL_LLONG_MIN (-%llu.0L)\n", w);
699 printf("#define LDBL_INTMAX_MIN LDBL_LLONG_MIN\n");
703 printf("#define LDBL_LLONG_MIN LDBL_LONG_MIN\n");
704 printf("#define LDBL_INTMAX_MIN LDBL_LONG_MIN\n");
715 } while (l != (l + pl));
717 #if defined(LDBL_MIN) && defined(LDBL_MIN_EXP)
738 printf("#ifndef LDBL_DIG\n");
739 printf("#define LDBL_DIG %d\n", s);
743 printf("#ifndef LDBL_MIN\n");
744 printf("#define LDBL_MIN %.*LE%s\n", s + 1, ml, ls);
748 printf("#ifndef LDBL_MIN_EXP\n");
749 printf("#define LDBL_MIN_EXP (%d)\n", i);
753 #if defined(LDBL_MAX) && defined(LDBL_MAX_EXP)
770 } while (ml == (ml + l));
771 l = (ml - l) * 2.0L + l;
780 printf("#ifndef LDBL_MAX\n");
781 printf("#define LDBL_MAX %.*LE%s\n", s + 1, l, ls);
785 printf("#ifndef LDBL_MAX_EXP\n");
786 printf("#define LDBL_MAX_EXP %d\n", i);
790 #ifdef LDBL_MIN_10_EXP
802 #ifndef LDBL_MIN_10_EXP
803 printf("#ifndef LDBL_MIN_10_EXP\n");
804 printf("#define LDBL_MIN_10_EXP (%d)\n", i);
808 #ifdef LDBL_MAX_10_EXP
820 #ifndef LDBL_MAX_10_EXP
821 printf("#ifndef LDBL_MAX_10_EXP\n");
822 printf("#define LDBL_MAX_10_EXP %d\n", i);
831 printf("#define FLTMAX_UINTMAX_MAX %s_UINTMAX_MAX\n", fp);
832 printf("#define FLTMAX_INTMAX_MAX %s_INTMAX_MAX\n", fp);
833 printf("#define FLTMAX_INTMAX_MIN %s_INTMAX_MIN\n", fp);
846 printf("\n#define _ast_fltsig %d\n", SIGFPE);
851 printf("extern double frexp(double, int*);\n");
854 printf("extern _ast_fltmax_t frexpl(_ast_fltmax_t, int*);\n");
857 printf("extern double ldexp(double, int);\n");
860 printf("extern _ast_fltmax_t ldexpl(_ast_fltmax_t, int);\n");
867 tst - note{ double exponent bitfoolery }end output{
868 #include "FEATURE/common"
870 typedef union _dbl_exp_u
872 unsigned _ast_int4_t e[sizeof(double) / 4];
880 unsigned _ast_int4_t e;
885 for (i = 0; i < sizeof(a.e) / sizeof(a.e[0]); i++)
886 if (e = a.e[i] ^ b.e[i])
888 for (j = i + 1; j < sizeof(a.e) / sizeof(a.e[0]); j++)
891 printf("typedef union _ast_dbl_exp_u\n{\n\tuint32_t\t\te[sizeof(double)/4];\n\tdouble\t\t\tf;\n} _ast_dbl_exp_t;\n\n");
892 printf("#define _ast_dbl_exp_index %d\n", i);
893 for (i = 0; !(e & 1); e >>= 1, i++);
894 printf("#define _ast_dbl_exp_shift %d\n\n", i);
901 tst - note{ long double exponent bitfoolery }end output{
902 #include "FEATURE/common"
904 typedef union _ast_fltmax_exp_u
906 unsigned _ast_int4_t e[sizeof(_ast_fltmax_t) / 4];
914 unsigned _ast_int4_t e;
919 for (i = 0; i < sizeof(a.e) / sizeof(a.e[0]); i++)
920 if (e = a.e[i] ^ b.e[i])
922 for (j = i + 1; j < sizeof(a.e) / sizeof(a.e[0]); j++)
925 printf("typedef union _fltmax_exp_u\n{\n\tuint32_t\t\te[sizeof(_ast_fltmax_t)/4];\n\t_ast_fltmax_t\t\tf;\n} _ast_fltmax_exp_t;\n\n");
926 printf("#define _ast_fltmax_exp_index\t%d\n", i);
927 for (i = 0; !(e & 1); e >>= 1, i++);
928 printf("#define _ast_fltmax_exp_shift\t%d\n\n", i);
935 tst - -DN=1 - -DN=2 note{ _ast_fltmax_t maximum integral type }end output{
941 unsigned long long m;
942 long double f = 123.456;
947 printf("#define _ast_flt_unsigned_max_t unsigned long long\n");
949 printf("#define _ast_flt_unsigned_max_t unsigned long\n");
955 tst - -DSCAN=1 - -lm -DSTRTO=1 - -DMAC=1 - -DDIV=1 - -DEXP=1 - -DADD=1 - -DMPY=1 note{ INF and NAN memory representations }end output{
957 #define _AIX_COMPATIBILITY 1
958 #define _FP_MODE_VARIABLE 1
960 #include "FEATURE/common"
962 #include <sys/types.h>
976 #if STRTO && _hdr_stdlib
979 #if !defined(FLT_MAX) && defined(MAXFLOAT)
980 #define FLT_MAX MAXFLOAT
982 #if !defined(DBL_MAX) && defined(MAXDOUBLE)
983 #define DBL_MAX MAXDOUBLE
985 #if _ast_fltmax_double
990 list(const char* typ, const char* var, void* val, int siz)
992 list(typ, var, val, siz)
999 register unsigned char* u = (unsigned char*)val;
1000 register unsigned char* e = u + siz;
1002 printf("#define _ast_%s_%s_init\t0x%02x", typ, var, *u);
1004 printf(",0x%02x", *u);
1019 if (sscanf(NAN, "%g", &f) != 1)
1024 list("flt", "nan", &f, sizeof(f));
1026 if (sscanf(INF, "%g", &f) != 1)
1031 list("flt", "inf", &f, sizeof(f));
1040 if (sscanf(NAN, "%lg", &f) != 1)
1043 f = strtod(NAN, &e);
1047 list("dbl", "nan", &f, sizeof(f));
1049 if (sscanf(INF, "%lg", &f) != 1)
1052 f = strtod(INF, &e);
1056 list("dbl", "inf", &f, sizeof(f));
1066 if (sscanf(NAN, "%Lg", &f) != 1)
1069 f = strtold(NAN, &e);
1073 list("ldbl", "nan", &f, sizeof(f));
1075 if (sscanf(INF, "%Lg", &f) != 1)
1078 f = strtold(INF, &e);
1082 list("ldbl", "inf", &f, sizeof(f));
1087 signal(SIGFPE, SIG_IGN);
1098 list("flt", "nan", &f, sizeof(f));
1100 list("flt", "inf", &f, sizeof(f));
1114 list("flt", "nan", &f, sizeof(f));
1118 list("flt", "inf", &f, sizeof(f));
1131 list("dbl", "nan", &f, sizeof(f));
1133 list("dbl", "inf", &f, sizeof(f));
1147 list("dbl", "nan", &f, sizeof(f));
1151 list("dbl", "inf", &f, sizeof(f));
1157 long double f = LDBL_MAX;
1164 list("ldbl", "nan", &f, sizeof(f));
1166 list("ldbl", "inf", &f, sizeof(f));
1180 list("ldbl", "nan", &f, sizeof(f));
1184 list("ldbl", "inf", &f, sizeof(f));