summaryrefslogtreecommitdiff
path: root/src/lib/libast/features/float
blob: de27bb235bb83f50cc823d33ce4772320431534e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
set	prototyped
set	nooptimize
set	stdio FEATURE/isoc99
hdr	float,limits,math,values
lib	fpclassify,frexp,frexpl,ldexp,ldexpl,finite,finitel,isinf,isinfl,isnan,isnanl,signbit,copysign,copysignl FEATURE/isoc99 math.h -lm

tst	ast_no_um2fm note{ no unsigned intmax => floatmax cast }end nolink{
	#include "FEATURE/common"
	int
	main()
	{
		_ast_fltmax_t		f = 0;
		unsigned _ast_intmax_t	i = 0;
		f = i;
		i = f;
		return f == i;
	}
}end

tst	ast_mpy_overflow_fpe note{ fpe on mpy overflow }end noexecute{
	int
	main()
	{
		float	f;
		float	p;
		int	i;

		i = 0;
		p = f = 1.0;
		do
		{
			p = f;
			f *= 2.0;
		} while (f != p && ++i < 1024);
		return 0;
	}
}end

tst	ast_div_underflow_fpe note{ fpe on div underflow }end noexecute{
	int
	main()
	{
		float	f;
		float	p;
		int	i;

		i = 0;
		p = f = 1.0;
		do
		{
			p = f;
			f /= 2.0;
		} while (f != p && ++i < 1024);
		return 0;
	}
}end

