1 /* tests/fptest.java - checks most of the floating point instructions
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
29 Changes: Christian Thalinger
34 public static void main(String [] s) {
35 float fnan = Float.NaN;
36 float fpinf = Float.POSITIVE_INFINITY;
37 float fninf = Float.NEGATIVE_INFINITY;
38 float fmax = Float.MAX_VALUE;
39 float fmin = Float.MIN_VALUE;
43 double dnan = Double.NaN;
44 double dpinf = Double.POSITIVE_INFINITY;
45 double dninf = Double.NEGATIVE_INFINITY;
46 double dmax = Double.MAX_VALUE;
47 double dmin = Double.MIN_VALUE;
51 p("---------------------------- tests NaNs and Infs -------------------");
52 p("------------------- print NaNs and Infs");
62 p("------------------- test zero division");
64 zerodiv("0 / 0 = NaNQ ", 0F, f1);
65 zerodiv("+ / 0 = +INF ", 5F, f1);
66 zerodiv("- / 0 = -INF ", -5F, f1);
68 zerodiv("0 / 0 = NaNQ ", 0D, d1);
69 zerodiv("+ / 0 = +INF ", 5D, d1);
70 zerodiv("- / 0 = -INF ", -5D, d1);
72 p("------------------- test conversions");
73 testfcvt("NaNQ", fnan, dnan);
74 testfcvt("+INF", fpinf, dpinf);
75 testfcvt("-INF", fninf, dninf);
76 testfcvt(" MAX", fmax, dmax);
77 testfcvt(" MIN", fmin, dmin);
78 testfcvt("MAXINT-1", 2147483646.0F, 2147483646.0D);
79 testfcvt("MAXINT+0", 2147483647.0F, 2147483647.0D);
80 testfcvt("MAXINT+1", 2147483648.0F, 2147483648.0D);
81 testfcvt("-MAXINT+1", -2147483647.0F, -2147483647.0D);
82 testfcvt("-MAXINT+0", -2147483648.0F, -2147483648.0D);
83 testfcvt("-MAXINT-1", -2147483649.0F, -2147483649.0D);
84 testfcvt("MAXLNG-1", 9223372036854775806.0F, 9223372036854775806.0D);
85 testfcvt("MAXLNG+0", 9223372036854775807.0F, 9223372036854775807.0D);
86 testfcvt("MAXLNG+1", 9223372036854775808.0F, 9223372036854775808.0D);
87 testfcvt("-MAXLNG+1", -9223372036854775807.0F, -9223372036854775807.0D);
88 testfcvt("-MAXLNG+0", -9223372036854775808.0F, -9223372036854775808.0D);
89 testfcvt("-MAXLNG-1", -9223372036854775809.0F, -9223372036854775809.0D);
91 p("------------------- test NaNQ op value");
92 testfops("NaNQ", "-5.0", fnan, -5F, dnan, -5D);
93 testfcmp("NaNQ", "-5.0", fnan, -5F, dnan, -5D);
94 testfops("NaNQ", "-0.0", fnan, -0F, dnan, -0D);
95 testfcmp("NaNQ", "-0.0", fnan, -0F, dnan, -0D);
96 testfops("NaNQ", "0.0", fnan, 0F, dnan, 0D);
97 testfcmp("NaNQ", "0.0", fnan, 0F, dnan, 0D);
98 testfops("NaNQ", "5.0", fnan, 5F, dnan, 5D);
99 testfcmp("NaNQ", "5.0", fnan, 5F, dnan, 5D);
101 p("------------------- test value op NaNQ");
102 testfops("-5.0", "NaNQ", -5F, fnan, -5D, dnan);
103 testfcmp("-5.0", "NaNQ", -5F, fnan, -5D, dnan);
104 testfops("-0.0", "NaNQ", -0F, fnan, -0D, dnan);
105 testfcmp("-0.0", "NaNQ", -0F, fnan, -0D, dnan);
106 testfops("0.0", "NaNQ", 0F, fnan, 0D, dnan);
107 testfcmp("0.0", "NaNQ", 0F, fnan, 0D, dnan);
108 testfops("5.0", "NaNQ", 5F, fnan, 5D, dnan);
109 testfcmp("5.0", "NaNQ", 5F, fnan, 5D, dnan);
111 p("------------------- test +INF op value");
112 testfops("+INF", "-5.0", fpinf, -5F, dpinf, -5D);
113 testfcmp("+INF", "-5.0", fpinf, -5F, dpinf, -5D);
114 testfops("+INF", "-0.0", fpinf, -0F, dpinf, -0D);
115 testfcmp("+INF", "-0.0", fpinf, -0F, dpinf, -0D);
116 testfops("+INF", "0.0", fpinf, 0F, dpinf, 0D);
117 testfcmp("+INF", "0.0", fpinf, 0F, dpinf, 0D);
118 testfops("+INF", "5.0", fpinf, 5F, dpinf, 5D);
119 testfcmp("+INF", "5.0", fpinf, 5F, dpinf, 5D);
121 p("------------------- test +INF op value");
122 testfops("-5.0", "+INF", -5F, fpinf, -5D, dpinf);
123 testfcmp("-5.0", "+INF", -5F, fpinf, -5D, dpinf);
124 testfops("-0.0", "+INF", -0F, fpinf, -0D, dpinf);
125 testfcmp("-0.0", "+INF", -0F, fpinf, -0D, dpinf);
126 testfops("0.0", "+INF", 0F, fpinf, 0D, dpinf);
127 testfcmp("0.0", "+INF", 0F, fpinf, 0D, dpinf);
128 testfops("5.0", "+INF", 5F, fpinf, 5D, dpinf);
129 testfcmp("5.0", "+INF", 5F, fpinf, 5D, dpinf);
131 p("------------------- test -INF op value");
132 testfops("-INF", "-5.0", fninf, -5F, dninf, -5D);
133 testfcmp("-INF", "-5.0", fninf, -5F, dninf, -5D);
134 testfops("-INF", "-0.0", fninf, -0F, dninf, -0D);
135 testfcmp("-INF", "-0.0", fninf, -0F, dninf, -0D);
136 testfops("-INF", "0.0", fninf, 0F, dninf, 0D);
137 testfcmp("-INF", "0.0", fninf, 0F, dninf, 0D);
138 testfops("-INF", "5.0", fninf, 5F, dninf, 5D);
139 testfcmp("-INF", "5.0", fninf, 5F, dninf, 5D);
141 p("------------------- test -INF op value");
142 testfops("-5.0", "-INF", -5F, fninf, -5D, dninf);
143 testfcmp("-5.0", "-INF", -5F, fninf, -5D, dninf);
144 testfops("-0.0", "-INF", -0F, fninf, -0D, dninf);
145 testfcmp("-0.0", "-INF", -0F, fninf, -0D, dninf);
146 testfops("0.0", "-INF", 0F, fninf, 0D, dninf);
147 testfcmp("0.0", "-INF", 0F, fninf, 0D, dninf);
148 testfops("5.0", "-INF", 5F, fninf, 5D, dninf);
149 testfcmp("5.0", "-INF", 5F, fninf, 5D, dninf);
151 p("------------------- test MAX op value");
152 testfops("MAX", "5.0", fmax, 5F, dmax, 5D);
154 p("------------------- test value op MAX");
155 testfops("5.0", "MAX", 5F, fmax, 5D, dmax);
157 p("------------------- test MIN op value");
158 testfops("MIN", "5.0", fmin, 5F, dmin, 5D);
160 p("------------------- test value op MIN");
161 testfops("5.0", "MIN", 5F, fmin, 5D, dmin);
165 public static void zerodiv(String s, float f1, float f2) {
169 public static void zerodiv(String s, double d1, double d2) {
173 public static void testfcvt(String s1, float f1, double d1) {
174 p("convert " + s1 + " (" + f1 + "," + d1 + ") to ", (int) f1);
175 p("convert " + s1 + " (" + f1 + "," + d1 + ") to ", (int) d1);
176 p("convert " + s1 + " (" + f1 + "," + d1 + ") to ", (long) f1);
177 p("convert " + s1 + " (" + f1 + "," + d1 + ") to ", (long) d1);
180 public static void testfops(String s1, String s2, float f1, float f2,
181 double d1, double d2) {
182 p(s1 + " + " + s2 + " = ", f1 + f2);
183 p(s1 + " - " + s2 + " = ", f1 - f2);
184 p(s1 + " * " + s2 + " = ", f1 * f2);
185 p(s1 + " / " + s2 + " = ", f1 / f2);
186 p(s1 + " % " + s2 + " = ", f1 % f2);
187 p(s1 + " + " + s2 + " = ", d1 + d2);
188 p(s1 + " - " + s2 + " = ", d1 - d2);
189 p(s1 + " * " + s2 + " = ", d1 * d2);
190 p(s1 + " / " + s2 + " = ", d1 / d2);
191 p(s1 + " % " + s2 + " = ", d1 % d2);
194 public static void testfcmp(String s1, String s2, float f1, float f2,
195 double d1, double d2) {
196 if ( (f1 == f2)) p(" (" + s1 + " == " + s2 + ") = float: true");
197 else p(" (" + s1 + " == " + s2 + ") = float: false");
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");
209 if (!(f1 == f2)) p("!(" + s1 + " == " + s2 + ") = float: true");
210 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");
222 if ( (d1 == d2)) p(" (" + s1 + " == " + s2 + ") = double: true");
223 else p(" (" + s1 + " == " + s2 + ") = double: 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");
235 if (!(d1 == d2)) p("!(" + s1 + " == " + s2 + ") = double: true");
236 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");
249 // ********************* output methods ****************************
251 public static int linenum = 0;
253 public static void pnl() {
256 System.out.println();
257 for (i = 4 - Integer.toString(linenum).length(); i > 0; i--)
258 System.out.print(' ');
259 System.out.print(linenum);
260 System.out.print(". ");
264 public static void p(String a) {
265 System.out.print(a); pnl();
267 public static void p(boolean a) {
268 System.out.print(a); pnl();
270 public static void p(int a) {
271 System.out.print("int: "); System.out.print(a); pnl();
273 public static void p(long a) {
274 System.out.print("long: "); System.out.print(a); pnl();
276 public static void p(short a) {
277 System.out.print("short: "); System.out.print(a); pnl();
279 public static void p(byte a) {
280 System.out.print("byte: "); System.out.print(a); pnl();
282 public static void p(char a) {
283 System.out.print("char: "); System.out.print((int)a); pnl();
285 public static void p(float a) {
286 System.out.print("float: "); System.out.print(a); pnl();
288 public static void p(double a) {
289 System.out.print("double: "); System.out.print(a); pnl();
292 public static void p(String s, boolean i) {
293 System.out.print(s); p(i);
295 public static void p(String s, int i) {
296 System.out.print(s); p(i);
298 public static void p(String s, byte i) {
299 System.out.print(s); p(i);
301 public static void p(String s, char i) {
302 System.out.print(s); p(i);
304 public static void p(String s, short i) {
305 System.out.print(s); p(i);
307 public static void p(String s, long l) {
308 System.out.print(s); p(l);
310 public static void p(String s, float f) {
311 System.out.print(s); p(f);
313 public static void p(String s, double d) {
314 System.out.print(s); p(d);