3 // Jon Guymon (guymon@slackworks.com)
4 // Pedro Martínez Juliá (yoros@wanadoo.es)
7 // Copyright (C) 2003 Pedro Martínez Juliá <yoros@wanadoo.es>
8 // Copyright (C) 2004 Novell (http://www.novell.com)
12 using NUnit.Framework;
14 namespace MonoTests.System
19 private static double double_epsilon = 2.2204460492503131e-16; /* DBL_EPSILON = 2^-52 */
21 static double x = 0.1234;
22 static double y = 12.345;
25 public void TestDecimalAbs ()
29 Assert.IsTrue (9.0M == Math.Abs (a), "#1");
30 Assert.IsTrue (Decimal.MaxValue == Math.Abs (Decimal.MaxValue), "#2");
31 Assert.IsTrue (Decimal.MaxValue == Math.Abs (Decimal.MinValue), "#3");
32 Assert.IsTrue (Decimal.Zero == Math.Abs (Decimal.Zero), "#4");
33 Assert.IsTrue (Decimal.One == Math.Abs (Decimal.One), "#5");
34 Assert.IsTrue (Decimal.One == Math.Abs (Decimal.MinusOne), "#6");
38 public void TestDoubleAbs ()
42 Assert.IsTrue (9.0D == Math.Abs (a), "#1");
43 Assert.IsTrue (0.0D == Math.Abs (0.0D), "#2");
44 Assert.IsTrue (Double.MaxValue == Math.Abs (Double.MaxValue), "#3");
45 Assert.IsTrue (Double.MaxValue == Math.Abs (Double.MinValue), "#4");
46 Assert.IsTrue (Double.IsPositiveInfinity (Math.Abs (Double.PositiveInfinity)), "#5");
47 Assert.IsTrue (Double.IsPositiveInfinity (Math.Abs (Double.NegativeInfinity)), "#6");
48 Assert.IsTrue (Double.IsNaN (Math.Abs (Double.NaN)), "#7");
52 public void TestFloatAbs ()
56 Assert.IsTrue (9.0F == Math.Abs (a), "#1");
57 Assert.IsTrue (0.0F == Math.Abs (0.0F), "#2");
58 Assert.IsTrue (Single.MaxValue == Math.Abs (Single.MaxValue), "#3");
59 Assert.IsTrue (Single.MaxValue == Math.Abs (Single.MinValue), "#4");
60 Assert.IsTrue (Single.PositiveInfinity == Math.Abs (Single.PositiveInfinity), "#5");
61 Assert.IsTrue (Single.PositiveInfinity == Math.Abs (Single.NegativeInfinity), "#6");
62 Assert.IsTrue (Single.IsNaN (Math.Abs (Single.NaN)), "#7");
66 public void TestLongAbs ()
69 long b = Int64.MinValue;
71 Assert.IsTrue (9L == Math.Abs (a), "#1");
75 } catch (Exception e) {
76 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
78 Assert.IsTrue (Int64.MaxValue == Math.Abs (Int64.MaxValue), "#4");
82 public void TestIntAbs ()
85 int b = Int32.MinValue;
87 Assert.IsTrue (9 == Math.Abs (a), "#1");
91 } catch (Exception e) {
92 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
94 Assert.IsTrue (Int32.MaxValue == Math.Abs (Int32.MaxValue), "#4");
98 public void TestSbyteAbs ()
101 sbyte b = SByte.MinValue;
103 Assert.IsTrue (9 == Math.Abs (a), "#1");
107 } catch (Exception e) {
108 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
110 Assert.IsTrue (SByte.MaxValue == Math.Abs (SByte.MaxValue), "#4");
114 public void TestShortAbs ()
117 short b = Int16.MinValue;
119 Assert.IsTrue (9 == Math.Abs (a), "#1");
123 } catch (Exception e) {
124 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
126 Assert.IsTrue (Int16.MaxValue == Math.Abs (Int16.MaxValue), "#4");
130 public void TestAcos ()
132 double a = Math.Acos (x);
133 double b = 1.4470809809523457;
135 bool regularTest = (Math.Abs (a - b) <= double_epsilon);
138 // On MacOS X libc acos (0.1234) returns
139 // 1.4470809809523455 (hex 0x3ff7273e62fda9ab) instead
140 // of 1.4470809809523457 (hex 0x3ff7273e62fda9ac)
142 // For now, let it go
144 if (a == 1.4470809809523455)
148 Assert.IsTrue (regularTest, a.ToString ("G99") + " != " + b.ToString ("G99"));
150 Assert.IsTrue (double.IsNaN (Math.Acos (-1.01D)));
151 Assert.IsTrue (double.IsNaN (Math.Acos (1.01D)));
152 Assert.IsTrue (double.IsNaN (Math.Acos (Double.MinValue)));
153 Assert.IsTrue (double.IsNaN (Math.Acos (Double.MaxValue)));
154 Assert.IsTrue (double.IsNaN (Math.Acos (Double.NegativeInfinity)));
155 Assert.IsTrue (double.IsNaN (Math.Acos (Double.PositiveInfinity)));
159 public void TestAsin ()
161 double a = Math.Asin (x);
162 double b = 0.12371534584255098;
164 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
165 + " != " + b.ToString ("G99"));
166 Assert.IsTrue (double.IsNaN (Math.Asin (-1.01D)));
167 Assert.IsTrue (double.IsNaN (Math.Asin (1.01D)));
168 Assert.IsTrue (double.IsNaN (Math.Asin (Double.MinValue)));
169 Assert.IsTrue (double.IsNaN (Math.Asin (Double.MaxValue)));
170 Assert.IsTrue (double.IsNaN (Math.Asin (Double.NegativeInfinity)));
171 Assert.IsTrue (double.IsNaN (Math.Asin (Double.PositiveInfinity)));
175 public void TestAtan ()
177 double a = Math.Atan (x);
178 double b = 0.12277930094473837;
179 double c = 1.5707963267948966;
180 double d = -1.5707963267948966;
182 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), "#1: " + a.ToString ("G99")
183 + " != " + b.ToString ("G99"));
184 Assert.IsTrue (double.IsNaN (Math.Atan (double.NaN)), "should return NaN");
185 Assert.IsTrue (Math.Abs ((double) Math.Atan (double.PositiveInfinity) - c) <= 0.0000000000000001,
186 "#2: " + Math.Atan (double.PositiveInfinity).ToString ("G99") + " != " + c.ToString ("G99"));
187 Assert.IsTrue (Math.Abs ((double) Math.Atan (double.NegativeInfinity) - d) <= 0.0000000000000001,
188 "#3: " + Math.Atan (double.NegativeInfinity).ToString ("G99") + " != " + d.ToString ("G99"));
192 public void TestAtan2 ()
194 double a = Math.Atan2 (x, y);
195 double b = 0.0099956168687207747;
197 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
198 + " != " + b.ToString ("G99"));
199 Assert.IsTrue (double.IsNaN (Math.Acos (-2D)));
200 Assert.IsTrue (double.IsNaN (Math.Acos (2D)));
203 // The following test is for methods that are in ECMA but they are
204 // not implemented in MS.NET. I leave them commented.
206 public void TestBigMul () {
207 int a = int.MaxValue;
208 int b = int.MaxValue;
210 Assert(((long)a * (long)b) == Math.BigMul(a,b));
215 public void TestCos ()
217 double a = Math.Cos (x);
218 double b = 0.99239587670489104;
220 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
221 + " != " + b.ToString ("G99"));
222 Assert.IsTrue (double.IsNaN (Math.Cos (Double.NaN)));
223 Assert.IsTrue (double.IsNaN (Math.Cos (Double.NegativeInfinity)));
224 Assert.IsTrue (double.IsNaN (Math.Cos (Double.PositiveInfinity)));
228 public void TestCosh ()
230 double a = Math.Cosh (x);
231 double b = 1.0076234465130722;
233 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
234 + " != " + b.ToString ("G99"));
235 Assert.IsTrue (Math.Cosh (double.NegativeInfinity) == double.PositiveInfinity);
236 Assert.IsTrue (Math.Cosh (double.PositiveInfinity) == double.PositiveInfinity);
237 Assert.IsTrue (double.IsNaN (Math.Cosh (double.NaN)));
240 // The following test is for methods that are in ECMA but they are
241 // not implemented in MS.NET. I leave them commented.
243 public void TestIntDivRem () {
246 int div = 0, rem = 0;
248 div = Math.DivRem (a, b, out rem);
250 Assert.IsTrue (rem == 1);
251 Assert.IsTrue (div == 2);
254 public void TestLongDivRem () {
257 long div = 0, rem = 0;
259 div = Math.DivRem (a, b, out rem);
261 Assert.IsTrue (rem == 1);
262 Assert.IsTrue (div == 2);
267 public void TestSin ()
269 double a = Math.Sin (x);
270 double b = 0.12308705821137626;
272 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
273 + " != " + b.ToString ("G99"));
274 Assert.IsTrue (double.IsNaN (Math.Sin (Double.NaN)));
275 Assert.IsTrue (double.IsNaN (Math.Sin (Double.NegativeInfinity)));
276 Assert.IsTrue (double.IsNaN (Math.Sin (Double.PositiveInfinity)));
280 public void TestSinh ()
282 double a = Math.Sinh (x);
283 double b = 0.12371341868561381;
285 Assert.IsTrue (Math.Abs (a - b) <= 0.0000000000000001, a.ToString ("G99")
286 + " != " + b.ToString ("G99"));
287 Assert.IsTrue (double.IsNaN (Math.Sinh (Double.NaN)));
288 Assert.IsTrue (double.IsNegativeInfinity (Math.Sinh (Double.NegativeInfinity)));
289 Assert.IsTrue (double.IsPositiveInfinity (Math.Sinh (Double.PositiveInfinity)));
293 public void TestTan ()
295 double a = Math.Tan (x);
296 double b = 0.12403019913793806;
298 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
299 + " != " + b.ToString ("G99"));
300 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.NaN)));
301 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.PositiveInfinity)));
302 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.NegativeInfinity)));
306 public void TestTanh ()
308 double a = Math.Tanh (x);
309 double b = 0.12277743150353424;
311 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
312 + " != " + b.ToString ("G99"));
313 Assert.IsTrue (Double.IsNaN (Math.Tanh (Double.NaN)),
314 "Tanh(NaN) should be NaN");
315 Assert.IsTrue (1 == Math.Tanh (Double.PositiveInfinity),
316 "Tanh(+Infinity) should be 1");
317 Assert.IsTrue (-1 == Math.Tanh (Double.NegativeInfinity),
318 "Tanh(-Infinity) should be -1");
322 public void TestSqrt ()
324 double a = Math.Sqrt (x);
325 double b = 0.35128336140500593;
327 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
328 + " != " + b.ToString ("G99"));
329 Assert.IsTrue (Double.IsNaN (Math.Sqrt (Double.NaN)));
330 Assert.IsTrue (Double.IsPositiveInfinity (Math.Sqrt (Double.PositiveInfinity)));
331 Assert.IsTrue (Double.IsNaN (Math.Sqrt (Double.NegativeInfinity)));
335 public void TestExp ()
337 double a = Math.Exp (x);
338 double b = 1.1313368651986859;
340 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
341 + " != " + b.ToString ("G99"));
342 Assert.IsTrue (double.IsNaN (Math.Exp (double.NaN)));
343 Assert.IsTrue (Math.Exp (double.NegativeInfinity) == 0);
344 Assert.IsTrue (Math.Exp (double.PositiveInfinity) == double.PositiveInfinity);
348 public void TestCeiling ()
352 double a = Math.Ceiling (1.5);
356 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
357 + " != " + b.ToString ("G99"));
359 Assert.IsTrue (Math.Ceiling (double.NegativeInfinity) == double.NegativeInfinity);
361 Assert.IsTrue (Math.Ceiling (double.PositiveInfinity) == double.PositiveInfinity);
363 Assert.IsTrue (double.IsNaN (Math.Ceiling (double.NaN)));
366 Assert.IsTrue (Double.MaxValue == Math.Ceiling (Double.MaxValue));
369 Assert.IsTrue (Double.MinValue == Math.Ceiling (Double.MinValue));
370 } catch (Exception e) {
371 Assert.Fail ("Unexpected Exception at iTest=" + iTest + ": " + e);
376 public void TestDecimalCeiling()
378 decimal a = Math.Ceiling(1.5M);
381 Assert.IsTrue (a == b, "#1");
382 Assert.IsTrue (Decimal.MaxValue == Math.Ceiling(Decimal.MaxValue), "#2");
383 Assert.IsTrue (Decimal.MinValue == Math.Ceiling(Decimal.MinValue), "#3");
387 public void TestFloor ()
389 double a = Math.Floor (1.5);
392 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
393 + " != " + b.ToString ("G99"));
394 Assert.IsTrue (Math.Floor (double.NegativeInfinity) == double.NegativeInfinity);
395 Assert.IsTrue (Math.Floor (double.PositiveInfinity) == double.PositiveInfinity);
396 Assert.IsTrue (double.IsNaN (Math.Floor (double.NaN)));
398 Assert.IsTrue (Double.MaxValue == Math.Floor (Double.MaxValue));
400 Assert.IsTrue (Double.MinValue == Math.Floor (Double.MinValue));
404 public void TestIEEERemainder ()
406 double a = Math.IEEERemainder (y, x);
407 double b = 0.0050000000000010592;
409 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
410 + " != " + b.ToString ("G99"));
412 Assert.IsTrue (double.IsNaN (Math.IEEERemainder (y, 0)), "Positive 0");
414 // http://www.obtuse.com/resources/negative_zero.html
415 double n0 = BitConverter.Int64BitsToDouble (Int64.MinValue);
416 Assert.IsTrue (double.IsNaN (Math.IEEERemainder (n0, 0)), "Negative 0");
418 // the "zero" remainder of negative number is negative
419 long result = BitConverter.DoubleToInt64Bits (Math.IEEERemainder (-1, 1));
420 Assert.AreEqual (Int64.MinValue, result, "Negative Dividend");
424 public void TestLog ()
426 double a = Math.Log (y);
427 double b = 2.513251122797143;
429 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
430 + " != " + b.ToString ("G99"));
431 Assert.IsTrue (double.IsNaN (Math.Log (-1)));
432 Assert.IsTrue (double.IsNaN (Math.Log (double.NaN)));
434 // MS docs say this should be PositiveInfinity
435 Assert.IsTrue (Math.Log (0) == double.NegativeInfinity);
436 Assert.IsTrue (Math.Log (double.PositiveInfinity) == double.PositiveInfinity);
440 public void TestLog2 ()
442 double a = Math.Log (x, y);
443 double b = -0.83251695325303621;
445 Assert.IsTrue ((Math.Abs (a - b) <= 1e-14), a + " != " + b
446 + " because diff is " + Math.Abs (a - b));
447 Assert.IsTrue (double.IsNaN (Math.Log (-1, y)));
448 Assert.IsTrue (double.IsNaN (Math.Log (double.NaN, y)));
449 Assert.IsTrue (double.IsNaN (Math.Log (x, double.NaN)));
450 Assert.IsTrue (double.IsNaN (Math.Log (double.NegativeInfinity, y)));
451 Assert.IsTrue (double.IsNaN (Math.Log (x, double.NegativeInfinity)));
452 Assert.IsTrue (double.IsNaN (Math.Log (double.PositiveInfinity, double.PositiveInfinity)));
453 Assert.IsTrue (double.IsNaN (Math.Log (2, 1)));
455 // MS docs say this should be PositiveInfinity
456 Assert.IsTrue (Math.Log (0, y) == double.NegativeInfinity);
457 Assert.IsTrue (Math.Log (double.PositiveInfinity, y) == double.PositiveInfinity);
459 Assert.IsTrue (Double.IsNaN (Math.Log (x, double.PositiveInfinity)));
463 public void TestLog10 ()
465 double a = Math.Log10 (x);
466 double b = -0.90868484030277719;
468 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
469 + " != " + b.ToString ("G99"));
470 Assert.IsTrue (double.IsNaN (Math.Log10 (-1)));
471 Assert.IsTrue (double.IsNaN (Math.Log10 (double.NaN)));
473 // MS docs say this should be PositiveInfinity
474 Assert.IsTrue (Math.Log10 (0) == double.NegativeInfinity);
475 Assert.IsTrue (Math.Log10 (double.PositiveInfinity) == double.PositiveInfinity);
480 public void TestPow ()
484 // It fails on Nexus 9 with
486 // 1.3636094460602122 != 1.3636094460602119
488 // when using double_epsilon. Precision differs between different ARM CPUs, so we
489 // will just use a more conservative value
490 precision = double_epsilon * 10;
492 precision = double_epsilon;
495 /* documentation cases : https://msdn.microsoft.com/en-us/library/system.math.pow%28v=vs.110%29.aspx */
497 /* x or y = NaN -> NaN */
498 Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, double.NaN)), "#1");
499 Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, double.NegativeInfinity)), "#2");
500 Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, -2)), "#2");
501 Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, -1)), "#3");
502 Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, 0)), "#4");
503 Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, 1)), "#5");
504 Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, 2)), "#6");
505 Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, double.PositiveInfinity)), "#7");
506 Assert.IsTrue (double.IsNaN (Math.Pow (double.NegativeInfinity, double.NaN)), "#8");
507 Assert.IsTrue (double.IsNaN (Math.Pow ( -2, double.NaN)), "#9");
508 Assert.IsTrue (double.IsNaN (Math.Pow ( -1, double.NaN)), "#10");
509 Assert.IsTrue (double.IsNaN (Math.Pow ( 0, double.NaN)), "#11");
510 Assert.IsTrue (double.IsNaN (Math.Pow ( 1, double.NaN)), "#12");
511 Assert.IsTrue (double.IsNaN (Math.Pow ( 2, double.NaN)), "#13");
512 Assert.IsTrue (double.IsNaN (Math.Pow (double.PositiveInfinity, double.NaN)), "#14");
514 /* x = Any value except NaN; y = 0 -> 1 */
515 Assert.AreEqual ((double) 1, Math.Pow (2, 0), "#15");
517 /* x = NegativeInfinity; y < 0 -> 0 */
518 Assert.AreEqual ((double) 0, Math.Pow (double.NegativeInfinity, -2), "#16");
520 /* x = NegativeInfinity; y is a positive odd integer -> NegativeInfinity */
521 Assert.AreEqual (double.NegativeInfinity, Math.Pow (double.NegativeInfinity, 3), "#17");
523 /* x = NegativeInfinity; y is positive but not an odd integer -> PositiveInfinity */
524 Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.NegativeInfinity, 2), "#18");
526 /* x < 0 but not NegativeInfinity; y is not an integer, NegativeInfinity, or PositiveInfinity -> NaN */
527 Assert.IsTrue (double.IsNaN (Math.Pow (-1, 2.5)), "#19");
529 /* x = -1; y = NegativeInfinity or PositiveInfinity -> NaN */
530 Assert.IsTrue (double.IsNaN (Math.Pow (-1, double.PositiveInfinity)), "#20");
531 Assert.IsTrue (double.IsNaN (Math.Pow (-1, double.NegativeInfinity)), "#21");
533 /* -1 < x < 1; y = NegativeInfinity -> PositiveInfinity */
534 Assert.AreEqual (double.PositiveInfinity, Math.Pow (-0.5, double.NegativeInfinity), "#22");
535 Assert.AreEqual (double.PositiveInfinity, Math.Pow (+0.5, double.NegativeInfinity), "#23");
537 /* -1 < x < 1; y = PositiveInfinity -> 0 */
538 Assert.AreEqual ((double) 0, Math.Pow (-0.5, double.PositiveInfinity), "#24");
539 Assert.AreEqual ((double) 0, Math.Pow (+0.5, double.PositiveInfinity), "#25");
541 /* x < -1 or x > 1; y = NegativeInfinity -> 0 */
542 Assert.AreEqual ((double) 0, Math.Pow (-2, double.NegativeInfinity), "#26");
543 Assert.AreEqual ((double) 0, Math.Pow (+2, double.NegativeInfinity), "#27");
545 /* x < -1 or x > 1; y = PositiveInfinity -> PositiveInfinity */
546 Assert.AreEqual (double.PositiveInfinity, Math.Pow (-2, double.PositiveInfinity), "#28");
547 Assert.AreEqual (double.PositiveInfinity, Math.Pow (+2, double.PositiveInfinity), "#29");
549 /* x = 0; y < 0 -> PositiveInfinity */
550 Assert.AreEqual (double.PositiveInfinity, Math.Pow (0, -2), "#30");
552 /* x = 0; y > 0 -> PositiveInfinity */
553 Assert.AreEqual ((double) 0, Math.Pow (0, +2), "#31");
555 /* x = 1; y is any value except NaN -> 1 */
556 Assert.AreEqual ((double) 1, Math.Pow (1, double.NegativeInfinity), "#32");
557 Assert.AreEqual ((double) 1, Math.Pow (1, -2), "#33");
558 Assert.AreEqual ((double) 1, Math.Pow (1, 0), "#34");
559 Assert.AreEqual ((double) 1, Math.Pow (1, +2), "#35");
560 Assert.AreEqual ((double) 1, Math.Pow (1, double.PositiveInfinity), "#36");
562 /* x = PositiveInfinity; y < 0 -> 0 */
563 Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, -1), "#37");
564 Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, -2), "#38");
566 /* x = PositiveInfinity; y > 0 -> PositiveInfinity */
567 Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.PositiveInfinity, 1), "#39");
568 Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.PositiveInfinity, 2), "#40");
572 double a = Math.Pow (y, x);
573 double b = 1.363609446060212;
575 Assert.IsTrue (Math.Abs (a - b) <= precision, "#41 " + a.ToString ("G99") + " != " + b.ToString ("G99") + " +/- " + precision.ToString ("G99"));
576 Assert.AreEqual (double.NegativeInfinity, Math.Pow (double.NegativeInfinity, 1), "#42");
577 Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.NegativeInfinity, 2), "#43");
579 Assert.AreEqual (Math.Pow (double.PositiveInfinity, double.NegativeInfinity), (double) 0, "#44");
581 Assert.AreEqual ((double) 1, Math.Pow (-1, Double.MaxValue), "#45");
582 Assert.AreEqual ((double) 1, Math.Pow (-1, Double.MinValue), "#46");
583 Assert.AreEqual ((double) 0, Math.Pow (Double.MinValue, Double.MinValue), "#47");
584 Assert.AreEqual (double.PositiveInfinity, Math.Pow (Double.MinValue, Double.MaxValue), "#48");
586 double infinity = double.PositiveInfinity;
587 Assert.AreEqual ((double) 0, Math.Pow ( 0.5, infinity), "#49");
588 Assert.AreEqual ( infinity, Math.Pow ( 0.5, -infinity), "#50");
589 Assert.AreEqual ( infinity, Math.Pow ( 2, infinity), "#51");
590 Assert.AreEqual ((double) 0, Math.Pow ( 2, -infinity), "#52");
591 Assert.AreEqual ((double) 1, Math.Pow ( infinity, 0), "#53");
592 Assert.AreEqual ((double) 1, Math.Pow (-infinity, 0), "#54");
596 public void TestByteMax ()
601 Assert.IsTrue (b == Math.Max (a, b), "#1");
602 Assert.IsTrue (b == Math.Max (b, a), "#2");
606 public void TestDecimalMax ()
611 Assert.IsTrue (b == Math.Max (a, b), "#1");
612 Assert.IsTrue (b == Math.Max (b, a), "#2");
616 public void TestDoubleMax ()
621 Assert.IsTrue (b == Math.Max (a, b), "#1");
622 Assert.IsTrue (b == Math.Max (b, a), "#2");
624 Assert.IsTrue (Double.IsNaN (Math.Max (Double.NaN, Double.NaN)), "#3");
625 Assert.IsTrue (Double.IsNaN (Math.Max (Double.NaN, a)), "#4");
626 Assert.IsTrue (Double.IsNaN (Math.Max (b, Double.NaN)), "#5");
630 public void TestFloatMax ()
635 Assert.IsTrue (b == Math.Max (a, b), "#1");
636 Assert.IsTrue (b == Math.Max (b, a), "#2");
637 Assert.IsTrue (Single.IsNaN (Math.Max (Single.NaN, Single.NaN)), "#3");
638 Assert.IsTrue (Single.IsNaN (Math.Max (Single.NaN, a)), "#4");
639 Assert.IsTrue (Single.IsNaN (Math.Max (b, Single.NaN)), "#5");
643 public void TestIntMax ()
650 Assert.AreEqual (b, Math.Max (a, b), "#1");
651 Assert.AreEqual (b, Math.Max (b, a), "#2");
652 Assert.AreEqual (c, Math.Max (c, d), "#3");
653 Assert.AreEqual (c, Math.Max (d, c), "#4");
657 public void TestLongMax ()
662 Assert.IsTrue (b == Math.Max (a, b), "#1");
663 Assert.IsTrue (b == Math.Max (b, a), "#2");
667 public void TestSbyteMax ()
672 Assert.IsTrue (b == Math.Max (a, b), "#1");
673 Assert.IsTrue (b == Math.Max (b, a), "#2");
677 public void TestShortMax ()
682 Assert.IsTrue (b == Math.Max (a, b), "#1");
683 Assert.IsTrue (b == Math.Max (b, a), "#2");
687 public void TestUintMax ()
692 Assert.IsTrue (b == Math.Max (a, b), "#1");
693 Assert.IsTrue (b == Math.Max (b, a), "#2");
697 public void TestUlongMax ()
702 Assert.IsTrue (b == Math.Max (a, b), "#1");
703 Assert.IsTrue (b == Math.Max (b, a), "#2");
707 public void TestUshortMax ()
712 Assert.IsTrue (b == Math.Max (a, b), "#1");
713 Assert.IsTrue (b == Math.Max (b, a), "#2");
717 public void TestByteMin ()
722 Assert.IsTrue (a == Math.Min (a, b), "#1");
723 Assert.IsTrue (a == Math.Min (b, a), "#2");
727 public void TestDecimalMin ()
732 Assert.IsTrue (a == Math.Min (a, b), "#1");
733 Assert.IsTrue (a == Math.Min (b, a), "#2");
737 public void TestDoubleMin ()
742 Assert.IsTrue (a == Math.Min (a, b), "#1");
743 Assert.IsTrue (a == Math.Min (b, a), "#2");
744 Assert.IsTrue (Double.IsNaN (Math.Min (Double.NaN, Double.NaN)), "#3");
745 Assert.IsTrue (Double.IsNaN (Math.Min (Double.NaN, a)), "#4");
746 Assert.IsTrue (Double.IsNaN (Math.Min (b, Double.NaN)), "#5");
750 public void TestFloatMin ()
755 Assert.IsTrue (a == Math.Min (a, b), "#1");
756 Assert.IsTrue (a == Math.Min (b, a), "#2");
757 Assert.IsTrue (Single.IsNaN (Math.Min (Single.NaN, Single.NaN)), "#3");
758 Assert.IsTrue (Single.IsNaN (Math.Min (Single.NaN, a)), "#4");
759 Assert.IsTrue (Single.IsNaN (Math.Min (b, Single.NaN)), "#5");
763 public void TestIntMin ()
768 Assert.IsTrue (a == Math.Min (a, b), "#1");
769 Assert.IsTrue (a == Math.Min (b, a), "#2");
773 public void TestLongMin ()
778 Assert.IsTrue (a == Math.Min (a, b), "#1");
779 Assert.IsTrue (a == Math.Min (b, a), "#2");
783 public void TestSbyteMin ()
788 Assert.IsTrue (a == Math.Min (a, b), "#1");
789 Assert.IsTrue (a == Math.Min (b, a), "#2");
793 public void TestShortMin ()
798 Assert.IsTrue (a == Math.Min (a, b), "#1");
799 Assert.IsTrue (a == Math.Min (b, a), "#2");
803 public void TestUintMin ()
808 Assert.IsTrue (a == Math.Min (a, b), "#1");
809 Assert.IsTrue (a == Math.Min (b, a), "#2");
813 public void TestUlongMin ()
818 Assert.IsTrue (a == Math.Min (a, b), "#1");
819 Assert.IsTrue (a == Math.Min (b, a), "#2");
823 public void TestUshortMin ()
828 Assert.IsTrue (a == Math.Min (a, b), "#1");
829 Assert.IsTrue (a == Math.Min (b, a), "#2");
833 public void TestDecimalRound ()
838 Assert.IsTrue (Math.Round (a) == 2, "#1");
839 Assert.IsTrue (Math.Round (b) == 2, "#2");
840 Assert.IsTrue (Decimal.MaxValue == Math.Round (Decimal.MaxValue), "#3");
841 Assert.IsTrue (Decimal.MinValue == Math.Round (Decimal.MinValue), "#4");
845 public void TestDecimalRound2 ()
850 Assert.AreEqual (3.4M, Math.Round (a, 1), "#1");
851 Assert.AreEqual (3.5M, Math.Round (b, 1), "#2");
855 public void TestDoubleRound ()
860 Assert.AreEqual (2D, Math.Round (a), "#1");
861 Assert.AreEqual (2D, Math.Round (b), "#2");
862 Assert.IsTrue (Double.MaxValue == Math.Round (Double.MaxValue), "#3");
863 Assert.IsTrue (Double.MinValue == Math.Round (Double.MinValue), "#4");
867 public void TestDoubleTruncate ()
873 Assert.AreEqual (1D, Math.Truncate (a), "#1");
874 Assert.AreEqual (2D, Math.Truncate (b), "#2");
876 Assert.AreEqual (-1D, Math.Truncate (a * -1D), "#3");
877 Assert.AreEqual (-2D, Math.Truncate (b * -1D), "#4");
879 Assert.AreEqual (0D, Math.Truncate (c), "#5");
881 Assert.IsTrue (Double.MaxValue == Math.Truncate (Double.MaxValue), "#6");
882 Assert.IsTrue (Double.MinValue == Math.Truncate (Double.MinValue), "#7");
886 public void TestDecimalTruncate ()
892 Assert.AreEqual (1M, Math.Truncate (a), "#1");
893 Assert.AreEqual (2M, Math.Truncate (b), "#2");
895 Assert.AreEqual (-1M, Math.Truncate (a * -1M), "#3");
896 Assert.AreEqual (-2M, Math.Truncate (b * -1M), "#4");
898 Assert.AreEqual (0M, Math.Truncate (c), "#5");
900 Assert.IsTrue (Decimal.MaxValue == Math.Truncate (Decimal.MaxValue), "#6");
901 Assert.IsTrue (Decimal.MinValue == Math.Truncate (Decimal.MinValue), "#7");
905 public void TestDoubleRound2 ()
910 Assert.AreEqual (3.4D, Math.Round (a, 1), "#1");
911 Assert.AreEqual (3.5D, Math.Round (b, 1), "#2");
912 Assert.AreEqual (-0.1, Math.Round (-0.123456789, 1), "#3");
916 public void TestDoubleRound3 ()
918 Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.ToEven), "#1");
919 Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.AwayFromZero), "#2");
921 Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.ToEven), "#3");
922 Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.AwayFromZero), "#4");
924 Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.ToEven), "#5");
925 Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.AwayFromZero), "#6");
927 Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.ToEven), "#7");
928 Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.AwayFromZero), "#8");
930 Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.ToEven), "#9");
931 Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.AwayFromZero), "#A");
933 Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.ToEven), "#B");
934 Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.AwayFromZero), "#C");
936 Assert.AreEqual (1.2D, Math.Round (1.2345D, 1, MidpointRounding.ToEven), "#D");
937 Assert.AreEqual (1.2D, Math.Round (1.2345D, 1, MidpointRounding.AwayFromZero), "#E");
939 Assert.AreEqual (-1.2D, Math.Round (-1.2345D, 1, MidpointRounding.ToEven), "#F");
940 Assert.AreEqual (-1.2D, Math.Round (-1.2345D, 1, MidpointRounding.AwayFromZero), "#10");
942 Assert.AreEqual (1.23D, Math.Round (1.2345D, 2, MidpointRounding.ToEven), "#11");
943 Assert.AreEqual (1.23D, Math.Round (1.2345D, 2, MidpointRounding.AwayFromZero), "#12");
945 Assert.AreEqual (-1.23D, Math.Round (-1.2345D, 2, MidpointRounding.ToEven), "#13");
946 Assert.AreEqual (-1.23D, Math.Round (-1.2345D, 2, MidpointRounding.AwayFromZero), "#14");
948 Assert.AreEqual (1.234D, Math.Round (1.2345D, 3, MidpointRounding.ToEven), "#15");
949 Assert.AreEqual (1.235D, Math.Round (1.2345D, 3, MidpointRounding.AwayFromZero), "#16");
951 Assert.AreEqual (-1.234D, Math.Round (-1.2345D, 3, MidpointRounding.ToEven), "#17");
952 Assert.AreEqual (-1.235D, Math.Round (-1.2345D, 3, MidpointRounding.AwayFromZero), "#18");
954 Assert.AreEqual (1.2345D, Math.Round (1.2345D, 4, MidpointRounding.ToEven), "#19");
955 Assert.AreEqual (1.2345D, Math.Round (1.2345D, 4, MidpointRounding.AwayFromZero), "#1A");
957 Assert.AreEqual (-1.2345D, Math.Round (-1.2345D, 4, MidpointRounding.ToEven), "#1B");
958 Assert.AreEqual (-1.2345D, Math.Round (-1.2345D, 4, MidpointRounding.AwayFromZero), "#1C");
960 Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.ToEven), "#1D");
961 Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.AwayFromZero), "#1E");
963 Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.ToEven), "#1F");
964 Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.AwayFromZero), "#20");
966 Assert.AreEqual (1.5D, Math.Round (1.5432D, 1, MidpointRounding.ToEven), "#21");
967 Assert.AreEqual (1.5D, Math.Round (1.5432D, 1, MidpointRounding.AwayFromZero), "#22");
969 Assert.AreEqual (-1.5D, Math.Round (-1.5432D, 1, MidpointRounding.ToEven), "#23");
970 Assert.AreEqual (-1.5D, Math.Round (-1.5432D, 1, MidpointRounding.AwayFromZero), "#24");
972 Assert.AreEqual (1.54D, Math.Round (1.5432D, 2, MidpointRounding.ToEven), "#25");
973 Assert.AreEqual (1.54D, Math.Round (1.5432D, 2, MidpointRounding.AwayFromZero), "#26");
975 Assert.AreEqual (-1.54D, Math.Round (-1.5432D, 2, MidpointRounding.ToEven), "#27");
976 Assert.AreEqual (-1.54D, Math.Round (-1.5432D, 2, MidpointRounding.AwayFromZero), "#28");
978 Assert.AreEqual (1.543D, Math.Round (1.5432D, 3, MidpointRounding.ToEven), "#29");
979 Assert.AreEqual (1.543D, Math.Round (1.5432D, 3, MidpointRounding.AwayFromZero), "#2A");
981 Assert.AreEqual (-1.543D, Math.Round (-1.5432D, 3, MidpointRounding.ToEven), "#2B");
982 Assert.AreEqual (-1.543D, Math.Round (-1.5432D, 3, MidpointRounding.AwayFromZero), "#2C");
984 Assert.AreEqual (1.5432D, Math.Round (1.5432D, 4, MidpointRounding.ToEven), "#2D");
985 Assert.AreEqual (1.5432D, Math.Round (1.5432D, 4, MidpointRounding.AwayFromZero), "#2E");
987 Assert.AreEqual (-1.5432D, Math.Round (-1.5432D, 4, MidpointRounding.ToEven), "#2F");
988 Assert.AreEqual (-1.5432D, Math.Round (-1.5432D, 4, MidpointRounding.AwayFromZero), "#30");
990 Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.ToEven), "#31");
991 Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.AwayFromZero), "#32");
993 Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.ToEven), "#33");
994 Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.AwayFromZero), "#34");
996 Assert.AreEqual (63987.83594D, Math.Round (63987.83593942D, 5, MidpointRounding.ToEven), "#35");
997 Assert.AreEqual (63987.83594D, Math.Round (63987.83593942D, 5, MidpointRounding.AwayFromZero), "#36");
999 Assert.AreEqual (-63987.83594D, Math.Round (-63987.83593942D, 5, MidpointRounding.ToEven), "#37");
1000 Assert.AreEqual (-63987.83594D, Math.Round (-63987.83593942D, 5, MidpointRounding.AwayFromZero), "#38");
1002 Assert.AreEqual (63987.83593942D, Math.Round (63987.83593942D, 8, MidpointRounding.ToEven), "#39");
1003 Assert.AreEqual (63987.83593942D, Math.Round (63987.83593942D, 8, MidpointRounding.AwayFromZero), "#3A");
1005 Assert.AreEqual (-63987.83593942D, Math.Round (-63987.83593942D, 8, MidpointRounding.ToEven), "#3B");
1006 Assert.AreEqual (-63987.83593942D, Math.Round (-63987.83593942D, 8, MidpointRounding.AwayFromZero), "#3C");
1008 Assert.AreEqual (1, Math.Round (0.5, 0, MidpointRounding.AwayFromZero));
1012 public void TestDecimalSign ()
1017 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1018 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1019 Assert.IsTrue (Math.Sign (0M) == 0, "#3");
1023 public void TestDoubleSign ()
1028 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1029 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1030 Assert.IsTrue (Math.Sign (0D) == 0, "#3");
1034 public void TestFloatSign ()
1039 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1040 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1041 Assert.IsTrue (Math.Sign (0F) == 0, "#3");
1045 public void TestIntSign ()
1050 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1051 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1052 Assert.IsTrue (Math.Sign (0) == 0, "#3");
1056 public void TestLongSign ()
1061 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1062 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1063 Assert.IsTrue (Math.Sign (0L) == 0, "#3");
1067 public void TestSbyteSign ()
1072 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1073 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1074 Assert.IsTrue (Math.Sign (0) == 0, "#3");
1078 public void TestShortSign ()
1083 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1084 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1085 Assert.IsTrue (Math.Sign (0) == 0, "#3");