macro{
	#if _hdr_float
	#include <float.h>
	#endif
	#if _hdr_limits
	#include <limits.h>
	#endif
	#if _hdr_math
	#include <math.h>
	#endif
	#if _hdr_values
	#include <values.h>
	#endif

	#if !defined(FLT_MIN_EXP) && defined(FMINEXP)
	#define FLT_MIN_EXP	FMINEXP
	#endif
	#if !defined(FLT_MIN) && defined(MINFLOAT)
	#define FLT_MIN		MINFLOAT
	#endif
	#if !defined(FLT_MAX_EXP) && defined(FMAXEXP)
	#define FLT_MAX_EXP	FMAXEXP
	#endif
	#if !defined(FLT_MAX) && defined(MAXFLOAT)
	#define FLT_MAX		MAXFLOAT
	#endif

	#if !defined(DBL_MIN_EXP) && defined(DMINEXP)
	#define DBL_MIN_EXP	DMINEXP
	#endif
	#if !defined(DBL_MIN) && defined(MINDOUBLE)
	#define DBL_MIN		MINDOUBLE
	#endif
	#if !defined(DBL_MAX_EXP) && defined(DMAXEXP)
	#define DBL_MAX_EXP	DMAXEXP
	#endif
	#if !defined(DBL_MAX) && defined(MAXDOUBLE)
	#define DBL_MAX		MAXDOUBLE
	#endif

	<<"#include <ast_common.h>">>
	#if _hdr_float
	<<"#include <float.h>">>
	#endif
	#if _hdr_math
	<<"#include <math.h>">>
	#endif
	#ifdef FLT_DIG
	<<"#ifndef FLT_DIG">>
	<<"#define FLT_DIG">>		FLT_DIG
	<<"#endif">>
	#endif
	#ifdef FLT_MAX
	<<"#ifndef FLT_MAX">>
	<<"#define FLT_MAX">>		FLT_MAX
	<<"#endif">>
	#endif
	#ifdef FLT_MAX_10_EXP
	<<"#ifndef FLT_MAX_10_EXP">>
	<<"#define FLT_MAX_10_EXP">>	FLT_MAX_10_EXP
	<<"#endif">>
	#endif
	#ifdef FLT_MAX_EXP
	<<"#ifndef FLT_MAX_EXP">>
	<<"#define FLT_MAX_EXP">>	FLT_MAX_EXP
	<<"#endif">>
	#endif
	#ifdef FLT_MIN
	<<"#ifndef FLT_MIN">>
	<<"#define FLT_MIN">>		FLT_MIN
	<<"#endif">>
	#endif
	#ifdef FLT_MIN_10_EXP
	<<"#ifndef FLT_MIN_10_EXP">>
	<<"#define FLT_MIN_10_EXP">>	FLT_MIN_10_EXP
	<<"#endif">>
	#endif
	#ifdef FLT_MIN_EXP
	<<"#ifndef FLT_MIN_EXP">>
	<<"#define FLT_MIN_EXP">>	FLT_MIN_EXP
	<<"#endif">>
	#endif

	#ifdef DBL_DIG
	<<"#ifndef DBL_DIG">>
	<<"#define DBL_DIG">>		DBL_DIG
	<<"#endif">>
	#endif
	#ifdef DBL_MAX
	<<"#ifndef DBL_MAX">>
	<<"#define DBL_MAX">>		DBL_MAX
	<<"#endif">>
	#endif
	#ifdef DBL_MAX_10_EXP
	<<"#ifndef DBL_MAX_10_EXP">>
	<<"#define DBL_MAX_10_EXP">>	DBL_MAX_10_EXP
	<<"#endif">>
	#endif
	#ifdef DBL_MAX_EXP
	<<"#ifndef DBL_MAX_EXP">>
	<<"#define DBL_MAX_EXP">>	DBL_MAX_EXP
	<<"#endif">>
	#endif
	#ifdef DBL_MIN
	<<"#ifndef DBL_MIN">>
	<<"#define DBL_MIN">>		DBL_MIN
	<<"#endif">>
	#endif
	#ifdef DBL_MIN_10_EXP
	<<"#ifndef DBL_MIN_10_EXP">>
	<<"#define DBL_MIN_10_EXP">>	DBL_MIN_10_EXP
	<<"#endif">>
	#endif
	#ifdef DBL_MIN_EXP
	<<"#ifndef DBL_MIN_EXP">>
	<<"#define DBL_MIN_EXP">>	DBL_MIN_EXP
	<<"#endif">>
	#endif

	#ifdef LDBL_DIG
	<<"#ifndef LDBL_DIG">>
	<<"#define LDBL_DIG">>		LDBL_DIG
	<<"#endif">>
	#endif
	#ifdef LDBL_MAX
	<<"#ifndef LDBL_MAX">>
	<<"#define LDBL_MAX">>		LDBL_MAX
	<<"#endif">>
	#endif
	#ifdef LDBL_MAX_10_EXP
	<<"#ifndef LDBL_MAX_10_EXP">>
	<<"#define LDBL_MAX_10_EXP">>	LDBL_MAX_10_EXP
	<<"#endif">>
	#endif
	#ifdef LDBL_MAX_EXP
	<<"#ifndef LDBL_MAX_EXP">>
	<<"#define LDBL_MAX_EXP">>	LDBL_MAX_EXP
	<<"#endif">>
	#endif
	#ifdef LDBL_MIN
	<<"#ifndef LDBL_MIN">>
	<<"#define LDBL_MIN">>		LDBL_MIN
	<<"#endif">>
	#endif
	#ifdef LDBL_MIN_10_EXP
	<<"#ifndef LDBL_MIN_10_EXP">>
	<<"#define LDBL_MIN_10_EXP">>	LDBL_MIN_10_EXP
	<<"#endif">>
	#endif
	#ifdef LDBL_MIN_EXP
	<<"#ifndef LDBL_MIN_EXP">>
	<<"#define LDBL_MIN_EXP">>	LDBL_MIN_EXP
	<<"#endif">>
	#endif
}end

