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