[System.Runtime.InteropServices.RuntimeInformation] Updated to reference copied files...
[mono-project.git] / mono / tests / checked.cs
blobf0ee56973232e2f5a04e76fced36357dd008a7a2
1 using System;
3 namespace test {
4 public class tester {
5 public tester() {}
7 public static int Main () {
8 float a = 1e20f;
9 int i = 0;
10 uint ui = 0;
12 bool exception = false;
14 try {
15 int b = (int) a;
16 checked {
17 i = (int)a;
20 catch (OverflowException) {
21 exception = true;
23 catch (Exception) {
27 if (!exception)
28 return 1;
30 exception = false;
32 a = 1e5f;
34 try {
35 int b = (int) a;
36 checked {
37 i = (int)a;
39 } catch (Exception) {
40 return 2;
44 if (i != 100000)
45 return 3;
47 exception = false;
49 a = -1e30f;
50 try {
51 int b = (int) a;
52 checked {
53 i = (int)a;
56 catch (OverflowException) {
57 exception = true;
59 catch (Exception) {
61 exception = false;
64 a = -1e30f;
65 try {
66 uint b = (uint) a;
67 checked {
68 ui = (uint)a;
71 Console.WriteLine("No Exception");
73 catch (OverflowException) {
74 exception = true;
76 catch (Exception) {
80 if (!exception)
81 return 4;
83 a = 1e5f;
84 try {
85 uint b = (uint) a;
86 checked {
87 ui = (uint)a;
90 catch (Exception) {
91 return 5;
94 if (ui != 100000)
95 return 6;
97 // Check mul.ovf
98 checked {
99 int l;
100 int m;
102 int[][] cases = new int [][] {
103 new int [] {0, 0, 0},
104 new int [] {-5, 0, 0},
105 new int [] {3, -5, -15},
106 new int [] {3, 5, 15},
107 new int [] {-3, -5, 15},
108 new int [] {-3, 5, -15},
109 new int [] {-1, 32767, -32767},
110 new int [] {32767, -1, -32767}};
113 for (int j = 0; j < cases.Length; ++j)
114 if (cases [j][0] * cases [j][1] != cases [j][2])
115 return 7 + j;
118 checked {
119 int j;
120 int k;
122 j = k = 0;
123 if (j * k != 0)
124 return 20;
126 j = -5;
127 k = 0;
128 if (j * k != 0)
129 return 21;
131 j = 0;
132 k = -5;
133 if (j * k != 0)
134 return 22;
136 j = 3;
137 k = -5;
138 if (j * k != -15)
139 return 23;
141 j = 3;
142 k = 5;
143 if (j * k != 15)
144 return 24;
146 j = -3;
147 k = -5;
148 if (j * k != 15)
149 return 25;
151 j = -3;
152 k = 5;
153 if (j * k != -15)
154 return 26;
156 j = -1;
157 k = 32767;
158 if (j * k != -32767)
159 return 27;
161 j = 32767;
162 k = -1;
163 if (j * k != -32767)
164 return 28;
167 checked {
168 long l;
169 long m;
171 long[][] cases = new long [][] {
172 new long [] {0, 0, 0},
173 new long [] {-5, 0, 0},
174 new long [] {3, -5, -15},
175 new long [] {3, 5, 15},
176 new long [] {-3, -5, 15},
177 new long [] {-3, 5, -15},
178 new long [] {-1, 2147483647, -2147483647},
179 new long [] {2147483647, -1, -2147483647}};
181 for (int j = 0; j < cases.Length; ++j)
182 if (cases [j][0] * cases [j][1] != cases [j][2])
183 return 29 + j;
186 Console.WriteLine("test-ok");
188 return 0;