tst	- note{ missing floating point limits }end output{
	#include "FEATURE/common"
	#include <stdio.h>
	#if _hdr_float
	#include <float.h>
	#endif
	#if _hdr_limits
	#include <limits.h>
	#endif
	#if _hdr_math
	#include <math.h>
	#endif
	#if _hdr_values
	#include <values.h>
	#endif
	#include <signal.h>
	#ifdef SIGFPE
	static int caught = 0;
	#if _STD_
	static void catch(int sig)
	#else
	static void catch(sig) int sig;
	#endif
	{
		signal(sig, SIG_IGN);
		caught++;
	}
	#endif
	int
	main()
	{
		register int		i;
		register int		s;
		float			f;
		float			pf;
		float			mf;
		float			xf;
		double			d;
		double			pd;
		double			md;
		char*			fp;
	#if _ast_fltmax_double
		char*			fs = "";
		char*			ds = "";
	#else
		_ast_fltmax_t		l;
		_ast_fltmax_t		pl;
		_ast_fltmax_t		ml;
		char*			fs = "F";
		char*			ds = "";
		char*			ls = "L";
	#endif
		unsigned long		u;
		unsigned _ast_intmax_t	w;
		unsigned _ast_intmax_t	pw;
		unsigned _ast_intmax_t	x;
		unsigned short		us;
		unsigned int		ui;
		unsigned long		ul;
		unsigned _ast_intmax_t	uq;
	
	#ifdef SIGFPE
		signal(SIGFPE, catch);
	#endif
		printf("\n");
		printf("\n");
		us = 0;
		us = ~us;
		i = 0;
		while (us /= 10)
			i++;
		printf("#define USHRT_DIG		%d\n", i);
		ui = 0;
		ui = ~ui;
		i = 0;
		while (ui /= 10)
			i++;
		printf("#define UINT_DIG		%d\n", i);
		ul = 0;
		ul = ~ul;
		i = 0;
		while (ul /= 10)
			i++;
		printf("#define ULONG_DIG		%d\n", i);
		if (sizeof(uq) > sizeof(ul))
		{
			uq = 0;
			uq = ~uq;
			i = 0;
			while (uq /= 10)
				i++;
			printf("#define ULLONG_DIG		%d\n", i);
			printf("#define UINTMAX_DIG		ULLONG_DIG\n");
		}
		else
			printf("#define UINTMAX_DIG		ULONG_DIG\n");
		printf("\n");
		w = 1;
		do
		{
			pw = w;
			w *= 2;
			f = (_ast_intmax_t)w;
			x = (_ast_intmax_t)f;
		} while (w > pw && w == x);
		w = (pw - 1) + pw;
		u = ~0;
		if (u > w)
			u = w;
		printf("#define FLT_ULONG_MAX		%lu.0F\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define FLT_ULLONG_MAX		%llu.0F\n", w);
			printf("#define FLT_UINTMAX_MAX		FLT_ULLONG_MAX\n");
		}
		else
		{
			printf("#define FLT_ULLONG_MAX		FLT_ULONG_MAX\n");
			printf("#define FLT_UINTMAX_MAX		FLT_ULONG_MAX\n");
		}
		u /= 2;
		w /= 2;
		printf("#define FLT_LONG_MAX		%lu.0F\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define FLT_LLONG_MAX		%llu.0F\n", w);
			printf("#define FLT_INTMAX_MAX		FLT_LLONG_MAX\n");
		}
		else
		{
			printf("#define FLT_LLONG_MAX		FLT_LONG_MAX\n");
			printf("#define FLT_INTMAX_MAX		FLT_LONG_MAX\n");
		}
		u++;
		w++;
		printf("#define FLT_LONG_MIN		(-%lu.0F)\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define FLT_LLONG_MIN		(-%llu.0F)\n", w);
			printf("#define FLT_INTMAX_MIN		FLT_LLONG_MIN\n");
		}
		else
		{
			printf("#define FLT_LLONG_MIN		FLT_LONG_MIN\n");
			printf("#define FLT_INTMAX_MIN		FLT_LONG_MIN\n");
		}
	#ifdef FLT_DIG
		s = FLT_DIG;
	#else
		f = pf = 1.0;
		s = -1;
		do
		{
			s++;
			f *= 10.0;
		} while (f != (f + pf));
	#endif
	#if defined(FLT_MIN) && defined(FLT_MIN_EXP)
		i = FLT_MIN_EXP;
		mf = FLT_MIN;
	#else
		i = 3;
		f = pf = 1.0;
		do
		{
			i--;
			mf = pf;
			pf = f;
			f /= 2.0;
		} while (f < pf);
	#ifdef FLT_MIN_EXP
		i = FLT_MIN_EXP;
	#endif
	#ifdef FLT_MIN
		mf = FLT_MIN;
	#endif
	#endif
	#ifndef FLT_DIG
		printf("#ifndef FLT_DIG\n");
		printf("#define FLT_DIG			%d\n", s);
		printf("#endif\n");
	#endif
	#ifndef FLT_MIN
		printf("#ifndef FLT_MIN\n");
		printf("#define FLT_MIN			%.*E%s\n", s + 1, mf, fs);
		printf("#endif\n");
	#endif
	#ifndef FLT_MIN_EXP
		printf("#ifndef FLT_MIN_EXP\n");
		printf("#define FLT_MIN_EXP		(%d)\n", i);
		printf("#endif\n");
	#endif

	#if defined(FLT_MAX) && defined(FLT_MAX_EXP)
		i = FLT_MAX_EXP;
		f = FLT_MAX;
	#else
		i = -1;
		f = pf = 1.0;
		do
		{
			i++;
			mf = pf;
			pf = f;
			f *= 2.0;
		} while (f > pf);
	#ifdef FLT_MAX_EXP
		i = FLT_MAX_EXP;
	#endif
	#ifdef FLT_MAX
		f = FLT_MAX;
	#endif
	#endif
	#ifdef FLT_MAX_EXP
		i = FLT_MAX_EXP;
	#else
		f = 1;
		do
		{
			f *= 2.0;
		} while (mf == (mf + f));
		f = (mf - f) * 2.0 + f;
	#endif
		xf = f;
	#ifndef FLT_MAX
		printf("#ifndef FLT_MAX\n");
		printf("#define FLT_MAX			%.*E%s\n", s + 1, f, fs);
		printf("#endif\n");
	#endif
	#ifndef FLT_MAX_EXP
		printf("#ifndef FLT_MAX_EXP\n");
		printf("#define FLT_MAX_EXP		%d\n", i);
		printf("#endif\n");
	#endif

	#ifdef FLT_MIN_10_EXP
		i = FLT_MIN_10_EXP;
	#else
		i = 2;
		f = 1.0;
		do
		{
			i--;
			pf = f;
			f /= 10.0;
		} while (f < pf);
	#endif
	#ifndef FLT_MIN_10_EXP
		printf("#ifndef FLT_MIN_10_EXP\n");
		printf("#define FLT_MIN_10_EXP		(%d)\n", i);
		printf("#endif\n");
	#endif

	#ifdef FLT_MAX_10_EXP
		i = FLT_MAX_10_EXP;
	#else
		i = -2;
		f = 1.0;
		do
		{
			i++;
			pf = f;
			f *= 10.0;
		} while (f > pf);
	#endif
	#ifndef FLT_MAX_10_EXP
		printf("#ifndef FLT_MAX_10_EXP\n");
		printf("#define FLT_MAX_10_EXP		%d\n", i);
		printf("#endif\n");
	#endif

		printf("\n");
		w = 1;
		do
		{
			pw = w;
			w *= 2;
			d = (_ast_intmax_t)w;
			x = (_ast_intmax_t)d;
		} while (w > pw && w == x);
		w = (pw - 1) + pw;
		u = ~0;
		if (u > w)
			u = w;
		printf("#define DBL_ULONG_MAX		%lu.0\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define DBL_ULLONG_MAX		%llu.0\n", w);
			printf("#define DBL_UINTMAX_MAX		DBL_ULLONG_MAX\n");
		}
		else
		{
			printf("#define DBL_ULLONG_MAX		DBL_ULONG_MAX\n");
			printf("#define DBL_UINTMAX_MAX		DBL_ULONG_MAX\n");
		}
		u /= 2;
		w /= 2;
		printf("#define DBL_LONG_MAX		%lu.0\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define DBL_LLONG_MAX		%llu.0\n", w);
			printf("#define DBL_INTMAX_MAX		DBL_LLONG_MAX\n");
		}
		else
		{
			printf("#define DBL_LLONG_MAX		DBL_LONG_MAX\n");
			printf("#define DBL_INTMAX_MAX		DBL_LONG_MAX\n");
		}
		u++;
		w++;
		printf("#define DBL_LONG_MIN		(-%lu.0)\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define DBL_LLONG_MIN		(-%llu.0)\n", w);
			printf("#define DBL_INTMAX_MIN		DBL_LLONG_MIN\n");
		}
		else
		{
			printf("#define DBL_LLONG_MIN		DBL_LONG_MIN\n");
			printf("#define DBL_INTMAX_MIN		DBL_LONG_MIN\n");
		}
	#ifdef DBL_DIG
		s = DBL_DIG;
	#else
		d = pd = 1.0;
		s = -1;
		do
		{
			s++;
			d *= 10.0;
		} while (d != (d + pd));
	#endif
	#if defined(DBL_MIN) && defined(DBL_MIN_EXP)
		i = DBL_MIN_EXP;
		md = DBL_MIN;
	#else
		i = 3;
		d = pd = 1.0;
		do
		{
			i--;
			md = pd;
			pd = d;
			d /= 2.0;
		} while (d < pd);
	#ifdef DBL_MIN_EXP
		i = DBL_MIN_EXP;
	#endif
	#ifdef DBL_MIN
		md = DBL_MIN;
	#endif
	#endif
	#ifndef DBL_DIG
		printf("#ifndef DBL_DIG\n");
		printf("#define DBL_DIG			%d\n", s);
		printf("#endif\n");
	#endif
	#ifndef DBL_MIN
		printf("#ifndef DBL_MIN\n");
		printf("#define DBL_MIN			%.*E%s\n", s + 1, md, ds);
		printf("#endif\n");
	#endif
	#ifndef DBL_MIN_EXP
		printf("#ifndef DBL_MIN_EXP\n");
		printf("#define DBL_MIN_EXP		(%d)\n", i);
		printf("#endif\n");
	#endif

	#if defined(DBL_MAX) && defined(DBL_MAX_EXP)
		i = DBL_MAX_EXP;
		d = DBL_MAX;
	#else
		i = -1;
		d = pd = 1.0;
		do
		{
			i++;
			md = pd;
			pd = d;
			d *= 2.0;
		} while (d > pd);
		d = 1.0;
		do
		{
			d *= 2.0;
		} while (md == (md + d));
		d = (md - d) * 2.0 + d;
	#ifdef DBL_MAX_EXP
		i = DBL_MAX_EXP;
	#endif
	#ifdef DBL_MAX
		d = DBL_MAX;
	#endif
	#endif
	#ifndef DBL_MAX
		printf("#ifndef DBL_MAX\n");
		printf("#define DBL_MAX			%.*E%s\n", s + 1, d, ds);
		printf("#endif\n");
	#endif
	#ifndef DBL_MAX_EXP
		printf("#ifndef DBL_MAX_EXP\n");
		printf("#define DBL_MAX_EXP		%d\n", i);
		printf("#endif\n");
	#endif

	#ifdef DBL_MIN_10_EXP
		i = DBL_MIN_10_EXP;
	#else
		i = 2;
		d = 1.0;
		do
		{
			i--;
			pd = d;
			d /= 10.0;
		} while (d < pd);
	#endif
	#ifndef DBL_MIN_10_EXP
		printf("#ifndef DBL_MIN_10_EXP\n");
		printf("#define DBL_MIN_10_EXP		(%d)\n", i);
		printf("#endif\n");
	#endif

	#ifdef DBL_MAX_10_EXP
		i = DBL_MAX_10_EXP;
	#else
		i = -2;
		d = 1.0;
		do
		{
			i++;
			pd = d;
			d *= 10.0;
		} while (d > pd);
	#endif
	#ifndef DBL_MAX_10_EXP
		printf("#ifndef DBL_MAX_10_EXP\n");
		printf("#define DBL_MAX_10_EXP		%d\n", i);
		printf("#endif\n");
	#endif

	#if !_ast_fltmax_double
		printf("\n");
		w = 1;
		do
		{
			pw = w;
			w *= 2;
			l = (_ast_intmax_t)w;
			x = (_ast_intmax_t)l;
		} while (w > pw && w == x);
		w = (pw - 1) + pw;
		u = ~0;
		if (u > w)
			u = w;
		printf("#define LDBL_ULONG_MAX		%lu.0L\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define LDBL_ULLONG_MAX		%llu.0L\n", w);
			printf("#define LDBL_UINTMAX_MAX	LDBL_ULLONG_MAX\n");
		}
		else
		{
			printf("#define LDBL_ULLONG_MAX		LDBL_ULONG_MAX\n");
			printf("#define LDBL_UINTMAX_MAX	LDBL_ULONG_MAX\n");
		}
		u /= 2;
		w /= 2;
		printf("#define LDBL_LONG_MAX		%lu.0L\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define LDBL_LLONG_MAX		%llu.0L\n", w);
			printf("#define LDBL_INTMAX_MAX		LDBL_LLONG_MAX\n");
		}
		else
		{
			printf("#define LDBL_LLONG_MAX		LDBL_LONG_MAX\n");
			printf("#define LDBL_INTMAX_MAX		LDBL_LONG_MAX\n");
		}
		u++;
		w++;
		printf("#define LDBL_LONG_MIN		(-%lu.0L)\n", u);
		if (sizeof(w) > sizeof(u))
		{
			printf("#define LDBL_LLONG_MIN		(-%llu.0L)\n", w);
			printf("#define LDBL_INTMAX_MIN		LDBL_LLONG_MIN\n");
		}
		else
		{
			printf("#define LDBL_LLONG_MIN		LDBL_LONG_MIN\n");
			printf("#define LDBL_INTMAX_MIN		LDBL_LONG_MIN\n");
		}
	#ifdef LDBL_DIG
		s = LDBL_DIG;
	#else
		l = pl = 1.0L;
		s = -1;
		do
		{
			s++;
			l *= 10.0L;
		} while (l != (l + pl));
	#endif
	#if defined(LDBL_MIN) && defined(LDBL_MIN_EXP)
		i = LDBL_MIN_EXP;
		ml = LDBL_MIN;
	#else
		i = 3;
		l = pl = 1.0L;
		do
		{
			i--;
			ml = pl;
			pl = l;
			l /= 2.0L;
		} while (l < pl);
	#ifdef LDBL_MIN_EXP
		i = LDBL_MIN_EXP;
	#endif
	#ifdef LDBL_MIN
		ml = LDBL_MIN;
	#endif
	#endif
	#ifndef LDBL_DIG
		printf("#ifndef LDBL_DIG\n");
		printf("#define LDBL_DIG		%d\n", s);
		printf("#endif\n");
	#endif
	#ifndef LDBL_MIN
		printf("#ifndef LDBL_MIN\n");
		printf("#define LDBL_MIN		%.*LE%s\n", s + 1, ml, ls);
		printf("#endif\n");
	#endif
	#ifndef LDBL_MIN_EXP
		printf("#ifndef LDBL_MIN_EXP\n");
		printf("#define LDBL_MIN_EXP		(%d)\n", i);
		printf("#endif\n");
	#endif

	#if defined(LDBL_MAX) && defined(LDBL_MAX_EXP)
		i = LDBL_MAX_EXP;
		l = LDBL_MAX;
	#else
		i = -1;
		l = pl = 1.0L;
		do
		{
			i++;
			ml = pl;
			pl = l;
			l *= 2.0L;
		} while (l > pl);
		l = 1.0L;
		do
		{
			l *= 2.0L;
		} while (ml == (ml + l));
		l = (ml - l) * 2.0L + l;
	#ifdef LDBL_MAX_EXP
		i = LDBL_MAX_EXP;
	#endif
	#ifdef LDBL_MAX
		l = LDBL_MAX;
	#endif
	#endif
	#ifndef LDBL_MAX
		printf("#ifndef LDBL_MAX\n");
		printf("#define LDBL_MAX		%.*LE%s\n", s + 1, l, ls);
		printf("#endif\n");
	#endif
	#ifndef LDBL_MAX_EXP
		printf("#ifndef LDBL_MAX_EXP\n");
		printf("#define LDBL_MAX_EXP		%d\n", i);
		printf("#endif\n");
	#endif

	#ifdef LDBL_MIN_10_EXP
		i = LDBL_MIN_10_EXP;
	#else
		i = 2;
		l = 1.0L;
		do
		{
			i--;
			pl = l;
			l /= 10.0L;
		} while (l < pl);
	#endif
	#ifndef LDBL_MIN_10_EXP
		printf("#ifndef LDBL_MIN_10_EXP\n");
		printf("#define LDBL_MIN_10_EXP		(%d)\n", i);
		printf("#endif\n");
	#endif

	#ifdef LDBL_MAX_10_EXP
		i = LDBL_MAX_10_EXP;
	#else
		i = -2;
		l = 1.0L;
		do
		{
			i++;
			pl = l;
			l *= 10.0L;
		} while (l > pl);
	#endif
	#ifndef LDBL_MAX_10_EXP
		printf("#ifndef LDBL_MAX_10_EXP\n");
		printf("#define LDBL_MAX_10_EXP		%d\n", i);
		printf("#endif\n");
	#endif
		fp = "LDBL";
	#else
		fp = "DBL";
	#endif

	printf("\n");
	printf("#define FLTMAX_UINTMAX_MAX	%s_UINTMAX_MAX\n", fp);
	printf("#define FLTMAX_INTMAX_MAX	%s_INTMAX_MAX\n", fp);
	printf("#define FLTMAX_INTMAX_MIN	%s_INTMAX_MIN\n", fp);

	#ifdef SIGFPE
		if (!caught)
		{
	#if !__MVS__
			f = xf;
			f *= 2;
			if (!f)
	#endif
				caught = 1;
		}
		if (caught)
			printf("\n#define _ast_fltsig		%d\n", SIGFPE);
	#endif

		printf("\n");
	#if !_lib_frexp
		printf("extern double		frexp(double, int*);\n");
	#endif
	#if !_lib_frexpl
		printf("extern _ast_fltmax_t	frexpl(_ast_fltmax_t, int*);\n");
	#endif
	#if !_lib_ldexp
		printf("extern double		ldexp(double, int);\n");
	#endif
	#if !_lib_ldexpl
		printf("extern _ast_fltmax_t	ldexpl(_ast_fltmax_t, int);\n");
	#endif

		return 0;
	}
}end

