1 /* tests/fptest.java - checks most of the floating point instructions
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
29 Changes: Christian Thalinger
31 $Id: fptest.java 3061 2005-07-19 08:52:11Z twisti $
36 public static void main(String [] s) {
37 float fnan = Float.NaN;
38 float fpinf = Float.POSITIVE_INFINITY;
39 float fninf = Float.NEGATIVE_INFINITY;
40 float fmax = Float.MAX_VALUE;
41 float fmin = Float.MIN_VALUE;
45 double dnan = Double.NaN;
46 double dpinf = Double.POSITIVE_INFINITY;
47 double dninf = Double.NEGATIVE_INFINITY;
48 double dmax = Double.MAX_VALUE;
49 double dmin = Double.MIN_VALUE;
53 p("---------------------------- tests NaNs and Infs -------------------");
54 p("------------------- print NaNs and Infs");
64 p("------------------- test zero division");
66 zerodiv("0 / 0 = NaNQ ", 0F, f1);
67 zerodiv("+ / 0 = +INF ", 5F, f1);
68 zerodiv("- / 0 = -INF ", -5F, f1);
70 zerodiv("0 / 0 = NaNQ ", 0D, d1);
71 zerodiv("+ / 0 = +INF ", 5D, d1);
72 zerodiv("- / 0 = -INF ", -5D, d1);
74 p("------------------- test conversions");
75 testfcvt("NaNQ", fnan, dnan);
76 testfcvt("+INF", fpinf, dpinf);
77 testfcvt("-INF", fninf, dninf);
78 testfcvt(" MAX", fmax, dmax);
79 testfcvt(" MIN", fmin, dmin);
80 testfcvt("MAXINT-1", 2147483646.0F, 2147483646.0D);
81 testfcvt("MAXINT+0", 2147483647.0F, 2147483647.0D);
82 testfcvt("MAXINT+1", 2147483648.0F, 2147483648.0D);
83 testfcvt("-MAXINT+1", -2147483647.0F, -2147483647.0D);
84 testfcvt("-MAXINT+0", -2147483648.0F, -2147483648.0D);
85 testfcvt("-MAXINT-1", -2147483649.0F, -2147483649.0D);
86 testfcvt("MAXLNG-1", 9223372036854775806.0F, 9223372036854775806.0D);
87 testfcvt("MAXLNG+0", 9223372036854775807.0F, 9223372036854775807.0D);
88 testfcvt("MAXLNG+1", 9223372036854775808.0F, 9223372036854775808.0D);
89 testfcvt("-MAXLNG+1", -9223372036854775807.0F, -9223372036854775807.0D);
90 testfcvt("-MAXLNG+0", -9223372036854775808.0F, -9223372036854775808.0D);
91 testfcvt("-MAXLNG-1", -9223372036854775809.0F, -9223372036854775809.0D);
93 p("------------------- test NaNQ op value");
94 testfops("NaNQ", "-5.0", fnan, -5F, dnan, -5D);
95 testfcmp("NaNQ", "-5.0", fnan, -5F, dnan, -5D);
96 testfops("NaNQ", "-0.0", fnan, -0F, dnan, -0D);
97 testfcmp("NaNQ", "-0.0", fnan, -0F, dnan, -0D);
98 testfops("NaNQ", "0.0", fnan, 0F, dnan, 0D);
99 testfcmp("NaNQ", "0.0", fnan, 0F, dnan, 0D);
100 testfops("NaNQ", "5.0", fnan, 5F, dnan, 5D);
101 testfcmp("NaNQ", "5.0", fnan, 5F, dnan, 5D);
103 p("------------------- test value op NaNQ");
104 testfops("-5.0", "NaNQ", -5F, fnan, -5D, dnan);
105 testfcmp("-5.0", "NaNQ", -5F, fnan, -5D, dnan);
106 testfops("-0.0", "NaNQ", -0F, fnan, -0D, dnan);
107 testfcmp("-0.0", "NaNQ", -0F, fnan, -0D, dnan);
108 testfops("0.0", "NaNQ", 0F, fnan, 0D, dnan);
109 testfcmp("0.0", "NaNQ", 0F, fnan, 0D, dnan);
110 testfops("5.0", "NaNQ", 5F, fnan, 5D, dnan);
111 testfcmp("5.0", "NaNQ", 5F, fnan, 5D, dnan);
113 p("------------------- test +INF op value");
114 testfops("+INF", "-5.0", fpinf, -5F, dpinf, -5D);
115 testfcmp("+INF", "-5.0", fpinf, -5F, dpinf, -5D);
116 testfops("+INF", "-0.0", fpinf, -0F, dpinf, -0D);
117 testfcmp("+INF", "-0.0", fpinf, -0F, dpinf, -0D);
118 testfops("+INF", "0.0", fpinf, 0F, dpinf, 0D);
119 testfcmp("+INF", "0.0", fpinf, 0F, dpinf, 0D);
120 testfops("+INF", "5.0", fpinf, 5F, dpinf, 5D);
121 testfcmp("+INF", "5.0", fpinf, 5F, dpinf, 5D);
123 p("------------------- test +INF op value");
124 testfops("-5.0", "+INF", -5F, fpinf, -5D, dpinf);
125 testfcmp("-5.0", "+INF", -5F, fpinf, -5D, dpinf);
126 testfops("-0.0", "+INF", -0F, fpinf, -0D, dpinf);
127 testfcmp("-0.0", "+INF", -0F, fpinf, -0D, dpinf);
128 testfops("0.0", "+INF", 0F, fpinf, 0D, dpinf);
129 testfcmp("0.0", "+INF", 0F, fpinf, 0D, dpinf);
130 testfops("5.0", "+INF", 5F, fpinf, 5D, dpinf);
131 testfcmp("5.0", "+INF", 5F, fpinf, 5D, dpinf);
133 p("------------------- test -INF op value");
134 testfops("-INF", "-5.0", fninf, -5F, dninf, -5D);
135 testfcmp("-INF", "-5.0", fninf, -5F, dninf, -5D);
136 testfops("-INF", "-0.0", fninf, -0F, dninf, -0D);
137 testfcmp("-INF", "-0.0", fninf, -0F, dninf, -0D);
138 testfops("-INF", "0.0", fninf, 0F, dninf, 0D);
139 testfcmp("-INF", "0.0", fninf, 0F, dninf, 0D);
140 testfops("-INF", "5.0", fninf, 5F, dninf, 5D);
141 testfcmp("-INF", "5.0", fninf, 5F, dninf, 5D);
143 p("------------------- test -INF op value");
144 testfops("-5.0", "-INF", -5F, fninf, -5D, dninf);
145 testfcmp("-5.0", "-INF", -5F, fninf, -5D, dninf);
146 testfops("-0.0", "-INF", -0F, fninf, -0D, dninf);
147 testfcmp("-0.0", "-INF", -0F, fninf, -0D, dninf);
148 testfops("0.0", "-INF", 0F, fninf, 0D, dninf);
149 testfcmp("0.0", "-INF", 0F, fninf, 0D, dninf);
150 testfops("5.0", "-INF", 5F, fninf, 5D, dninf);
151 testfcmp("5.0", "-INF", 5F, fninf, 5D, dninf);
153 p("------------------- test MAX op value");
154 testfops("MAX", "5.0", fmax, 5F, dmax, 5D);
156 p("------------------- test value op MAX");
157 testfops("5.0", "MAX", 5F, fmax, 5D, dmax);
159 p("------------------- test MIN op value");
160 testfops("MIN", "5.0", fmin, 5F, dmin, 5D);
162 p("------------------- test value op MIN");
163 testfops("5.0", "MIN", 5F, fmin, 5D, dmin);
167 public static void zerodiv(String s, float f1, float f2) {
171 public static void zerodiv(String s, double d1, double d2) {
175 public static void testfcvt(String s1, float f1, double d1) {
176 p("convert " + s1 + " (" + f1 + "," + d1 + ") to ", (int) f1);
177 p("convert " + s1 + " (" + f1 + "," + d1 + ") to ", (int) d1);
178 p("convert " + s1 + " (" + f1 + "," + d1 + ") to ", (long) f1);
179 p("convert " + s1 + " (" + f1 + "," + d1 + ") to ", (long) d1);
182 public static void testfops(String s1, String s2, float f1, float f2,
183 double d1, double d2) {
184 p(s1 + " + " + s2 + " = ", f1 + f2);
185 p(s1 + " - " + s2 + " = ", f1 - f2);
186 p(s1 + " * " + s2 + " = ", f1 * f2);
187 p(s1 + " / " + s2 + " = ", f1 / f2);
188 p(s1 + " % " + s2 + " = ", f1 % f2);
189 p(s1 + " + " + s2 + " = ", d1 + d2);
190 p(s1 + " - " + s2 + " = ", d1 - d2);
191 p(s1 + " * " + s2 + " = ", d1 * d2);
192 p(s1 + " / " + s2 + " = ", d1 / d2);
193 p(s1 + " % " + s2 + " = ", d1 % d2);
196 public static void testfcmp(String s1, String s2, float f1, float f2,
197 double d1, double d2) {
198 if ( (f1 == f2)) p(" (" + s1 + " == " + s2 + ") = float: true");
199 else p(" (" + s1 + " == " + s2 + ") = float: false");
200 if ( (f1 != f2)) p(" (" + s1 + " != " + s2 + ") = float: true");
201 else p(" (" + s1 + " != " + s2 + ") = float: false");
202 if ( (f1 < f2)) p(" (" + s1 + " < " + s2 + ") = float: true");
203 else p(" (" + s1 + " < " + s2 + ") = float: false");
204 if ( (f1 <= f2)) p(" (" + s1 + " <= " + s2 + ") = float: true");
205 else p(" (" + s1 + " <= " + s2 + ") = float: false");
206 if ( (f1 > f2)) p(" (" + s1 + " > " + s2 + ") = float: true");
207 else p(" (" + s1 + " > " + s2 + ") = float: false");
208 if ( (f1 >= f2)) p(" (" + s1 + " >= " + s2 + ") = float: true");
209 else p(" (" + s1 + " >= " + s2 + ") = float: false");
211 if (!(f1 == f2)) p("!(" + s1 + " == " + s2 + ") = float: true");
212 else p("!(" + s1 + " == " + s2 + ") = float: false");
213 if (!(f1 != f2)) p("!(" + s1 + " != " + s2 + ") = float: true");
214 else p("!(" + s1 + " != " + s2 + ") = float: false");
215 if (!(f1 < f2)) p("!(" + s1 + " < " + s2 + ") = float: true");
216 else p("!(" + s1 + " < " + s2 + ") = float: false");
217 if (!(f1 <= f2)) p("!(" + s1 + " <= " + s2 + ") = float: true");
218 else p("!(" + s1 + " <= " + s2 + ") = float: false");
219 if (!(f1 > f2)) p("!(" + s1 + " > " + s2 + ") = float: true");
220 else p("!(" + s1 + " > " + s2 + ") = float: false");
221 if (!(f1 >= f2)) p("!(" + s1 + " >= " + s2 + ") = float: true");
222 else p("!(" + s1 + " >= " + s2 + ") = float: false");
224 if ( (d1 == d2)) p(" (" + s1 + " == " + s2 + ") = double: true");
225 else p(" (" + s1 + " == " + s2 + ") = double: false");
226 if ( (d1 != d2)) p(" (" + s1 + " != " + s2 + ") = double: true");
227 else p(" (" + s1 + " != " + s2 + ") = double: false");
228 if ( (d1 < d2)) p(" (" + s1 + " < " + s2 + ") = double: true");
229 else p(" (" + s1 + " < " + s2 + ") = double: false");
230 if ( (d1 <= d2)) p(" (" + s1 + " <= " + s2 + ") = double: true");
231 else p(" (" + s1 + " <= " + s2 + ") = double: false");
232 if ( (d1 > d2)) p(" (" + s1 + " > " + s2 + ") = double: true");
233 else p(" (" + s1 + " > " + s2 + ") = double: false");
234 if ( (d1 >= d2)) p(" (" + s1 + " >= " + s2 + ") = double: true");
235 else p(" (" + s1 + " >= " + s2 + ") = double: false");
237 if (!(d1 == d2)) p("!(" + s1 + " == " + s2 + ") = double: true");
238 else p("!(" + s1 + " == " + s2 + ") = double: false");
239 if (!(d1 != d2)) p("!(" + s1 + " != " + s2 + ") = double: true");
240 else p("!(" + s1 + " != " + s2 + ") = double: false");
241 if (!(d1 < d2)) p("!(" + s1 + " < " + s2 + ") = double: true");
242 else p("!(" + s1 + " < " + s2 + ") = double: false");
243 if (!(d1 <= d2)) p("!(" + s1 + " <= " + s2 + ") = double: true");
244 else p("!(" + s1 + " <= " + s2 + ") = double: false");
245 if (!(d1 > d2)) p("!(" + s1 + " > " + s2 + ") = double: true");
246 else p("!(" + s1 + " > " + s2 + ") = double: false");
247 if (!(d1 >= d2)) p("!(" + s1 + " >= " + s2 + ") = double: true");
248 else p("!(" + s1 + " >= " + s2 + ") = double: false");
251 // ********************* output methods ****************************
253 public static int linenum = 0;
255 public static void pnl() {
258 System.out.println();
259 for (i = 4 - Integer.toString(linenum).length(); i > 0; i--)
260 System.out.print(' ');
261 System.out.print(linenum);
262 System.out.print(". ");
266 public static void p(String a) {
267 System.out.print(a); pnl();
269 public static void p(boolean a) {
270 System.out.print(a); pnl();
272 public static void p(int a) {
273 System.out.print("int: "); System.out.print(a); pnl();
275 public static void p(long a) {
276 System.out.print("long: "); System.out.print(a); pnl();
278 public static void p(short a) {
279 System.out.print("short: "); System.out.print(a); pnl();
281 public static void p(byte a) {
282 System.out.print("byte: "); System.out.print(a); pnl();
284 public static void p(char a) {
285 System.out.print("char: "); System.out.print((int)a); pnl();
287 public static void p(float a) {
288 System.out.print("float: "); System.out.print(a); pnl();
290 public static void p(double a) {
291 System.out.print("double: "); System.out.print(a); pnl();
294 public static void p(String s, boolean i) {
295 System.out.print(s); p(i);
297 public static void p(String s, int i) {
298 System.out.print(s); p(i);
300 public static void p(String s, byte i) {
301 System.out.print(s); p(i);
303 public static void p(String s, char i) {
304 System.out.print(s); p(i);
306 public static void p(String s, short i) {
307 System.out.print(s); p(i);
309 public static void p(String s, long l) {
310 System.out.print(s); p(l);
312 public static void p(String s, float f) {
313 System.out.print(s); p(f);
315 public static void p(String s, double d) {
316 System.out.print(s); p(d);