1 dnl $NetBSD: math.m4,v 1.2 2005/10/06 17:38:09 drochner Exp $
2 dnl FreeBSD: /repoman/r/ncvs/src/usr.bin/m4/TEST/math.m4,v 1.1 2004/05/01 03:27:05 smkelly Exp
3 dnl A regression test for m4 C operators (ksb,petef)
4 dnl If you think you have a short-circuiting m4, run us m4 -DSHORCIRCUIT=yes
6 dnl first level of precedence
7 ifelse(eval(-7),-7,,`failed -
9 ifelse(eval(- -2),2,,`failed -
11 ifelse(eval(!0),1,,`failed !
13 ifelse(eval(!7),0,,`failed !
15 ifelse(eval(~-1),0,,`failed ~
17 dnl next level of precedence
18 ifelse(eval(3*5),15,,`failed *
20 ifelse(eval(3*0),0,,`failed *
22 ifelse(eval(11/2),5,,`failed /
24 ifelse(eval(1/700),0,,`failed /
26 ifelse(eval(10%5),0,,`failed %
28 ifelse(eval(2%5),2,,`failed %
30 ifelse(eval(2%-1),0,,`failed %
32 dnl next level of precedence
33 ifelse(eval(2+2),4,,`failed +
35 ifelse(eval(2+-2),0,,`failed +
37 ifelse(eval(2- -2),4,,`failed -
39 ifelse(eval(2-2),0,,`failed -
41 dnl next level of precedence
42 ifelse(eval(1<<4),16,,`failed <<
44 ifelse(eval(16>>4),1,,`failed >>
46 dnl next level of precedence
47 ifelse(eval(4<4),0,,`failed <
49 ifelse(eval(4<5),1,,`failed <
51 ifelse(eval(4<3),0,,`failed <
53 ifelse(eval(4>4),0,,`failed >
55 ifelse(eval(4>5),0,,`failed >
57 ifelse(eval(4>3),1,,`failed >
59 ifelse(eval(4<=4),1,,`failed <=
61 ifelse(eval(4<=5),1,,`failed <=
63 ifelse(eval(4<=3),0,,`failed <=
65 ifelse(eval(4>=4),1,,`failed >=
67 ifelse(eval(4>=5),0,,`failed >=
69 ifelse(eval(4>=3),1,,`failed >=
71 dnl next level of precedence
72 ifelse(eval(1==1),1,,`failed ==
74 ifelse(eval(1==-1),0,,`failed ==
76 ifelse(eval(1!=1),0,,`failed !=
78 ifelse(eval(1!=2),1,,`failed !=
80 dnl next level of precedence
81 ifelse(eval(3&5),1,,`failed &
83 ifelse(eval(8&7),0,,`failed &
85 dnl next level of precedence
86 ifelse(eval(1^1),0,,`failed ^
88 ifelse(eval(21^5),16,,`failed ^
90 dnl next level of precedence
91 ifelse(eval(1|1),1,,`failed |
93 ifelse(eval(21|5),21,,`failed |
95 ifelse(eval(100|1),101,,`failed |
97 dnl next level of precedence
98 ifelse(eval(1&&1),1,,`failed &&
100 ifelse(eval(0&&1),0,,`failed &&
102 ifelse(eval(1&&0),0,,`failed &&
104 ifelse(SHORTCIRCUIT,`yes',`ifelse(eval(0&&10/0),0,,`failed && shortcircuit
106 dnl next level of precedence
107 ifelse(eval(1||1),1,,`failed ||
109 ifelse(eval(1||0),1,,`failed ||
111 ifelse(eval(0||0),0,,`failed ||
113 ifelse(SHORTCIRCUIT,`yes',`ifelse(eval(1||10/0),1,,`failed || shortcircuit
115 dnl next level of precedence
116 ifelse(eval(0 ? 2 : 5),5,,`failed ?:
118 ifelse(eval(1 ? 2 : 5),2,,`failed ?:
120 ifelse(SHORTCIRCUIT,`yes',`ifelse(eval(0 ? 10/0 : 7),7,,`failed ?: shortcircuit
122 ifelse(SHORTCIRCUIT,`yes',`ifelse(eval(1 ? 7 : 10/0),7,,`failed ?: shortcircuit
124 dnl operator precedence
125 ifelse(eval(!0*-2),-2,,`precedence wrong, ! *
127 ifelse(eval(~8/~2),3,,`precedence wrong ~ /
129 ifelse(eval(~-20%7),5,,`precedence wrong ~ %
131 ifelse(eval(3*2+100),106,,`precedence wrong * +
133 ifelse(eval(3+2*100),203,,`precedence wrong + *
135 ifelse(eval(2%5-6/3),0,,`precedence wrong % -
137 ifelse(eval(2/5-5%3),-2,,`precedence wrong / -
139 ifelse(eval(2+5%5+1),3,,`precedence wrong % +
141 ifelse(eval(7+9<<1),32,,`precedence wrong + <<
143 ifelse(eval(35-3>>2),8,,`precedence wrong - >>
145 ifelse(eval(9<10<<5),1,,`precedence wrong << <
147 ifelse(eval(9>10<<5),0,,`precedence wrong << >
149 ifelse(eval(32>>2<32),1,,`precedence wrong >> <
151 ifelse(eval(9<=10<<5),1,,`precedence wrong << <
153 ifelse(eval(5<<1<=20>>1),1,,`precedence wrong << <=
155 ifelse(eval(5<<1>=20>>1),1,,`precedence wrong << >=
157 ifelse(eval(0<7==5>=5),1,,`precedence wrong < ==
159 ifelse(eval(0<7!=5>=5),0,,`precedence wrong < !=
161 ifelse(eval(0>7==5>=5),0,,`precedence wrong > ==
163 ifelse(eval(0>7!=5>=5),1,,`precedence wrong > !=
165 ifelse(eval(1&7==7),1,,`precedence wrong & ==
167 ifelse(eval(0&7!=6),0,,`precedence wrong & !=
169 ifelse(eval(9&1|5),5,,`precedence wrong & |
171 ifelse(eval(9&1^5),4,,`precedence wrong & ^
173 ifelse(eval(9^1|5),13,,`precedence wrong ^ |
175 ifelse(eval(5|0&&1),1,,`precedence wrong | &&
177 ifelse(eval(5&&0||0&&5||5),1,,`precedence wrong && ||
179 ifelse(eval(0 || 1 ? 0 : 1),0,,`precedence wrong || ?:
181 ifelse(eval(5&&(0||0)&&(5||5)),0,,`precedence wrong || parens