xref: /freebsd/usr.bin/m4/TEST/math.m4 (revision af0a81b6470aba4af4a24ae9804053722846ded4)
1dnl A regression test for m4 C operators		(ksb,petef)
2dnl If you think you have a short-circuiting m4, run us m4 -DSHORCIRCUIT=yes
3dnl
4dnl first level of precedence
5ifelse(expr(-7),-7,,`failed -
6')dnl
7ifelse(expr(- -2),2,,`failed -
8')dnl
9ifelse(expr(!0),1,,`failed !
10')dnl
11ifelse(expr(!7),0,,`failed !
12')dnl
13ifelse(expr(~-1),0,,`failed ~
14')dnl
15dnl next level of precedence
16ifelse(expr(3*5),15,,`failed *
17')dnl
18ifelse(expr(3*0),0,,`failed *
19')dnl
20ifelse(expr(11/2),5,,`failed /
21')dnl
22ifelse(expr(1/700),0,,`failed /
23')dnl
24ifelse(expr(10%5),0,,`failed %
25')dnl
26ifelse(expr(2%5),2,,`failed %
27')dnl
28ifelse(expr(2%-1),0,,`failed %
29')dnl
30dnl next level of precedence
31ifelse(expr(2+2),4,,`failed +
32')dnl
33ifelse(expr(2+-2),0,,`failed +
34')dnl
35ifelse(expr(2- -2),4,,`failed -
36')dnl
37ifelse(expr(2-2),0,,`failed -
38')dnl
39dnl next level of precedence
40ifelse(expr(1<<4),16,,`failed <<
41')dnl
42ifelse(expr(16>>4),1,,`failed >>
43')dnl
44dnl next level of precedence
45ifelse(expr(4<4),0,,`failed <
46')dnl
47ifelse(expr(4<5),1,,`failed <
48')dnl
49ifelse(expr(4<3),0,,`failed <
50')dnl
51ifelse(expr(4>4),0,,`failed >
52')dnl
53ifelse(expr(4>5),0,,`failed >
54')dnl
55ifelse(expr(4>3),1,,`failed >
56')dnl
57ifelse(expr(4<=4),1,,`failed <=
58')dnl
59ifelse(expr(4<=5),1,,`failed <=
60')dnl
61ifelse(expr(4<=3),0,,`failed <=
62')dnl
63ifelse(expr(4>=4),1,,`failed >=
64')dnl
65ifelse(expr(4>=5),0,,`failed >=
66')dnl
67ifelse(expr(4>=3),1,,`failed >=
68')dnl
69dnl next level of precedence
70ifelse(expr(1==1),1,,`failed ==
71')dnl
72ifelse(expr(1==-1),0,,`failed ==
73')dnl
74ifelse(expr(1!=1),0,,`failed !=
75')dnl
76ifelse(expr(1!=2),1,,`failed !=
77')dnl
78dnl next level of precedence
79ifelse(expr(3&5),1,,`failed &
80')dnl
81ifelse(expr(8&7),0,,`failed &
82')dnl
83dnl next level of precedence
84ifelse(expr(1^1),0,,`failed ^
85')dnl
86ifelse(expr(21^5),16,,`failed ^
87')dnl
88dnl next level of precedence
89ifelse(expr(1|1),1,,`failed |
90')dnl
91ifelse(expr(21|5),21,,`failed |
92')dnl
93ifelse(expr(100|1),101,,`failed |
94')dnl
95dnl next level of precedence
96ifelse(expr(1&&1),1,,`failed &&
97')dnl
98ifelse(expr(0&&1),0,,`failed &&
99')dnl
100ifelse(expr(1&&0),0,,`failed &&
101')dnl
102ifelse(SHORTCIRCUIT,`yes',`ifelse(expr(0&&10/0),0,,`failed && shortcircuit
103')')dnl
104dnl next level of precedence
105ifelse(expr(1||1),1,,`failed ||
106')dnl
107ifelse(expr(1||0),1,,`failed ||
108')dnl
109ifelse(expr(0||0),0,,`failed ||
110')dnl
111ifelse(SHORTCIRCUIT,`yes',`ifelse(expr(1||10/0),1,,`failed || shortcircuit
112')')dnl
113dnl next level of precedence
114ifelse(expr(0 ? 2 : 5),5,,`failed ?:
115')dnl
116ifelse(expr(1 ? 2 : 5),2,,`failed ?:
117')dnl
118ifelse(SHORTCIRCUIT,`yes',`ifelse(expr(0 ? 10/0 : 7),7,,`failed ?: shortcircuit
119')')dnl
120ifelse(SHORTCIRCUIT,`yes',`ifelse(expr(1 ? 7 : 10/0),7,,`failed ?: shortcircuit
121')')dnl
122dnl operator precedence
123ifelse(expr(!0*-2),-2,,`precedence wrong, ! *
124')dnl
125ifelse(expr(~8/~2),3,,`precedence wrong ~ /
126')dnl
127ifelse(expr(~-20%7),5,,`precedence wrong ~ %
128')dnl
129ifelse(expr(3*2+100),106,,`precedence wrong * +
130')dnl
131ifelse(expr(3+2*100),203,,`precedence wrong + *
132')dnl
133ifelse(expr(2%5-6/3),0,,`precedence wrong % -
134')dnl
135ifelse(expr(2/5-5%3),-2,,`precedence wrong / -
136')dnl
137ifelse(expr(2+5%5+1),3,,`precedence wrong % +
138')dnl
139ifelse(expr(7+9<<1),32,,`precedence wrong + <<
140')dnl
141ifelse(expr(35-3>>2),8,,`precedence wrong - >>
142')dnl
143ifelse(expr(9<10<<5),1,,`precedence wrong << <
144')dnl
145ifelse(expr(9>10<<5),0,,`precedence wrong << >
146')dnl
147ifelse(expr(32>>2<32),1,,`precedence wrong >> <
148')dnl
149ifelse(expr(9<=10<<5),1,,`precedence wrong << <
150')dnl
151ifelse(expr(5<<1<=20>>1),1,,`precedence wrong << <=
152')dnl
153ifelse(expr(5<<1>=20>>1),1,,`precedence wrong << >=
154')dnl
155ifelse(expr(0<7==5>=5),1,,`precedence wrong < ==
156')dnl
157ifelse(expr(0<7!=5>=5),0,,`precedence wrong < !=
158')dnl
159ifelse(expr(0>7==5>=5),0,,`precedence wrong > ==
160')dnl
161ifelse(expr(0>7!=5>=5),1,,`precedence wrong > !=
162')dnl
163ifelse(expr(1&7==7),1,,`precedence wrong & ==
164')dnl
165ifelse(expr(0&7!=6),0,,`precedence wrong & !=
166')dnl
167ifelse(expr(9&1|5),5,,`precedence wrong & |
168')dnl
169ifelse(expr(9&1^5),4,,`precedence wrong & ^
170')dnl
171ifelse(expr(9^1|5),13,,`precedence wrong ^ |
172')dnl
173ifelse(expr(5|0&&1),1,,`precedence wrong | &&
174')dnl
175ifelse(expr(5&&0||0&&5||5),1,,`precedence wrong && ||
176')dnl
177ifelse(expr(0 || 1 ? 0 : 1),0,,`precedence wrong || ?:
178')dnl
179ifelse(expr(5&&(0||0)&&(5||5)),0,,`precedence wrong || parens
180')dnl
181