BindingFlags.Public needed here as Exception.HResult is now public in .NET 4.5. This...
[mono.git] / mcs / class / corlib / Test / System / MathTest.cs
1 // MathTest.cs
2 //
3 // Jon Guymon (guymon@slackworks.com)
4 // Pedro Martínez Juliá (yoros@wanadoo.es)
5 //
6 // (C) 2002 Jon Guymon
7 // Copyright (C) 2003 Pedro Martínez Juliá <yoros@wanadoo.es>
8 // Copyright (C) 2004 Novell (http://www.novell.com)
9 // 
10
11 using System;
12 using NUnit.Framework;
13
14 namespace MonoTests.System
15 {
16         [TestFixture]
17         public class MathTest
18         {
19                 private static double double_epsilon =
20 #if TARGET_JVM
21                         1E-15;
22 #else
23                         double.Epsilon;
24 #endif
25
26                 static double x = 0.1234;
27                 static double y = 12.345;
28
29                 [Test]
30                 public void TestDecimalAbs ()
31                 {
32                         decimal a = -9.0M;
33
34                         Assert.IsTrue (9.0M == Math.Abs (a), "#1");
35                         Assert.IsTrue (Decimal.MaxValue == Math.Abs (Decimal.MaxValue), "#2");
36                         Assert.IsTrue (Decimal.MaxValue == Math.Abs (Decimal.MinValue), "#3");
37                         Assert.IsTrue (Decimal.Zero == Math.Abs (Decimal.Zero), "#4");
38                         Assert.IsTrue (Decimal.One == Math.Abs (Decimal.One), "#5");
39                         Assert.IsTrue (Decimal.One == Math.Abs (Decimal.MinusOne), "#6");
40                 }
41
42                 [Test]
43                 public void TestDoubleAbs ()
44                 {
45                         double a = -9.0D;
46
47                         Assert.IsTrue (9.0D == Math.Abs (a), "#1");
48                         Assert.IsTrue (0.0D == Math.Abs (0.0D), "#2");
49                         Assert.IsTrue (Double.MaxValue == Math.Abs (Double.MaxValue), "#3");
50                         Assert.IsTrue (Double.MaxValue == Math.Abs (Double.MinValue), "#4");
51                         Assert.IsTrue (Double.IsPositiveInfinity (Math.Abs (Double.PositiveInfinity)), "#5");
52                         Assert.IsTrue (Double.IsPositiveInfinity (Math.Abs (Double.NegativeInfinity)), "#6");
53                         Assert.IsTrue (Double.IsNaN (Math.Abs (Double.NaN)), "#7");
54                 }
55
56                 [Test]
57                 public void TestFloatAbs ()
58                 {
59                         float a = -9.0F;
60
61                         Assert.IsTrue (9.0F == Math.Abs (a), "#1");
62                         Assert.IsTrue (0.0F == Math.Abs (0.0F), "#2");
63                         Assert.IsTrue (Single.MaxValue == Math.Abs (Single.MaxValue), "#3");
64                         Assert.IsTrue (Single.MaxValue == Math.Abs (Single.MinValue), "#4");
65                         Assert.IsTrue (Single.PositiveInfinity == Math.Abs (Single.PositiveInfinity), "#5");
66                         Assert.IsTrue (Single.PositiveInfinity == Math.Abs (Single.NegativeInfinity), "#6");
67                         Assert.IsTrue (Single.IsNaN (Math.Abs (Single.NaN)), "#7");
68                 }
69
70                 [Test]
71                 public void TestLongAbs ()
72                 {
73                         long a = -9L;
74                         long b = Int64.MinValue;
75
76                         Assert.IsTrue (9L == Math.Abs (a), "#1");
77                         try {
78                                 Math.Abs (b);
79                                 Assert.Fail ("#2");
80                         } catch (Exception e) {
81                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
82                         }
83                         Assert.IsTrue (Int64.MaxValue == Math.Abs (Int64.MaxValue), "#4");
84                 }
85
86                 [Test]
87                 public void TestIntAbs ()
88                 {
89                         int a = -9;
90                         int b = Int32.MinValue;
91
92                         Assert.IsTrue (9 == Math.Abs (a), "#1");
93                         try {
94                                 Math.Abs (b);
95                                 Assert.Fail ("#2");
96                         } catch (Exception e) {
97                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
98                         }
99                         Assert.IsTrue (Int32.MaxValue == Math.Abs (Int32.MaxValue), "#4");
100                 }
101
102                 [Test]
103                 public void TestSbyteAbs ()
104                 {
105                         sbyte a = -9;
106                         sbyte b = SByte.MinValue;
107
108                         Assert.IsTrue (9 == Math.Abs (a), "#1");
109                         try {
110                                 Math.Abs (b);
111                                 Assert.Fail ("#2");
112                         } catch (Exception e) {
113                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
114                         }
115                         Assert.IsTrue (SByte.MaxValue == Math.Abs (SByte.MaxValue), "#4");
116                 }
117
118                 [Test]
119                 public void TestShortAbs ()
120                 {
121                         short a = -9;
122                         short b = Int16.MinValue;
123
124                         Assert.IsTrue (9 == Math.Abs (a), "#1");
125                         try {
126                                 Math.Abs (b);
127                                 Assert.Fail ("#2");
128                         } catch (Exception e) {
129                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
130                         }
131                         Assert.IsTrue (Int16.MaxValue == Math.Abs (Int16.MaxValue), "#4");
132                 }
133
134                 [Test]
135                 public void TestAcos ()
136                 {
137                         double a = Math.Acos (x);
138                         double b = 1.4470809809523457;
139
140                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
141                                 + " != " + b.ToString ("G99"));
142                         Assert.IsTrue (double.IsNaN (Math.Acos (-1.01D)));
143                         Assert.IsTrue (double.IsNaN (Math.Acos (1.01D)));
144                         Assert.IsTrue (double.IsNaN (Math.Acos (Double.MinValue)));
145                         Assert.IsTrue (double.IsNaN (Math.Acos (Double.MaxValue)));
146                         Assert.IsTrue (double.IsNaN (Math.Acos (Double.NegativeInfinity)));
147                         Assert.IsTrue (double.IsNaN (Math.Acos (Double.PositiveInfinity)));
148                 }
149
150                 [Test]
151                 public void TestAsin ()
152                 {
153                         double a = Math.Asin (x);
154                         double b = 0.12371534584255098;
155
156                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
157                                 + " != " + b.ToString ("G99"));
158                         Assert.IsTrue (double.IsNaN (Math.Asin (-1.01D)));
159                         Assert.IsTrue (double.IsNaN (Math.Asin (1.01D)));
160                         Assert.IsTrue (double.IsNaN (Math.Asin (Double.MinValue)));
161                         Assert.IsTrue (double.IsNaN (Math.Asin (Double.MaxValue)));
162                         Assert.IsTrue (double.IsNaN (Math.Asin (Double.NegativeInfinity)));
163                         Assert.IsTrue (double.IsNaN (Math.Asin (Double.PositiveInfinity)));
164                 }
165
166                 [Test]
167                 public void TestAtan ()
168                 {
169                         double a = Math.Atan (x);
170                         double b = 0.12277930094473837;
171                         double c = 1.5707963267948966;
172                         double d = -1.5707963267948966;
173
174                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), "#1: " + a.ToString ("G99")
175                                 + " != " + b.ToString ("G99"));
176                         Assert.IsTrue (double.IsNaN (Math.Atan (double.NaN)), "should return NaN");
177                         Assert.IsTrue (Math.Abs ((double) Math.Atan (double.PositiveInfinity) - c) <= 0.0000000000000001,
178                                 "#2: " + Math.Atan (double.PositiveInfinity).ToString ("G99") + " != " + c.ToString ("G99"));
179                         Assert.IsTrue (Math.Abs ((double) Math.Atan (double.NegativeInfinity) - d) <= 0.0000000000000001,
180                                 "#3: " + Math.Atan (double.NegativeInfinity).ToString ("G99") + " != " + d.ToString ("G99"));
181                 }
182
183                 [Test]
184                 public void TestAtan2 ()
185                 {
186                         double a = Math.Atan2 (x, y);
187                         double b = 0.0099956168687207747;
188
189                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
190                                 + " != " + b.ToString ("G99"));
191                         Assert.IsTrue (double.IsNaN (Math.Acos (-2D)));
192                         Assert.IsTrue (double.IsNaN (Math.Acos (2D)));
193                 }
194
195                 // The following test is for methods that are in ECMA but they are
196                 // not implemented in MS.NET. I leave them commented.
197                 /*
198                 public void TestBigMul () {
199                         int a = int.MaxValue;
200                         int b = int.MaxValue;
201
202                         Assert(((long)a * (long)b) == Math.BigMul(a,b));
203                 }
204                 */
205
206                 [Test]
207                 public void TestCos ()
208                 {
209                         double a = Math.Cos (x);
210                         double b = 0.99239587670489104;
211
212                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
213                                 + " != " + b.ToString ("G99"));
214                         Assert.IsTrue (double.IsNaN (Math.Cos (Double.NaN)));
215                         Assert.IsTrue (double.IsNaN (Math.Cos (Double.NegativeInfinity)));
216                         Assert.IsTrue (double.IsNaN (Math.Cos (Double.PositiveInfinity)));
217                 }
218
219                 [Test]
220                 public void TestCosh ()
221                 {
222                         double a = Math.Cosh (x);
223                         double b = 1.0076234465130722;
224
225                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
226                                 + " != " + b.ToString ("G99"));
227                         Assert.IsTrue (Math.Cosh (double.NegativeInfinity) == double.PositiveInfinity);
228                         Assert.IsTrue (Math.Cosh (double.PositiveInfinity) == double.PositiveInfinity);
229                         Assert.IsTrue (double.IsNaN (Math.Cosh (double.NaN)));
230                 }
231
232                 // The following test is for methods that are in ECMA but they are
233                 // not implemented in MS.NET. I leave them commented.
234                 /*
235                 public void TestIntDivRem () {
236                         int a = 5;
237                         int b = 2;
238                         int div = 0, rem = 0;
239
240                         div = Math.DivRem (a, b, out rem);
241
242                         Assert.IsTrue (rem == 1);
243                         Assert.IsTrue (div == 2);
244                 }
245
246                 public void TestLongDivRem () {
247                         long a = 5;
248                         long b = 2;
249                         long div = 0, rem = 0;
250
251                         div = Math.DivRem (a, b, out rem);
252
253                         Assert.IsTrue (rem == 1);
254                         Assert.IsTrue (div == 2);
255                 }
256                 */
257
258                 [Test]
259                 public void TestSin ()
260                 {
261                         double a = Math.Sin (x);
262                         double b = 0.12308705821137626;
263
264                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
265                                 + " != " + b.ToString ("G99"));
266                         Assert.IsTrue (double.IsNaN (Math.Sin (Double.NaN)));
267                         Assert.IsTrue (double.IsNaN (Math.Sin (Double.NegativeInfinity)));
268                         Assert.IsTrue (double.IsNaN (Math.Sin (Double.PositiveInfinity)));
269                 }
270
271                 [Test]
272                 public void TestSinh ()
273                 {
274                         double a = Math.Sinh (x);
275                         double b = 0.12371341868561381;
276
277                         Assert.IsTrue (Math.Abs (a - b) <= 0.0000000000000001, a.ToString ("G99")
278                                 + " != " + b.ToString ("G99"));
279                         Assert.IsTrue (double.IsNaN (Math.Sinh (Double.NaN)));
280                         Assert.IsTrue (double.IsNegativeInfinity (Math.Sinh (Double.NegativeInfinity)));
281                         Assert.IsTrue (double.IsPositiveInfinity (Math.Sinh (Double.PositiveInfinity)));
282                 }
283
284                 [Test]
285                 public void TestTan ()
286                 {
287                         double a = Math.Tan (x);
288                         double b = 0.12403019913793806;
289
290                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
291                                 + " != " + b.ToString ("G99"));
292                         Assert.IsTrue (Double.IsNaN (Math.Tan (Double.NaN)));
293                         Assert.IsTrue (Double.IsNaN (Math.Tan (Double.PositiveInfinity)));
294                         Assert.IsTrue (Double.IsNaN (Math.Tan (Double.NegativeInfinity)));
295                 }
296
297                 [Test]
298                 public void TestTanh ()
299                 {
300                         double a = Math.Tanh (x);
301                         double b = 0.12277743150353424;
302
303                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
304                                 + " != " + b.ToString ("G99"));
305                         Assert.IsTrue (Double.IsNaN (Math.Tanh (Double.NaN)),
306                                 "Tanh(NaN) should be NaN");
307                         Assert.IsTrue (1 == Math.Tanh (Double.PositiveInfinity),
308                                 "Tanh(+Infinity) should be 1");
309                         Assert.IsTrue (-1 == Math.Tanh (Double.NegativeInfinity),
310                                 "Tanh(-Infinity) should be -1");
311                 }
312
313                 [Test]
314                 public void TestSqrt ()
315                 {
316                         double a = Math.Sqrt (x);
317                         double b = 0.35128336140500593;
318
319                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
320                                 + " != " + b.ToString ("G99"));
321                         Assert.IsTrue (Double.IsNaN (Math.Sqrt (Double.NaN)));
322                         Assert.IsTrue (Double.IsPositiveInfinity (Math.Sqrt (Double.PositiveInfinity)));
323                         Assert.IsTrue (Double.IsNaN (Math.Sqrt (Double.NegativeInfinity)));
324                 }
325
326                 [Test]
327                 public void TestExp ()
328                 {
329                         double a = Math.Exp (x);
330                         double b = 1.1313368651986859;
331
332                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
333                                 + " != " + b.ToString ("G99"));
334                         Assert.IsTrue (double.IsNaN (Math.Exp (double.NaN)));
335                         Assert.IsTrue (Math.Exp (double.NegativeInfinity) == 0);
336                         Assert.IsTrue (Math.Exp (double.PositiveInfinity) == double.PositiveInfinity);
337                 }
338
339                 [Test]
340                 public void TestCeiling ()
341                 {
342                         int iTest = 1;
343                         try {
344                                 double a = Math.Ceiling (1.5);
345                                 double b = 2;
346
347                                 iTest++;
348                                 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
349                                         + " != " + b.ToString ("G99"));
350                                 iTest++;
351                                 Assert.IsTrue (Math.Ceiling (double.NegativeInfinity) == double.NegativeInfinity);
352                                 iTest++;
353                                 Assert.IsTrue (Math.Ceiling (double.PositiveInfinity) == double.PositiveInfinity);
354                                 iTest++;
355                                 Assert.IsTrue (double.IsNaN (Math.Ceiling (double.NaN)));
356
357                                 iTest++;
358                                 Assert.IsTrue (Double.MaxValue == Math.Ceiling (Double.MaxValue));
359
360                                 iTest++;
361                                 Assert.IsTrue (Double.MinValue == Math.Ceiling (Double.MinValue));
362                         } catch (Exception e) {
363                                 Assert.Fail ("Unexpected Exception at iTest=" + iTest + ": " + e);
364                         }
365                 }
366
367 #if NET_2_0
368                 [Test]
369                 public void TestDecimalCeiling()
370                 {
371                         decimal a = Math.Ceiling(1.5M);
372                         decimal b = 2M;
373
374                         Assert.IsTrue (a == b, "#1");
375                         Assert.IsTrue (Decimal.MaxValue == Math.Ceiling(Decimal.MaxValue), "#2");
376                         Assert.IsTrue (Decimal.MinValue == Math.Ceiling(Decimal.MinValue), "#3");
377                 }
378 #endif
379
380                 [Test]
381                 public void TestFloor ()
382                 {
383                         double a = Math.Floor (1.5);
384                         double b = 1;
385
386                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
387                                 + " != " + b.ToString ("G99"));
388                         Assert.IsTrue (Math.Floor (double.NegativeInfinity) == double.NegativeInfinity);
389                         Assert.IsTrue (Math.Floor (double.PositiveInfinity) == double.PositiveInfinity);
390                         Assert.IsTrue (double.IsNaN (Math.Floor (double.NaN)));
391
392                         Assert.IsTrue (Double.MaxValue == Math.Floor (Double.MaxValue));
393
394                         Assert.IsTrue (Double.MinValue == Math.Floor (Double.MinValue));
395                 }
396
397                 [Test]
398                 public void TestIEEERemainder ()
399                 {
400                         double a = Math.IEEERemainder (y, x);
401                         double b = 0.0050000000000007816;
402
403                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
404                                 + " != " + b.ToString ("G99"));
405
406                         Assert.IsTrue (double.IsNaN (Math.IEEERemainder (y, 0)), "Positive 0");
407
408                         // http://www.obtuse.com/resources/negative_zero.html
409                         double n0 = BitConverter.Int64BitsToDouble (Int64.MinValue);
410                         Assert.IsTrue (double.IsNaN (Math.IEEERemainder (n0, 0)), "Negative 0");
411
412                         // the "zero" remainder of negative number is negative
413                         long result = BitConverter.DoubleToInt64Bits (Math.IEEERemainder (-1, 1));
414                         Assert.AreEqual (Int64.MinValue, result, "Negative Dividend");
415                 }
416
417                 [Test]
418                 public void TestLog ()
419                 {
420                         double a = Math.Log (y);
421                         double b = 2.513251122797143;
422
423                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
424                                 + " != " + b.ToString ("G99"));
425                         Assert.IsTrue (double.IsNaN (Math.Log (-1)));
426                         Assert.IsTrue (double.IsNaN (Math.Log (double.NaN)));
427
428                         // MS docs say this should be PositiveInfinity
429                         Assert.IsTrue (Math.Log (0) == double.NegativeInfinity);
430                         Assert.IsTrue (Math.Log (double.PositiveInfinity) == double.PositiveInfinity);
431                 }
432
433                 [Test]
434                 public void TestLog2 ()
435                 {
436                         double a = Math.Log (x, y);
437                         double b = -0.83251695325303621;
438
439                         Assert.IsTrue ((Math.Abs (a - b) <= 1e-14), a + " != " + b
440                                 + " because diff is " + Math.Abs (a - b));
441                         Assert.IsTrue (double.IsNaN (Math.Log (-1, y)));
442                         Assert.IsTrue (double.IsNaN (Math.Log (double.NaN, y)));
443                         Assert.IsTrue (double.IsNaN (Math.Log (x, double.NaN)));
444                         Assert.IsTrue (double.IsNaN (Math.Log (double.NegativeInfinity, y)));
445                         Assert.IsTrue (double.IsNaN (Math.Log (x, double.NegativeInfinity)));
446                         Assert.IsTrue (double.IsNaN (Math.Log (double.PositiveInfinity, double.PositiveInfinity)));
447                         Assert.IsTrue (double.IsNaN (Math.Log (2, 1)));
448
449                         // MS docs say this should be PositiveInfinity
450                         Assert.IsTrue (Math.Log (0, y) == double.NegativeInfinity);
451                         Assert.IsTrue (Math.Log (double.PositiveInfinity, y) == double.PositiveInfinity);
452                         Assert.IsTrue (Math.Log (x, double.PositiveInfinity) == 0);
453                 }
454
455                 [Test]
456                 public void TestLog10 ()
457                 {
458                         double a = Math.Log10 (x);
459                         double b = -0.90868484030277719;
460
461                         Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
462                                 + " != " + b.ToString ("G99"));
463                         Assert.IsTrue (double.IsNaN (Math.Log10 (-1)));
464                         Assert.IsTrue (double.IsNaN (Math.Log10 (double.NaN)));
465
466                         // MS docs say this should be PositiveInfinity
467                         Assert.IsTrue (Math.Log10 (0) == double.NegativeInfinity);
468                         Assert.IsTrue (Math.Log10 (double.PositiveInfinity) == double.PositiveInfinity);
469
470                 }
471
472                 [Test]
473                 public void TestPow ()
474                 {
475                         int iTest = 1;
476
477                         try {
478                                 double a = Math.Pow (y, x);
479                                 double b = 1.363609446060212;
480
481                                 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99") + " != " + b.ToString ("G99"));
482                                 iTest++;
483                                 Assert.IsTrue (double.IsNaN (Math.Pow (y, double.NaN)));
484                                 iTest++;
485                                 Assert.IsTrue (double.IsNaN (Math.Pow (double.NaN, x)));
486                                 iTest++;
487                                 Assert.IsTrue (double.IsNegativeInfinity (Math.Pow (double.NegativeInfinity, 1)),
488                                         "Math.Pow(double.NegativeInfinity, 1) should be NegativeInfinity");
489                                 iTest++;
490                                 Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.NegativeInfinity, 2)),
491                                         "Math.Pow(double.NegativeInfinity, 2) should be PositiveInfinity");
492
493                                 // MS docs say this should be 0
494                                 iTest++;
495                                 Assert.IsTrue (double.IsNaN (Math.Pow (1, double.NegativeInfinity)));
496                                 iTest++;
497                                 Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, double.NegativeInfinity),
498                                         "Math.Pow(double.PositiveInfinity, double.NegativeInfinity)");
499                                 iTest++;
500                                 Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.PositiveInfinity, 1)),
501                                         "Math.Pow(double.PositiveInfinity, 1) should be PositiveInfinity");
502
503                                 // MS docs say this should be PositiveInfinity
504                                 iTest++;
505                                 Assert.IsTrue (double.IsNaN (Math.Pow (1, double.PositiveInfinity)),
506                                         "Math.Pow(1, double.PositiveInfinity) should be NaN");
507
508                                 iTest++;
509                                 Assert.IsTrue (Double.IsNaN (Math.Pow (1, Double.NaN)),
510                                         "Math.Pow(1, NaN) should be NaN");
511 #if !TARGET_JVM
512                                 iTest++;
513                                 Assert.IsTrue (Double.IsNaN (Math.Pow (Double.NaN, 0)),
514                                         "Math.Pow(NaN, 0) should be NaN");
515 #endif
516                                 iTest++;
517                                 Assert.IsTrue (1.0 == Math.Pow (-1, Double.MaxValue),
518                                         "Math.Pow(-1, MaxValue) should be 1.0");
519
520                                 iTest++;
521                                 Assert.IsTrue (1.0 == Math.Pow (-1, Double.MinValue),
522                                         "Math.Pow(-1, MinValue) should be 1.0");
523
524                                 iTest++;
525                                 Assert.IsTrue (Double.IsPositiveInfinity (Math.Pow (Double.MinValue,
526                                         Double.MaxValue)), "Math.Pow(MinValue, MaxValue) should be +Infinity");
527
528                                 iTest++;
529                                 Assert.IsTrue (0.0 == Math.Pow (Double.MinValue, Double.MinValue),
530                                         "Math.Pow(MinValue, MinValue) should be 0.0");
531
532                                 //
533                                 // The following bugs were present because we tried to outsmart the C Pow:
534                                 //
535                                 double infinity = Double.PositiveInfinity;
536                                 Assert.IsTrue (Math.Pow (0.5, infinity) == 0.0,
537                                         "Math.Pow(0.5, Infinity) == 0.0");
538                                 Assert.IsTrue (Math.Pow (0.5, -infinity) == infinity,
539                                         "Math.Pow(0.5, -Infinity) == Infinity");
540                                 Assert.IsTrue (Math.Pow (2, infinity) == infinity,
541                                         "Math.Pow(2, Infinity) == Infinity");
542                                 Assert.IsTrue (Math.Pow (2, -infinity) == 0.0,
543                                         "Math.Pow(2, -Infinity) == 0");
544                                 Assert.IsTrue (Math.Pow (infinity, 0) == 1.0,
545                                         "Math.Pow(Infinity, 0) == 1.0");
546                                 Assert.IsTrue (Math.Pow (-infinity, 0) == 1.0,
547                                         "Math.Pow(-Infinity, 0) == 1.0");
548                         } catch (Exception e) {
549                                 Assert.Fail ("Unexpected exception at iTest=" + iTest + ". e=" + e);
550                         }
551                 }
552
553                 [Test]
554                 public void TestByteMax ()
555                 {
556                         byte a = 1;
557                         byte b = 2;
558
559                         Assert.IsTrue (b == Math.Max (a, b), "#1");
560                         Assert.IsTrue (b == Math.Max (b, a), "#2");
561                 }
562
563                 [Test]
564                 public void TestDecimalMax ()
565                 {
566                         decimal a = 1.5M;
567                         decimal b = 2.5M;
568
569                         Assert.IsTrue (b == Math.Max (a, b), "#1");
570                         Assert.IsTrue (b == Math.Max (b, a), "#2");
571                 }
572
573                 [Test]
574                 public void TestDoubleMax ()
575                 {
576                         double a = 1.5D;
577                         double b = 2.5D;
578
579                         Assert.IsTrue (b == Math.Max (a, b), "#1");
580                         Assert.IsTrue (b == Math.Max (b, a), "#2");
581
582                         Assert.IsTrue (Double.IsNaN (Math.Max (Double.NaN, Double.NaN)), "#3");
583                         Assert.IsTrue (Double.IsNaN (Math.Max (Double.NaN, a)), "#4");
584                         Assert.IsTrue (Double.IsNaN (Math.Max (b, Double.NaN)), "#5");
585                 }
586
587                 [Test]
588                 public void TestFloatMax ()
589                 {
590                         float a = 1.5F;
591                         float b = 2.5F;
592
593                         Assert.IsTrue (b == Math.Max (a, b), "#1");
594                         Assert.IsTrue (b == Math.Max (b, a), "#2");
595                         Assert.IsTrue (Single.IsNaN (Math.Max (Single.NaN, Single.NaN)), "#3");
596                         Assert.IsTrue (Single.IsNaN (Math.Max (Single.NaN, a)), "#4");
597                         Assert.IsTrue (Single.IsNaN (Math.Max (b, Single.NaN)), "#5");
598                 }
599
600                 [Test]
601                 public void TestIntMax ()
602                 {
603                         int a = 1;
604                         int b = 2;
605                         int c = 100;
606                         int d = -2147483647;
607
608                         Assert.AreEqual (b, Math.Max (a, b), "#1");
609                         Assert.AreEqual (b, Math.Max (b, a), "#2");
610                         Assert.AreEqual (c, Math.Max (c, d), "#3");
611                         Assert.AreEqual (c, Math.Max (d, c), "#4");
612                 }
613
614                 [Test]
615                 public void TestLongMax ()
616                 {
617                         long a = 1L;
618                         long b = 2L;
619
620                         Assert.IsTrue (b == Math.Max (a, b), "#1");
621                         Assert.IsTrue (b == Math.Max (b, a), "#2");
622                 }
623
624                 [Test]
625                 public void TestSbyteMax ()
626                 {
627                         sbyte a = 1;
628                         sbyte b = 2;
629
630                         Assert.IsTrue (b == Math.Max (a, b), "#1");
631                         Assert.IsTrue (b == Math.Max (b, a), "#2");
632                 }
633
634                 [Test]
635                 public void TestShortMax ()
636                 {
637                         short a = 1;
638                         short b = 2;
639
640                         Assert.IsTrue (b == Math.Max (a, b), "#1");
641                         Assert.IsTrue (b == Math.Max (b, a), "#2");
642                 }
643
644                 [Test]
645                 public void TestUintMax ()
646                 {
647                         uint a = 1U;
648                         uint b = 2U;
649
650                         Assert.IsTrue (b == Math.Max (a, b), "#1");
651                         Assert.IsTrue (b == Math.Max (b, a), "#2");
652                 }
653
654                 [Test]
655                 public void TestUlongMax ()
656                 {
657                         ulong a = 1UL;
658                         ulong b = 2UL;
659
660                         Assert.IsTrue (b == Math.Max (a, b), "#1");
661                         Assert.IsTrue (b == Math.Max (b, a), "#2");
662                 }
663
664                 [Test]
665                 public void TestUshortMax ()
666                 {
667                         ushort a = 1;
668                         ushort b = 2;
669
670                         Assert.IsTrue (b == Math.Max (a, b), "#1");
671                         Assert.IsTrue (b == Math.Max (b, a), "#2");
672                 }
673
674                 [Test]
675                 public void TestByteMin ()
676                 {
677                         byte a = 1;
678                         byte b = 2;
679
680                         Assert.IsTrue (a == Math.Min (a, b), "#1");
681                         Assert.IsTrue (a == Math.Min (b, a), "#2");
682                 }
683
684                 [Test]
685                 public void TestDecimalMin ()
686                 {
687                         decimal a = 1.5M;
688                         decimal b = 2.5M;
689
690                         Assert.IsTrue (a == Math.Min (a, b), "#1");
691                         Assert.IsTrue (a == Math.Min (b, a), "#2");
692                 }
693
694                 [Test]
695                 public void TestDoubleMin ()
696                 {
697                         double a = 1.5D;
698                         double b = 2.5D;
699
700                         Assert.IsTrue (a == Math.Min (a, b), "#1");
701                         Assert.IsTrue (a == Math.Min (b, a), "#2");
702                         Assert.IsTrue (Double.IsNaN (Math.Min (Double.NaN, Double.NaN)), "#3");
703                         Assert.IsTrue (Double.IsNaN (Math.Min (Double.NaN, a)), "#4");
704                         Assert.IsTrue (Double.IsNaN (Math.Min (b, Double.NaN)), "#5");
705                 }
706
707                 [Test]
708                 public void TestFloatMin ()
709                 {
710                         float a = 1.5F;
711                         float b = 2.5F;
712
713                         Assert.IsTrue (a == Math.Min (a, b), "#1");
714                         Assert.IsTrue (a == Math.Min (b, a), "#2");
715                         Assert.IsTrue (Single.IsNaN (Math.Min (Single.NaN, Single.NaN)), "#3");
716                         Assert.IsTrue (Single.IsNaN (Math.Min (Single.NaN, a)), "#4");
717                         Assert.IsTrue (Single.IsNaN (Math.Min (b, Single.NaN)), "#5");
718                 }
719
720                 [Test]
721                 public void TestIntMin ()
722                 {
723                         int a = 1;
724                         int b = 2;
725
726                         Assert.IsTrue (a == Math.Min (a, b), "#1");
727                         Assert.IsTrue (a == Math.Min (b, a), "#2");
728                 }
729
730                 [Test]
731                 public void TestLongMin ()
732                 {
733                         long a = 1L;
734                         long b = 2L;
735
736                         Assert.IsTrue (a == Math.Min (a, b), "#1");
737                         Assert.IsTrue (a == Math.Min (b, a), "#2");
738                 }
739
740                 [Test]
741                 public void TestSbyteMin ()
742                 {
743                         sbyte a = 1;
744                         sbyte b = 2;
745
746                         Assert.IsTrue (a == Math.Min (a, b), "#1");
747                         Assert.IsTrue (a == Math.Min (b, a), "#2");
748                 }
749
750                 [Test]
751                 public void TestShortMin ()
752                 {
753                         short a = 1;
754                         short b = 2;
755
756                         Assert.IsTrue (a == Math.Min (a, b), "#1");
757                         Assert.IsTrue (a == Math.Min (b, a), "#2");
758                 }
759
760                 [Test]
761                 public void TestUintMin ()
762                 {
763                         uint a = 1U;
764                         uint b = 2U;
765
766                         Assert.IsTrue (a == Math.Min (a, b), "#1");
767                         Assert.IsTrue (a == Math.Min (b, a), "#2");
768                 }
769
770                 [Test]
771                 public void TestUlongMin ()
772                 {
773                         ulong a = 1UL;
774                         ulong b = 2UL;
775
776                         Assert.IsTrue (a == Math.Min (a, b), "#1");
777                         Assert.IsTrue (a == Math.Min (b, a), "#2");
778                 }
779
780                 [Test]
781                 public void TestUshortMin ()
782                 {
783                         ushort a = 1;
784                         ushort b = 2;
785
786                         Assert.IsTrue (a == Math.Min (a, b), "#1");
787                         Assert.IsTrue (a == Math.Min (b, a), "#2");
788                 }
789
790                 [Test]
791                 public void TestDecimalRound ()
792                 {
793                         decimal a = 1.5M;
794                         decimal b = 2.5M;
795
796                         Assert.IsTrue (Math.Round (a) == 2, "#1");
797                         Assert.IsTrue (Math.Round (b) == 2, "#2");
798                         Assert.IsTrue (Decimal.MaxValue == Math.Round (Decimal.MaxValue), "#3");
799                         Assert.IsTrue (Decimal.MinValue == Math.Round (Decimal.MinValue), "#4");
800                 }
801
802                 [Test]
803                 public void TestDecimalRound2 ()
804                 {
805                         decimal a = 3.45M;
806                         decimal b = 3.46M;
807
808                         Assert.AreEqual (3.4M, Math.Round (a, 1), "#1");
809                         Assert.AreEqual (3.5M, Math.Round (b, 1), "#2");
810                 }
811
812                 [Test]
813                 public void TestDoubleRound ()
814                 {
815                         double a = 1.5D;
816                         double b = 2.5D;
817
818                         Assert.AreEqual (2D, Math.Round (a), "#1");
819                         Assert.AreEqual (2D, Math.Round (b), "#2");
820                         Assert.IsTrue (Double.MaxValue == Math.Round (Double.MaxValue), "#3");
821                         Assert.IsTrue (Double.MinValue == Math.Round (Double.MinValue), "#4");
822                 }
823
824 #if NET_2_0
825                 [Test]
826                 public void TestDoubleTruncate ()
827                 {
828                         double a = 1.2D;
829                         double b = 2.8D;
830                         double c = 0D;
831
832                         Assert.AreEqual (1D, Math.Truncate (a), "#1");
833                         Assert.AreEqual (2D, Math.Truncate (b), "#2");
834
835                         Assert.AreEqual (-1D, Math.Truncate (a * -1D), "#3");
836                         Assert.AreEqual (-2D, Math.Truncate (b * -1D), "#4");
837
838                         Assert.AreEqual (0D, Math.Truncate (c), "#5");
839
840                         Assert.IsTrue (Double.MaxValue == Math.Truncate (Double.MaxValue), "#6");
841                         Assert.IsTrue (Double.MinValue == Math.Truncate (Double.MinValue), "#7");
842                 }
843
844                 [Test]
845                 public void TestDecimalTruncate ()
846                 {
847                         decimal a = 1.2M;
848                         decimal b = 2.8M;
849                         decimal c = 0M;
850
851                         Assert.AreEqual (1M, Math.Truncate (a), "#1");
852                         Assert.AreEqual (2M, Math.Truncate (b), "#2");
853
854                         Assert.AreEqual (-1M, Math.Truncate (a * -1M), "#3");
855                         Assert.AreEqual (-2M, Math.Truncate (b * -1M), "#4");
856
857                         Assert.AreEqual (0M, Math.Truncate (c), "#5");
858
859                         Assert.IsTrue (Decimal.MaxValue == Math.Truncate (Decimal.MaxValue), "#6");
860                         Assert.IsTrue (Decimal.MinValue == Math.Truncate (Decimal.MinValue), "#7");
861                 }
862 #endif
863
864                 [Test]
865                 public void TestDoubleRound2 ()
866                 {
867                         double a = 3.45D;
868                         double b = 3.46D;
869
870                         Assert.AreEqual (3.4D, Math.Round (a, 1), "#1");
871                         Assert.AreEqual (3.5D, Math.Round (b, 1), "#2");
872                         Assert.AreEqual (-0.1, Math.Round (-0.123456789, 1), "#3");
873                 }
874
875 #if NET_2_0
876                 [Test]
877                 public void TestDoubleRound3 ()
878                 {
879                         Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.ToEven), "#1");
880                         Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.AwayFromZero), "#2");
881
882                         Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.ToEven), "#3");
883                         Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.AwayFromZero), "#4");
884
885                         Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.ToEven), "#5");
886                         Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.AwayFromZero), "#6");
887
888                         Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.ToEven), "#7");
889                         Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.AwayFromZero), "#8");
890
891                         Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.ToEven), "#9");
892                         Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.AwayFromZero), "#A");
893
894                         Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.ToEven), "#B");
895                         Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.AwayFromZero), "#C");
896
897                         Assert.AreEqual (1.2D, Math.Round (1.2345D, 1, MidpointRounding.ToEven), "#D");
898                         Assert.AreEqual (1.2D, Math.Round (1.2345D, 1, MidpointRounding.AwayFromZero), "#E");
899
900                         Assert.AreEqual (-1.2D, Math.Round (-1.2345D, 1, MidpointRounding.ToEven), "#F");
901                         Assert.AreEqual (-1.2D, Math.Round (-1.2345D, 1, MidpointRounding.AwayFromZero), "#10");
902
903                         Assert.AreEqual (1.23D, Math.Round (1.2345D, 2, MidpointRounding.ToEven), "#11");
904                         Assert.AreEqual (1.23D, Math.Round (1.2345D, 2, MidpointRounding.AwayFromZero), "#12");
905
906                         Assert.AreEqual (-1.23D, Math.Round (-1.2345D, 2, MidpointRounding.ToEven), "#13");
907                         Assert.AreEqual (-1.23D, Math.Round (-1.2345D, 2, MidpointRounding.AwayFromZero), "#14");
908
909                         Assert.AreEqual (1.234D, Math.Round (1.2345D, 3, MidpointRounding.ToEven), "#15");
910                         Assert.AreEqual (1.235D, Math.Round (1.2345D, 3, MidpointRounding.AwayFromZero), "#16");
911
912                         Assert.AreEqual (-1.234D, Math.Round (-1.2345D, 3, MidpointRounding.ToEven), "#17");
913                         Assert.AreEqual (-1.235D, Math.Round (-1.2345D, 3, MidpointRounding.AwayFromZero), "#18");
914
915                         Assert.AreEqual (1.2345D, Math.Round (1.2345D, 4, MidpointRounding.ToEven), "#19");
916                         Assert.AreEqual (1.2345D, Math.Round (1.2345D, 4, MidpointRounding.AwayFromZero), "#1A");
917
918                         Assert.AreEqual (-1.2345D, Math.Round (-1.2345D, 4, MidpointRounding.ToEven), "#1B");
919                         Assert.AreEqual (-1.2345D, Math.Round (-1.2345D, 4, MidpointRounding.AwayFromZero), "#1C");
920
921                         Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.ToEven), "#1D");
922                         Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.AwayFromZero), "#1E");
923
924                         Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.ToEven), "#1F");
925                         Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.AwayFromZero), "#20");
926
927                         Assert.AreEqual (1.5D, Math.Round (1.5432D, 1, MidpointRounding.ToEven), "#21");
928                         Assert.AreEqual (1.5D, Math.Round (1.5432D, 1, MidpointRounding.AwayFromZero), "#22");
929
930                         Assert.AreEqual (-1.5D, Math.Round (-1.5432D, 1, MidpointRounding.ToEven), "#23");
931                         Assert.AreEqual (-1.5D, Math.Round (-1.5432D, 1, MidpointRounding.AwayFromZero), "#24");
932
933                         Assert.AreEqual (1.54D, Math.Round (1.5432D, 2, MidpointRounding.ToEven), "#25");
934                         Assert.AreEqual (1.54D, Math.Round (1.5432D, 2, MidpointRounding.AwayFromZero), "#26");
935
936                         Assert.AreEqual (-1.54D, Math.Round (-1.5432D, 2, MidpointRounding.ToEven), "#27");
937                         Assert.AreEqual (-1.54D, Math.Round (-1.5432D, 2, MidpointRounding.AwayFromZero), "#28");
938
939                         Assert.AreEqual (1.543D, Math.Round (1.5432D, 3, MidpointRounding.ToEven), "#29");
940                         Assert.AreEqual (1.543D, Math.Round (1.5432D, 3, MidpointRounding.AwayFromZero), "#2A");
941
942                         Assert.AreEqual (-1.543D, Math.Round (-1.5432D, 3, MidpointRounding.ToEven), "#2B");
943                         Assert.AreEqual (-1.543D, Math.Round (-1.5432D, 3, MidpointRounding.AwayFromZero), "#2C");
944
945                         Assert.AreEqual (1.5432D, Math.Round (1.5432D, 4, MidpointRounding.ToEven), "#2D");
946                         Assert.AreEqual (1.5432D, Math.Round (1.5432D, 4, MidpointRounding.AwayFromZero), "#2E");
947
948                         Assert.AreEqual (-1.5432D, Math.Round (-1.5432D, 4, MidpointRounding.ToEven), "#2F");
949                         Assert.AreEqual (-1.5432D, Math.Round (-1.5432D, 4, MidpointRounding.AwayFromZero), "#30");
950
951                         Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.ToEven), "#31");
952                         Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.AwayFromZero), "#32");
953
954                         Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.ToEven), "#33");
955                         Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.AwayFromZero), "#34");
956
957                         Assert.AreEqual (63987.83594D, Math.Round (63987.83593942D, 5, MidpointRounding.ToEven), "#35");
958                         Assert.AreEqual (63987.83594D, Math.Round (63987.83593942D, 5, MidpointRounding.AwayFromZero), "#36");
959
960                         Assert.AreEqual (-63987.83594D, Math.Round (-63987.83593942D, 5, MidpointRounding.ToEven), "#37");
961                         Assert.AreEqual (-63987.83594D, Math.Round (-63987.83593942D, 5, MidpointRounding.AwayFromZero), "#38");
962
963                         Assert.AreEqual (63987.83593942D, Math.Round (63987.83593942D, 8, MidpointRounding.ToEven), "#39");
964                         Assert.AreEqual (63987.83593942D, Math.Round (63987.83593942D, 8, MidpointRounding.AwayFromZero), "#3A");
965
966                         Assert.AreEqual (-63987.83593942D, Math.Round (-63987.83593942D, 8, MidpointRounding.ToEven), "#3B");
967                         Assert.AreEqual (-63987.83593942D, Math.Round (-63987.83593942D, 8, MidpointRounding.AwayFromZero), "#3C");
968
969                         Assert.AreEqual (1, Math.Round (0.5, 0, MidpointRounding.AwayFromZero));
970                 }
971 #endif
972                 
973                 [Test]
974                 public void TestDecimalSign ()
975                 {
976                         decimal a = -5M;
977                         decimal b = 5M;
978
979                         Assert.IsTrue (Math.Sign (a) == -1, "#1");
980                         Assert.IsTrue (Math.Sign (b) == 1, "#2");
981                         Assert.IsTrue (Math.Sign (0M) == 0, "#3");
982                 }
983
984                 [Test]
985                 public void TestDoubleSign ()
986                 {
987                         double a = -5D;
988                         double b = 5D;
989
990                         Assert.IsTrue (Math.Sign (a) == -1, "#1");
991                         Assert.IsTrue (Math.Sign (b) == 1, "#2");
992                         Assert.IsTrue (Math.Sign (0D) == 0, "#3");
993                 }
994
995                 [Test]
996                 public void TestFloatSign ()
997                 {
998                         float a = -5F;
999                         float b = 5F;
1000
1001                         Assert.IsTrue (Math.Sign (a) == -1, "#1");
1002                         Assert.IsTrue (Math.Sign (b) == 1, "#2");
1003                         Assert.IsTrue (Math.Sign (0F) == 0, "#3");
1004                 }
1005
1006                 [Test]
1007                 public void TestIntSign ()
1008                 {
1009                         int a = -5;
1010                         int b = 5;
1011
1012                         Assert.IsTrue (Math.Sign (a) == -1, "#1");
1013                         Assert.IsTrue (Math.Sign (b) == 1, "#2");
1014                         Assert.IsTrue (Math.Sign (0) == 0, "#3");
1015                 }
1016
1017                 [Test]
1018                 public void TestLongSign ()
1019                 {
1020                         long a = -5L;
1021                         long b = 5L;
1022
1023                         Assert.IsTrue (Math.Sign (a) == -1, "#1");
1024                         Assert.IsTrue (Math.Sign (b) == 1, "#2");
1025                         Assert.IsTrue (Math.Sign (0L) == 0, "#3");
1026                 }
1027
1028                 [Test]
1029                 public void TestSbyteSign ()
1030                 {
1031                         sbyte a = -5;
1032                         sbyte b = 5;
1033
1034                         Assert.IsTrue (Math.Sign (a) == -1, "#1");
1035                         Assert.IsTrue (Math.Sign (b) == 1, "#2");
1036                         Assert.IsTrue (Math.Sign (0) == 0, "#3");
1037                 }
1038
1039                 [Test]
1040                 public void TestShortSign ()
1041                 {
1042                         short a = -5;
1043                         short b = 5;
1044
1045                         Assert.IsTrue (Math.Sign (a) == -1, "#1");
1046                         Assert.IsTrue (Math.Sign (b) == 1, "#2");
1047                         Assert.IsTrue (Math.Sign (0) == 0, "#3");
1048                 }
1049         }
1050 }