[MSBuild] Fixed a test that failed when the GAC wasn't available
[mono-project.git] / mono / mini / basic-float.cs
blob694a1d37d0aa11037d95006b08266d3e50467fd8
1 using System;
2 using System.Reflection;
4 /*
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * public static int test_<result>_<name> ();
11 * where <result> is an integer (the value that needs to be returned by
12 * the method to make it pass.
13 * <name> is a user-displayed name used to identify the test.
15 * The tests can be driven in two ways:
16 * *) running the program directly: Main() uses reflection to find and invoke
17 * the test methods (this is useful mostly to check that the tests are correct)
18 * *) with the --regression switch of the jit (this is the preferred way since
19 * all the tests will be run with optimizations on and off)
21 * The reflection logic could be moved to a .dll since we need at least another
22 * regression test file written in IL code to have better control on how
23 * the IL code looks.
26 /* A comparison made to same variable. */
27 #pragma warning disable 1718
29 #if MOBILE
30 class FloatTests
31 #else
32 class Tests
33 #endif
36 #if !MOBILE
37 public static int Main (string[] args) {
38 return TestDriver.RunTests (typeof (Tests), args);
40 #endif
42 public static int test_0_beq () {
43 double a = 2.0;
44 if (a != 2.0)
45 return 1;
46 return 0;
49 public static int test_0_bne_un () {
50 double a = 2.0;
51 if (a == 1.0)
52 return 1;
53 return 0;
56 public static int test_0_conv_r8 () {
57 double a = 2;
58 if (a != 2.0)
59 return 1;
60 return 0;
63 public static int test_0_conv_i () {
64 double a = 2.0;
65 int i = (int)a;
66 if (i != 2)
67 return 1;
68 uint ui = (uint)a;
69 if (ui != 2)
70 return 2;
71 short s = (short)a;
72 if (s != 2)
73 return 3;
74 ushort us = (ushort)a;
75 if (us != 2)
76 return 4;
77 byte b = (byte)a;
78 if (b != 2)
79 return 5;
80 sbyte sb = (sbyte)a;
81 if (sb != 2)
82 return 6;
83 /* MS.NET special cases these */
84 double d = Double.NaN;
85 ui = (uint)d;
86 if (ui != 0)
87 return 7;
88 d = Double.PositiveInfinity;
89 ui = (uint)d;
90 if (ui != 0)
91 return 8;
92 d = Double.NegativeInfinity;
93 ui = (uint)d;
94 if (ui != 0)
95 return 9;
97 return 0;
100 public static int test_5_conv_r4 () {
101 int i = 5;
102 float f = (float)i;
103 return (int)f;
106 public static int test_0_conv_r4_m1 () {
107 int i = -1;
108 float f = (float)i;
109 return (int)f + 1;
112 public static int test_5_double_conv_r4 () {
113 double d = 5.0;
114 float f = (float)d;
115 return (int)f;
118 public static int test_5_float_conv_r8 () {
119 float f = 5.0F;
120 double d = (double)f;
121 return (int)d;
124 public static int test_5_conv_r8 () {
125 int i = 5;
126 double f = (double)i;
127 return (int)f;
130 public static int test_5_add () {
131 double a = 2.0;
132 double b = 3.0;
133 return (int)(a + b);
136 public static int test_5_sub () {
137 double a = 8.0;
138 double b = 3.0;
139 return (int)(a - b);
142 public static int test_24_mul () {
143 double a = 8.0;
144 double b = 3.0;
145 return (int)(a * b);
148 public static int test_4_div () {
149 double a = 8.0;
150 double b = 2.0;
151 return (int)(a / b);
154 public static int test_2_rem () {
155 double a = 8.0;
156 double b = 3.0;
157 return (int)(a % b);
160 public static int test_2_neg () {
161 double a = -2.0;
162 return (int)(-a);
165 public static int test_46_float_add_spill () {
166 // we overflow the FP stack
167 double a = 1;
168 double b = 2;
169 double c = 3;
170 double d = 4;
171 double e = 5;
172 double f = 6;
173 double g = 7;
174 double h = 8;
175 double i = 9;
177 return (int)(1.0 + (a + (b + (c + (d + (e + (f + (g + (h + i)))))))));
180 public static int test_4_float_sub_spill () {
181 // we overflow the FP stack
182 double a = 1;
183 double b = 2;
184 double c = 3;
185 double d = 4;
186 double e = 5;
187 double f = 6;
188 double g = 7;
189 double h = 8;
190 double i = 9;
192 return -(int)(1.0 - (a - (b - (c - (d - (e - (f - (g - (h - i)))))))));
193 ////// -(int)(1.0 - (1 - (2 - (3 - (4 - (5 - (6 - (7 - (8 - 9)))))))));
196 public static int test_362880_float_mul_spill () {
197 // we overflow the FP stack
198 double a = 1;
199 double b = 2;
200 double c = 3;
201 double d = 4;
202 double e = 5;
203 double f = 6;
204 double g = 7;
205 double h = 8;
206 double i = 9;
208 return (int)(1.0 * (a * (b * (c * (d * (e * (f * (g * (h * i)))))))));
211 public static int test_4_long_cast () {
212 long a = 1000;
213 double d = (double)a;
214 long b = (long)d;
215 if (b != 1000)
216 return 0;
217 a = -1;
218 d = (double)a;
219 b = (long)d;
220 if (b != -1)
221 return 1;
222 return 4;
225 public static int test_4_ulong_cast () {
226 ulong a = 1000;
227 double d = (double)a;
228 ulong b = (ulong)d;
229 if (b != 1000)
230 return 0;
231 a = 0xffffffffffffffff;
232 float f = (float)a;
233 if (!(f > 0f))
234 return 1;
235 return 4;
238 public static int test_4_single_long_cast () {
239 long a = 1000;
240 float d = (float)a;
241 long b = (long)d;
242 if (b != 1000)
243 return 0;
244 a = -1;
245 d = (float)a;
246 b = (long)d;
247 if (b != -1)
248 return 1;
249 return 4;
252 public static int test_0_lconv_to_r8 () {
253 long a = 150;
254 double b = (double) a;
256 if (b != 150.0)
257 return 1;
258 return 0;
261 public static int test_0_lconv_to_r4 () {
262 long a = 3000;
263 float b = (float) a;
265 if (b != 3000.0F)
266 return 1;
267 return 0;
270 static void doit (double value, out long m) {
271 m = (long) value;
274 public static int test_0_ftol_clobber () {
275 long m;
276 doit (1.3, out m);
277 if (m != 1)
278 return 2;
279 return 0;
282 public static int test_0_rounding () {
283 long ticks = 631502475130080000L;
284 long ticksperday = 864000000000L;
286 double days = (double) ticks / ticksperday;
288 if ((int)days != 730905)
289 return 1;
291 return 0;
294 /* FIXME: This only works on little-endian machines */
296 static unsafe int test_2_negative_zero () {
297 int result = 0;
298 double d = -0.0;
299 float f = -0.0f;
301 byte *ptr = (byte*)&d;
302 if (ptr [7] == 0)
303 return result;
304 result ++;
306 ptr = (byte*)&f;
307 if (ptr [3] == 0)
308 return result;
309 result ++;
311 return result;
315 public static int test_16_float_cmp () {
316 double a = 2.0;
317 double b = 1.0;
318 int result = 0;
319 bool val;
321 val = a == a;
322 if (!val)
323 return result;
324 result++;
326 val = (a != a);
327 if (val)
328 return result;
329 result++;
331 val = a < a;
332 if (val)
333 return result;
334 result++;
336 val = a > a;
337 if (val)
338 return result;
339 result++;
341 val = a <= a;
342 if (!val)
343 return result;
344 result++;
346 val = a >= a;
347 if (!val)
348 return result;
349 result++;
351 val = b == a;
352 if (val)
353 return result;
354 result++;
356 val = b < a;
357 if (!val)
358 return result;
359 result++;
361 val = b > a;
362 if (val)
363 return result;
364 result++;
366 val = b <= a;
367 if (!val)
368 return result;
369 result++;
371 val = b >= a;
372 if (val)
373 return result;
374 result++;
376 val = a == b;
377 if (val)
378 return result;
379 result++;
381 val = a < b;
382 if (val)
383 return result;
384 result++;
386 val = a > b;
387 if (!val)
388 return result;
389 result++;
391 val = a <= b;
392 if (val)
393 return result;
394 result++;
396 val = a >= b;
397 if (!val)
398 return result;
399 result++;
401 return result;
404 public static int test_15_float_cmp_un () {
405 double a = Double.NaN;
406 double b = 1.0;
407 int result = 0;
408 bool val;
410 val = a == a;
411 if (val)
412 return result;
413 result++;
415 val = a < a;
416 if (val)
417 return result;
418 result++;
420 val = a > a;
421 if (val)
422 return result;
423 result++;
425 val = a <= a;
426 if (val)
427 return result;
428 result++;
430 val = a >= a;
431 if (val)
432 return result;
433 result++;
435 val = b == a;
436 if (val)
437 return result;
438 result++;
440 val = b < a;
441 if (val)
442 return result;
443 result++;
445 val = b > a;
446 if (val)
447 return result;
448 result++;
450 val = b <= a;
451 if (val)
452 return result;
453 result++;
455 val = b >= a;
456 if (val)
457 return result;
458 result++;
460 val = a == b;
461 if (val)
462 return result;
463 result++;
465 val = a < b;
466 if (val)
467 return result;
468 result++;
470 val = a > b;
471 if (val)
472 return result;
473 result++;
475 val = a <= b;
476 if (val)
477 return result;
478 result++;
480 val = a >= b;
481 if (val)
482 return result;
483 result++;
485 return result;
488 public static int test_15_float_branch () {
489 double a = 2.0;
490 double b = 1.0;
491 int result = 0;
493 if (!(a == a))
494 return result;
495 result++;
497 if (a < a)
498 return result;
499 result++;
501 if (a > a)
502 return result;
503 result++;
505 if (!(a <= a))
506 return result;
507 result++;
509 if (!(a >= a))
510 return result;
511 result++;
513 if (b == a)
514 return result;
515 result++;
517 if (!(b < a))
518 return result;
519 result++;
521 if (b > a)
522 return result;
523 result++;
525 if (!(b <= a))
526 return result;
527 result++;
529 if (b >= a)
530 return result;
531 result++;
533 if (a == b)
534 return result;
535 result++;
537 if (a < b)
538 return result;
539 result++;
541 if (!(a > b))
542 return result;
543 result++;
545 if (a <= b)
546 return result;
547 result++;
549 if (!(a >= b))
550 return result;
551 result++;
553 return result;
556 public static int test_15_float_branch_un () {
557 double a = Double.NaN;
558 double b = 1.0;
559 int result = 0;
561 if (a == a)
562 return result;
563 result++;
565 if (a < a)
566 return result;
567 result++;
569 if (a > a)
570 return result;
571 result++;
573 if (a <= a)
574 return result;
575 result++;
577 if (a >= a)
578 return result;
579 result++;
581 if (b == a)
582 return result;
583 result++;
585 if (b < a)
586 return result;
587 result++;
589 if (b > a)
590 return result;
591 result++;
593 if (b <= a)
594 return result;
595 result++;
597 if (b >= a)
598 return result;
599 result++;
601 if (a == b)
602 return result;
603 result++;
605 if (a < b)
606 return result;
607 result++;
609 if (a > b)
610 return result;
611 result++;
613 if (a <= b)
614 return result;
615 result++;
617 if (a >= b)
618 return result;
619 result++;
621 return result;
624 public static int test_0_float_precision () {
625 float f1 = 3.40282346638528859E+38f;
626 float f2 = 3.40282346638528859E+38f;
627 float PositiveInfinity = 1.0f / 0.0f;
628 float f = f1 + f2;
630 return f == PositiveInfinity ? 0 : 1;
633 static double VALUE = 0.19975845134874831D;
635 public static int test_0_float_conversion_reduces_double_precision () {
636 double d = (float)VALUE;
637 if (d != 0.19975845515727997d)
638 return 1;
640 return 0;
643 /* This doesn't work with llvm */
645 public static int test_0_long_to_double_conversion ()
647 long l = 9223372036854775807L;
648 long conv = (long)((double)l);
649 if (conv != -9223372036854775808L)
650 return 1;
652 return 0;
656 public static int INT_VAL = 0x13456799;
658 public static int test_0_int4_to_float_convertion ()
660 double d = (double)(float)INT_VAL;
662 if (d != 323315616)
663 return 1;
664 return 0;
667 public static int test_0_int8_to_float_convertion ()
669 double d = (double)(float)(long)INT_VAL;
671 if (d != 323315616)
672 return 1;
673 return 0;