tst	- note{ double exponent bitfoolery }end output{
	#include "FEATURE/common"
	#include <stdio.h>
	typedef union _dbl_exp_u
	{
		unsigned _ast_int4_t	e[sizeof(double) / 4];
		double			f;
	} _ast_dbl_exp_t;
	int
	main()
	{
		int			i;
		int			j;
		unsigned _ast_int4_t	e;
		_ast_dbl_exp_t		a;
		_ast_dbl_exp_t		b;
		a.f = 1;
		b.f = 2;
		for (i = 0; i < sizeof(a.e) / sizeof(a.e[0]); i++)
			if (e = a.e[i] ^ b.e[i])
			{
				for (j = i + 1; j < sizeof(a.e) / sizeof(a.e[0]); j++)
					if (a.e[j] ^ b.e[j])
						return 0;
				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");
				printf("#define _ast_dbl_exp_index	%d\n", i);
				for (i = 0; !(e & 1); e >>= 1, i++);
				printf("#define _ast_dbl_exp_shift	%d\n\n", i);
				return 0;
			}
		return 0;
	}
}end

tst	- note{ long double exponent bitfoolery }end output{
	#include "FEATURE/common"
	#include <stdio.h>
	typedef union _ast_fltmax_exp_u
	{
		unsigned _ast_int4_t	e[sizeof(_ast_fltmax_t) / 4];
		_ast_fltmax_t		f;
	} _ast_fltmax_exp_t;
	int
	main()
	{
		int			i;
		int			j;
		unsigned _ast_int4_t	e;
		_ast_fltmax_exp_t	a;
		_ast_fltmax_exp_t	b;
		a.f = 1;
		b.f = 2;
		for (i = 0; i < sizeof(a.e) / sizeof(a.e[0]); i++)
			if (e = a.e[i] ^ b.e[i])
			{
				for (j = i + 1; j < sizeof(a.e) / sizeof(a.e[0]); j++)
					if (a.e[j] ^ b.e[j])
						return 0;
				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");
				printf("#define _ast_fltmax_exp_index\t%d\n", i);
				for (i = 0; !(e & 1); e >>= 1, i++);
				printf("#define _ast_fltmax_exp_shift\t%d\n\n", i);
				return 0;
			}
		return 0;
	}
}end

tst	- -DN=1 - -DN=2 note{ _ast_fltmax_t maximum integral type }end output{
	#include <stdio.h>
	int
	main()
	{
	#if N == 1
		unsigned long long	m;
		long double		f = 123.456;

		m = f;
		if (!m || f == m)
			return 1;
		printf("#define _ast_flt_unsigned_max_t	unsigned long long\n");
	#else
		printf("#define _ast_flt_unsigned_max_t	unsigned long\n");
	#endif
		return 0;
	}
}end

tst	- -DSCAN=1 - -lm -DSTRTO=1 - -DMAC=1 - -DDIV=1 - -DEXP=1 - -DADD=1 - -DMPY=1 note{ INF and NAN memory representations }end output{
	#if MAC
	#define _AIX_COMPATIBILITY	1
	#define _FP_MODE_VARIABLE	1
	#endif
	#include "FEATURE/common"
	#include <stdio.h>
	#include <sys/types.h>
	#include <signal.h>
	#if _hdr_float
	#include <float.h>
	#endif
	#if _hdr_limits
	#include <limits.h>
	#endif
	#if _hdr_math
	#include <math.h>
	#endif
	#if _hdr_values
	#include <values.h>
	#endif
	#if STRTO && _hdr_stdlib
	#include <stdlib.h>
	#endif
	#if !defined(FLT_MAX) && defined(MAXFLOAT)
	#define FLT_MAX		MAXFLOAT
	#endif
	#if !defined(DBL_MAX) && defined(MAXDOUBLE)
	#define DBL_MAX		MAXDOUBLE
	#endif
	#if _ast_fltmax_double
	#undef	LDBL_MAX
	#endif
	static void
	#if _STD_
	list(const char* typ, const char* var, void* val, int siz)
	#else
	list(typ, var, val, siz)
	char* typ;
	char* var;
	void* val;
	int siz;
	#endif
	{
		register unsigned char*	u = (unsigned char*)val;
		register unsigned char*	e = u + siz;
	
		printf("#define _ast_%s_%s_init\t0x%02x", typ, var, *u);
		while (++u < e)
			printf(",0x%02x", *u);
		printf("\n");
	}
	int
	main()
	{
	#if SCAN || STRTO
	#undef	NAN
	#define NAN	"NaN"
	#undef	INF
	#define INF	"INF"
	{
		float	f;

	#if SCAN
		if (sscanf(NAN, "%g", &f) != 1)
			return 1;
	#else
		f = atof(NAN);
	#endif
		list("flt", "nan", &f, sizeof(f));
	#if SCAN
		if (sscanf(INF, "%g", &f) != 1)
			return 1;
	#else
		f = atof(INF);
	#endif
		list("flt", "inf", &f, sizeof(f));
	}
	{
		double	f;
	#if STRTO
		char*	e;
	#endif

	#if SCAN
		if (sscanf(NAN, "%lg", &f) != 1)
			return 1;
	#else
		f = strtod(NAN, &e);
		if (*e)
			return 1;
	#endif
		list("dbl", "nan", &f, sizeof(f));
	#if SCAN
		if (sscanf(INF, "%lg", &f) != 1)
			return 1;
	#else
		f = strtod(INF, &e);
		if (*e)
			return 1;
	#endif
		list("dbl", "inf", &f, sizeof(f));
	}
	#ifdef LDBL_MAX
	{
		long double	f;
	#if STRTO
		char*	e;
	#endif

	#if SCAN
		if (sscanf(NAN, "%Lg", &f) != 1)
			return 1;
	#else
		f = strtold(NAN, &e);
		if (*e)
			return 1;
	#endif
		list("ldbl", "nan", &f, sizeof(f));
	#if SCAN
		if (sscanf(INF, "%Lg", &f) != 1)
			return 1;
	#else
		f = strtold(INF, &e);
		if (*e)
			return 1;
	#endif
		list("ldbl", "inf", &f, sizeof(f));
	}
	#endif
	#else
	#ifdef SIGFPE
		signal(SIGFPE, SIG_IGN);
	#endif
	#ifdef FLT_MAX
		{
			float	f = FLT_MAX;
	#if DIV
			float	z = 0;

			f = 0.0 / z;
			if (!f)
				return 1;
			list("flt", "nan", &f, sizeof(f));
			f = 1.0 / z;
			list("flt", "inf", &f, sizeof(f));
	#else
	#if ADD
			f += f;
	#endif
	#if EXP
			f = exp(f);
	#endif
	#if MPY
			f *= 2;
	#endif
	#if MAC
			f = FLT_QNAN;
	#endif
			list("flt", "nan", &f, sizeof(f));
	#if MAC
			f = FLT_INFINITY;
	#endif
			list("flt", "inf", &f, sizeof(f));
	#endif
		}
	#endif
	#ifdef DBL_MAX
		{
			double	f = DBL_MAX;
	#if DIV
			double	z = 0;

			f = 0.0 / z;
			if (!f)
				return 1;
			list("dbl", "nan", &f, sizeof(f));
			f = 1.0 / z;
			list("dbl", "inf", &f, sizeof(f));
	#else
	#if ADD
			f += f;
	#endif
	#if EXP
			f = exp(f);
	#endif
	#if MPY
			f *= 2;
	#endif
	#if MAC
			f = DBL_QNAN;
	#endif
			list("dbl", "nan", &f, sizeof(f));
	#if MAC
			f = DBL_INFINITY;
	#endif
			list("dbl", "inf", &f, sizeof(f));
	#endif
		}
	#endif
	#ifdef LDBL_MAX
		{
			long double	f = LDBL_MAX;
	#if DIV
			long double	z = 0;

			f = 0.0 / z;
			if (!f)
				return 1;
			list("ldbl", "nan", &f, sizeof(f));
			f = 1.0 / z;
			list("ldbl", "inf", &f, sizeof(f));
	#else
	#if ADD
			f += f;
	#endif
	#if EXP
			f = exp(f);
	#endif
	#if MPY
			f *= 2;
	#endif
	#if MAC
			f = LDBL_QNAN;
	#endif
			list("ldbl", "nan", &f, sizeof(f));
	#if MAC
			f = LDBL_INFINITY;
	#endif
			list("ldbl", "inf", &f, sizeof(f));
	#endif
		}
	#endif
	#endif
		return 0;
	}
}end