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 =
22 static double x = 0.1234;
23 static double y = 12.345;
26 public void TestDecimalAbs ()
30 Assert.IsTrue (9.0M == Math.Abs (a), "#1");
31 Assert.IsTrue (Decimal.MaxValue == Math.Abs (Decimal.MaxValue), "#2");
32 Assert.IsTrue (Decimal.MaxValue == Math.Abs (Decimal.MinValue), "#3");
33 Assert.IsTrue (Decimal.Zero == Math.Abs (Decimal.Zero), "#4");
34 Assert.IsTrue (Decimal.One == Math.Abs (Decimal.One), "#5");
35 Assert.IsTrue (Decimal.One == Math.Abs (Decimal.MinusOne), "#6");
39 public void TestDoubleAbs ()
43 Assert.IsTrue (9.0D == Math.Abs (a), "#1");
44 Assert.IsTrue (0.0D == Math.Abs (0.0D), "#2");
45 Assert.IsTrue (Double.MaxValue == Math.Abs (Double.MaxValue), "#3");
46 Assert.IsTrue (Double.MaxValue == Math.Abs (Double.MinValue), "#4");
47 Assert.IsTrue (Double.IsPositiveInfinity (Math.Abs (Double.PositiveInfinity)), "#5");
48 Assert.IsTrue (Double.IsPositiveInfinity (Math.Abs (Double.NegativeInfinity)), "#6");
49 Assert.IsTrue (Double.IsNaN (Math.Abs (Double.NaN)), "#7");
53 public void TestFloatAbs ()
57 Assert.IsTrue (9.0F == Math.Abs (a), "#1");
58 Assert.IsTrue (0.0F == Math.Abs (0.0F), "#2");
59 Assert.IsTrue (Single.MaxValue == Math.Abs (Single.MaxValue), "#3");
60 Assert.IsTrue (Single.MaxValue == Math.Abs (Single.MinValue), "#4");
61 Assert.IsTrue (Single.PositiveInfinity == Math.Abs (Single.PositiveInfinity), "#5");
62 Assert.IsTrue (Single.PositiveInfinity == Math.Abs (Single.NegativeInfinity), "#6");
63 Assert.IsTrue (Single.IsNaN (Math.Abs (Single.NaN)), "#7");
67 public void TestLongAbs ()
70 long b = Int64.MinValue;
72 Assert.IsTrue (9L == Math.Abs (a), "#1");
76 } catch (Exception e) {
77 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
79 Assert.IsTrue (Int64.MaxValue == Math.Abs (Int64.MaxValue), "#4");
83 public void TestIntAbs ()
86 int b = Int32.MinValue;
88 Assert.IsTrue (9 == Math.Abs (a), "#1");
92 } catch (Exception e) {
93 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
95 Assert.IsTrue (Int32.MaxValue == Math.Abs (Int32.MaxValue), "#4");
99 public void TestSbyteAbs ()
102 sbyte b = SByte.MinValue;
104 Assert.IsTrue (9 == Math.Abs (a), "#1");
108 } catch (Exception e) {
109 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
111 Assert.IsTrue (SByte.MaxValue == Math.Abs (SByte.MaxValue), "#4");
115 public void TestShortAbs ()
118 short b = Int16.MinValue;
120 Assert.IsTrue (9 == Math.Abs (a), "#1");
124 } catch (Exception e) {
125 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
127 Assert.IsTrue (Int16.MaxValue == Math.Abs (Int16.MaxValue), "#4");
131 public void TestAcos ()
133 double a = Math.Acos (x);
134 double b = 1.4470809809523457;
136 bool regularTest = (Math.Abs (a - b) <= double_epsilon);
139 // On MacOS X libc acos (0.1234) returns
140 // 1.4470809809523455 (hex 0x3ff7273e62fda9ab) instead
141 // of 1.4470809809523457 (hex 0x3ff7273e62fda9ac)
143 // For now, let it go
145 if (a == 1.4470809809523455)
149 Assert.IsTrue (regularTest, a.ToString ("G99") + " != " + b.ToString ("G99"));
151 Assert.IsTrue (double.IsNaN (Math.Acos (-1.01D)));
152 Assert.IsTrue (double.IsNaN (Math.Acos (1.01D)));
153 Assert.IsTrue (double.IsNaN (Math.Acos (Double.MinValue)));
154 Assert.IsTrue (double.IsNaN (Math.Acos (Double.MaxValue)));
155 Assert.IsTrue (double.IsNaN (Math.Acos (Double.NegativeInfinity)));
156 Assert.IsTrue (double.IsNaN (Math.Acos (Double.PositiveInfinity)));
160 public void TestAsin ()
162 double a = Math.Asin (x);
163 double b = 0.12371534584255098;
165 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
166 + " != " + b.ToString ("G99"));
167 Assert.IsTrue (double.IsNaN (Math.Asin (-1.01D)));
168 Assert.IsTrue (double.IsNaN (Math.Asin (1.01D)));
169 Assert.IsTrue (double.IsNaN (Math.Asin (Double.MinValue)));
170 Assert.IsTrue (double.IsNaN (Math.Asin (Double.MaxValue)));
171 Assert.IsTrue (double.IsNaN (Math.Asin (Double.NegativeInfinity)));
172 Assert.IsTrue (double.IsNaN (Math.Asin (Double.PositiveInfinity)));
176 public void TestAtan ()
178 double a = Math.Atan (x);
179 double b = 0.12277930094473837;
180 double c = 1.5707963267948966;
181 double d = -1.5707963267948966;
183 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), "#1: " + a.ToString ("G99")
184 + " != " + b.ToString ("G99"));
185 Assert.IsTrue (double.IsNaN (Math.Atan (double.NaN)), "should return NaN");
186 Assert.IsTrue (Math.Abs ((double) Math.Atan (double.PositiveInfinity) - c) <= 0.0000000000000001,
187 "#2: " + Math.Atan (double.PositiveInfinity).ToString ("G99") + " != " + c.ToString ("G99"));
188 Assert.IsTrue (Math.Abs ((double) Math.Atan (double.NegativeInfinity) - d) <= 0.0000000000000001,
189 "#3: " + Math.Atan (double.NegativeInfinity).ToString ("G99") + " != " + d.ToString ("G99"));
193 public void TestAtan2 ()
195 double a = Math.Atan2 (x, y);
196 double b = 0.0099956168687207747;
198 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
199 + " != " + b.ToString ("G99"));
200 Assert.IsTrue (double.IsNaN (Math.Acos (-2D)));
201 Assert.IsTrue (double.IsNaN (Math.Acos (2D)));
204 // The following test is for methods that are in ECMA but they are
205 // not implemented in MS.NET. I leave them commented.
207 public void TestBigMul () {
208 int a = int.MaxValue;
209 int b = int.MaxValue;
211 Assert(((long)a * (long)b) == Math.BigMul(a,b));
216 public void TestCos ()
218 double a = Math.Cos (x);
219 double b = 0.99239587670489104;
221 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
222 + " != " + b.ToString ("G99"));
223 Assert.IsTrue (double.IsNaN (Math.Cos (Double.NaN)));
224 Assert.IsTrue (double.IsNaN (Math.Cos (Double.NegativeInfinity)));
225 Assert.IsTrue (double.IsNaN (Math.Cos (Double.PositiveInfinity)));
229 public void TestCosh ()
231 double a = Math.Cosh (x);
232 double b = 1.0076234465130722;
234 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
235 + " != " + b.ToString ("G99"));
236 Assert.IsTrue (Math.Cosh (double.NegativeInfinity) == double.PositiveInfinity);
237 Assert.IsTrue (Math.Cosh (double.PositiveInfinity) == double.PositiveInfinity);
238 Assert.IsTrue (double.IsNaN (Math.Cosh (double.NaN)));
241 // The following test is for methods that are in ECMA but they are
242 // not implemented in MS.NET. I leave them commented.
244 public void TestIntDivRem () {
247 int div = 0, rem = 0;
249 div = Math.DivRem (a, b, out rem);
251 Assert.IsTrue (rem == 1);
252 Assert.IsTrue (div == 2);
255 public void TestLongDivRem () {
258 long div = 0, rem = 0;
260 div = Math.DivRem (a, b, out rem);
262 Assert.IsTrue (rem == 1);
263 Assert.IsTrue (div == 2);
268 public void TestSin ()
270 double a = Math.Sin (x);
271 double b = 0.12308705821137626;
273 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
274 + " != " + b.ToString ("G99"));
275 Assert.IsTrue (double.IsNaN (Math.Sin (Double.NaN)));
276 Assert.IsTrue (double.IsNaN (Math.Sin (Double.NegativeInfinity)));
277 Assert.IsTrue (double.IsNaN (Math.Sin (Double.PositiveInfinity)));
281 public void TestSinh ()
283 double a = Math.Sinh (x);
284 double b = 0.12371341868561381;
286 Assert.IsTrue (Math.Abs (a - b) <= 0.0000000000000001, a.ToString ("G99")
287 + " != " + b.ToString ("G99"));
288 Assert.IsTrue (double.IsNaN (Math.Sinh (Double.NaN)));
289 Assert.IsTrue (double.IsNegativeInfinity (Math.Sinh (Double.NegativeInfinity)));
290 Assert.IsTrue (double.IsPositiveInfinity (Math.Sinh (Double.PositiveInfinity)));
294 public void TestTan ()
296 double a = Math.Tan (x);
297 double b = 0.12403019913793806;
299 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
300 + " != " + b.ToString ("G99"));
301 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.NaN)));
302 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.PositiveInfinity)));
303 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.NegativeInfinity)));
307 public void TestTanh ()
309 double a = Math.Tanh (x);
310 double b = 0.12277743150353424;
312 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
313 + " != " + b.ToString ("G99"));
314 Assert.IsTrue (Double.IsNaN (Math.Tanh (Double.NaN)),
315 "Tanh(NaN) should be NaN");
316 Assert.IsTrue (1 == Math.Tanh (Double.PositiveInfinity),
317 "Tanh(+Infinity) should be 1");
318 Assert.IsTrue (-1 == Math.Tanh (Double.NegativeInfinity),
319 "Tanh(-Infinity) should be -1");
323 public void TestSqrt ()
325 double a = Math.Sqrt (x);
326 double b = 0.35128336140500593;
328 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
329 + " != " + b.ToString ("G99"));
330 Assert.IsTrue (Double.IsNaN (Math.Sqrt (Double.NaN)));
331 Assert.IsTrue (Double.IsPositiveInfinity (Math.Sqrt (Double.PositiveInfinity)));
332 Assert.IsTrue (Double.IsNaN (Math.Sqrt (Double.NegativeInfinity)));
336 public void TestExp ()
338 double a = Math.Exp (x);
339 double b = 1.1313368651986859;
341 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
342 + " != " + b.ToString ("G99"));
343 Assert.IsTrue (double.IsNaN (Math.Exp (double.NaN)));
344 Assert.IsTrue (Math.Exp (double.NegativeInfinity) == 0);
345 Assert.IsTrue (Math.Exp (double.PositiveInfinity) == double.PositiveInfinity);
349 public void TestCeiling ()
353 double a = Math.Ceiling (1.5);
357 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
358 + " != " + b.ToString ("G99"));
360 Assert.IsTrue (Math.Ceiling (double.NegativeInfinity) == double.NegativeInfinity);
362 Assert.IsTrue (Math.Ceiling (double.PositiveInfinity) == double.PositiveInfinity);
364 Assert.IsTrue (double.IsNaN (Math.Ceiling (double.NaN)));
367 Assert.IsTrue (Double.MaxValue == Math.Ceiling (Double.MaxValue));
370 Assert.IsTrue (Double.MinValue == Math.Ceiling (Double.MinValue));
371 } catch (Exception e) {
372 Assert.Fail ("Unexpected Exception at iTest=" + iTest + ": " + e);
377 public void TestDecimalCeiling()
379 decimal a = Math.Ceiling(1.5M);
382 Assert.IsTrue (a == b, "#1");
383 Assert.IsTrue (Decimal.MaxValue == Math.Ceiling(Decimal.MaxValue), "#2");
384 Assert.IsTrue (Decimal.MinValue == Math.Ceiling(Decimal.MinValue), "#3");
388 public void TestFloor ()
390 double a = Math.Floor (1.5);
393 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
394 + " != " + b.ToString ("G99"));
395 Assert.IsTrue (Math.Floor (double.NegativeInfinity) == double.NegativeInfinity);
396 Assert.IsTrue (Math.Floor (double.PositiveInfinity) == double.PositiveInfinity);
397 Assert.IsTrue (double.IsNaN (Math.Floor (double.NaN)));
399 Assert.IsTrue (Double.MaxValue == Math.Floor (Double.MaxValue));
401 Assert.IsTrue (Double.MinValue == Math.Floor (Double.MinValue));
405 public void TestIEEERemainder ()
407 double a = Math.IEEERemainder (y, x);
408 double b = 0.0050000000000007816;
410 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
411 + " != " + b.ToString ("G99"));
413 Assert.IsTrue (double.IsNaN (Math.IEEERemainder (y, 0)), "Positive 0");
415 // http://www.obtuse.com/resources/negative_zero.html
416 double n0 = BitConverter.Int64BitsToDouble (Int64.MinValue);
417 Assert.IsTrue (double.IsNaN (Math.IEEERemainder (n0, 0)), "Negative 0");
419 // the "zero" remainder of negative number is negative
420 long result = BitConverter.DoubleToInt64Bits (Math.IEEERemainder (-1, 1));
421 Assert.AreEqual (Int64.MinValue, result, "Negative Dividend");
425 public void TestLog ()
427 double a = Math.Log (y);
428 double b = 2.513251122797143;
430 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
431 + " != " + b.ToString ("G99"));
432 Assert.IsTrue (double.IsNaN (Math.Log (-1)));
433 Assert.IsTrue (double.IsNaN (Math.Log (double.NaN)));
435 // MS docs say this should be PositiveInfinity
436 Assert.IsTrue (Math.Log (0) == double.NegativeInfinity);
437 Assert.IsTrue (Math.Log (double.PositiveInfinity) == double.PositiveInfinity);
441 public void TestLog2 ()
443 double a = Math.Log (x, y);
444 double b = -0.83251695325303621;
446 Assert.IsTrue ((Math.Abs (a - b) <= 1e-14), a + " != " + b
447 + " because diff is " + Math.Abs (a - b));
448 Assert.IsTrue (double.IsNaN (Math.Log (-1, y)));
449 Assert.IsTrue (double.IsNaN (Math.Log (double.NaN, y)));
450 Assert.IsTrue (double.IsNaN (Math.Log (x, double.NaN)));
451 Assert.IsTrue (double.IsNaN (Math.Log (double.NegativeInfinity, y)));
452 Assert.IsTrue (double.IsNaN (Math.Log (x, double.NegativeInfinity)));
453 Assert.IsTrue (double.IsNaN (Math.Log (double.PositiveInfinity, double.PositiveInfinity)));
454 Assert.IsTrue (double.IsNaN (Math.Log (2, 1)));
456 // MS docs say this should be PositiveInfinity
457 Assert.IsTrue (Math.Log (0, y) == double.NegativeInfinity);
458 Assert.IsTrue (Math.Log (double.PositiveInfinity, y) == double.PositiveInfinity);
459 Assert.IsTrue (Math.Log (x, double.PositiveInfinity) == 0);
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 ()
485 // It fails on Nexus 9 with
487 // 1.3636094460602122 != 1.3636094460602119
489 // when using double_epsilon. Precision differs between different ARM CPUs, so we
490 // will just use a more conservative value
491 precision = 0.000001;
493 precision = double_epsilon;
496 double a = Math.Pow (y, x);
497 double b = 1.363609446060212;
499 Assert.IsTrue ((Math.Abs (a - b) <= precision), a.ToString ("G99") + " != " + b.ToString ("G99"));
501 Assert.IsTrue (double.IsNaN (Math.Pow (y, double.NaN)));
503 Assert.IsTrue (double.IsNaN (Math.Pow (double.NaN, x)));
505 Assert.IsTrue (double.IsNegativeInfinity (Math.Pow (double.NegativeInfinity, 1)),
506 "Math.Pow(double.NegativeInfinity, 1) should be NegativeInfinity");
508 Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.NegativeInfinity, 2)),
509 "Math.Pow(double.NegativeInfinity, 2) should be PositiveInfinity");
511 // MS docs say this should be 0
513 Assert.IsTrue (double.IsNaN (Math.Pow (1, double.NegativeInfinity)));
515 Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, double.NegativeInfinity),
516 "Math.Pow(double.PositiveInfinity, double.NegativeInfinity)");
518 Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.PositiveInfinity, 1)),
519 "Math.Pow(double.PositiveInfinity, 1) should be PositiveInfinity");
521 // MS docs say this should be PositiveInfinity
523 Assert.IsTrue (double.IsNaN (Math.Pow (1, double.PositiveInfinity)),
524 "Math.Pow(1, double.PositiveInfinity) should be NaN");
527 Assert.IsTrue (Double.IsNaN (Math.Pow (1, Double.NaN)),
528 "Math.Pow(1, NaN) should be NaN");
530 Assert.IsTrue (Double.IsNaN (Math.Pow (Double.NaN, 0)),
531 "Math.Pow(NaN, 0) should be NaN");
533 Assert.IsTrue (1.0 == Math.Pow (-1, Double.MaxValue),
534 "Math.Pow(-1, MaxValue) should be 1.0");
537 Assert.IsTrue (1.0 == Math.Pow (-1, Double.MinValue),
538 "Math.Pow(-1, MinValue) should be 1.0");
541 Assert.IsTrue (Double.IsPositiveInfinity (Math.Pow (Double.MinValue,
542 Double.MaxValue)), "Math.Pow(MinValue, MaxValue) should be +Infinity");
545 Assert.IsTrue (0.0 == Math.Pow (Double.MinValue, Double.MinValue),
546 "Math.Pow(MinValue, MinValue) should be 0.0");
549 // The following bugs were present because we tried to outsmart the C Pow:
551 double infinity = Double.PositiveInfinity;
552 Assert.IsTrue (Math.Pow (0.5, infinity) == 0.0,
553 "Math.Pow(0.5, Infinity) == 0.0");
554 Assert.IsTrue (Math.Pow (0.5, -infinity) == infinity,
555 "Math.Pow(0.5, -Infinity) == Infinity");
556 Assert.IsTrue (Math.Pow (2, infinity) == infinity,
557 "Math.Pow(2, Infinity) == Infinity");
558 Assert.IsTrue (Math.Pow (2, -infinity) == 0.0,
559 "Math.Pow(2, -Infinity) == 0");
560 Assert.IsTrue (Math.Pow (infinity, 0) == 1.0,
561 "Math.Pow(Infinity, 0) == 1.0");
562 Assert.IsTrue (Math.Pow (-infinity, 0) == 1.0,
563 "Math.Pow(-Infinity, 0) == 1.0");
564 } catch (Exception e) {
565 Assert.Fail ("Unexpected exception at iTest=" + iTest + ". e=" + e);
570 public void TestByteMax ()
575 Assert.IsTrue (b == Math.Max (a, b), "#1");
576 Assert.IsTrue (b == Math.Max (b, a), "#2");
580 public void TestDecimalMax ()
585 Assert.IsTrue (b == Math.Max (a, b), "#1");
586 Assert.IsTrue (b == Math.Max (b, a), "#2");
590 public void TestDoubleMax ()
595 Assert.IsTrue (b == Math.Max (a, b), "#1");
596 Assert.IsTrue (b == Math.Max (b, a), "#2");
598 Assert.IsTrue (Double.IsNaN (Math.Max (Double.NaN, Double.NaN)), "#3");
599 Assert.IsTrue (Double.IsNaN (Math.Max (Double.NaN, a)), "#4");
600 Assert.IsTrue (Double.IsNaN (Math.Max (b, Double.NaN)), "#5");
604 public void TestFloatMax ()
609 Assert.IsTrue (b == Math.Max (a, b), "#1");
610 Assert.IsTrue (b == Math.Max (b, a), "#2");
611 Assert.IsTrue (Single.IsNaN (Math.Max (Single.NaN, Single.NaN)), "#3");
612 Assert.IsTrue (Single.IsNaN (Math.Max (Single.NaN, a)), "#4");
613 Assert.IsTrue (Single.IsNaN (Math.Max (b, Single.NaN)), "#5");
617 public void TestIntMax ()
624 Assert.AreEqual (b, Math.Max (a, b), "#1");
625 Assert.AreEqual (b, Math.Max (b, a), "#2");
626 Assert.AreEqual (c, Math.Max (c, d), "#3");
627 Assert.AreEqual (c, Math.Max (d, c), "#4");
631 public void TestLongMax ()
636 Assert.IsTrue (b == Math.Max (a, b), "#1");
637 Assert.IsTrue (b == Math.Max (b, a), "#2");
641 public void TestSbyteMax ()
646 Assert.IsTrue (b == Math.Max (a, b), "#1");
647 Assert.IsTrue (b == Math.Max (b, a), "#2");
651 public void TestShortMax ()
656 Assert.IsTrue (b == Math.Max (a, b), "#1");
657 Assert.IsTrue (b == Math.Max (b, a), "#2");
661 public void TestUintMax ()
666 Assert.IsTrue (b == Math.Max (a, b), "#1");
667 Assert.IsTrue (b == Math.Max (b, a), "#2");
671 public void TestUlongMax ()
676 Assert.IsTrue (b == Math.Max (a, b), "#1");
677 Assert.IsTrue (b == Math.Max (b, a), "#2");
681 public void TestUshortMax ()
686 Assert.IsTrue (b == Math.Max (a, b), "#1");
687 Assert.IsTrue (b == Math.Max (b, a), "#2");
691 public void TestByteMin ()
696 Assert.IsTrue (a == Math.Min (a, b), "#1");
697 Assert.IsTrue (a == Math.Min (b, a), "#2");
701 public void TestDecimalMin ()
706 Assert.IsTrue (a == Math.Min (a, b), "#1");
707 Assert.IsTrue (a == Math.Min (b, a), "#2");
711 public void TestDoubleMin ()
716 Assert.IsTrue (a == Math.Min (a, b), "#1");
717 Assert.IsTrue (a == Math.Min (b, a), "#2");
718 Assert.IsTrue (Double.IsNaN (Math.Min (Double.NaN, Double.NaN)), "#3");
719 Assert.IsTrue (Double.IsNaN (Math.Min (Double.NaN, a)), "#4");
720 Assert.IsTrue (Double.IsNaN (Math.Min (b, Double.NaN)), "#5");
724 public void TestFloatMin ()
729 Assert.IsTrue (a == Math.Min (a, b), "#1");
730 Assert.IsTrue (a == Math.Min (b, a), "#2");
731 Assert.IsTrue (Single.IsNaN (Math.Min (Single.NaN, Single.NaN)), "#3");
732 Assert.IsTrue (Single.IsNaN (Math.Min (Single.NaN, a)), "#4");
733 Assert.IsTrue (Single.IsNaN (Math.Min (b, Single.NaN)), "#5");
737 public void TestIntMin ()
742 Assert.IsTrue (a == Math.Min (a, b), "#1");
743 Assert.IsTrue (a == Math.Min (b, a), "#2");
747 public void TestLongMin ()
752 Assert.IsTrue (a == Math.Min (a, b), "#1");
753 Assert.IsTrue (a == Math.Min (b, a), "#2");
757 public void TestSbyteMin ()
762 Assert.IsTrue (a == Math.Min (a, b), "#1");
763 Assert.IsTrue (a == Math.Min (b, a), "#2");
767 public void TestShortMin ()
772 Assert.IsTrue (a == Math.Min (a, b), "#1");
773 Assert.IsTrue (a == Math.Min (b, a), "#2");
777 public void TestUintMin ()
782 Assert.IsTrue (a == Math.Min (a, b), "#1");
783 Assert.IsTrue (a == Math.Min (b, a), "#2");
787 public void TestUlongMin ()
792 Assert.IsTrue (a == Math.Min (a, b), "#1");
793 Assert.IsTrue (a == Math.Min (b, a), "#2");
797 public void TestUshortMin ()
802 Assert.IsTrue (a == Math.Min (a, b), "#1");
803 Assert.IsTrue (a == Math.Min (b, a), "#2");
807 public void TestDecimalRound ()
812 Assert.IsTrue (Math.Round (a) == 2, "#1");
813 Assert.IsTrue (Math.Round (b) == 2, "#2");
814 Assert.IsTrue (Decimal.MaxValue == Math.Round (Decimal.MaxValue), "#3");
815 Assert.IsTrue (Decimal.MinValue == Math.Round (Decimal.MinValue), "#4");
819 public void TestDecimalRound2 ()
824 Assert.AreEqual (3.4M, Math.Round (a, 1), "#1");
825 Assert.AreEqual (3.5M, Math.Round (b, 1), "#2");
829 public void TestDoubleRound ()
834 Assert.AreEqual (2D, Math.Round (a), "#1");
835 Assert.AreEqual (2D, Math.Round (b), "#2");
836 Assert.IsTrue (Double.MaxValue == Math.Round (Double.MaxValue), "#3");
837 Assert.IsTrue (Double.MinValue == Math.Round (Double.MinValue), "#4");
841 public void TestDoubleTruncate ()
847 Assert.AreEqual (1D, Math.Truncate (a), "#1");
848 Assert.AreEqual (2D, Math.Truncate (b), "#2");
850 Assert.AreEqual (-1D, Math.Truncate (a * -1D), "#3");
851 Assert.AreEqual (-2D, Math.Truncate (b * -1D), "#4");
853 Assert.AreEqual (0D, Math.Truncate (c), "#5");
855 Assert.IsTrue (Double.MaxValue == Math.Truncate (Double.MaxValue), "#6");
856 Assert.IsTrue (Double.MinValue == Math.Truncate (Double.MinValue), "#7");
860 public void TestDecimalTruncate ()
866 Assert.AreEqual (1M, Math.Truncate (a), "#1");
867 Assert.AreEqual (2M, Math.Truncate (b), "#2");
869 Assert.AreEqual (-1M, Math.Truncate (a * -1M), "#3");
870 Assert.AreEqual (-2M, Math.Truncate (b * -1M), "#4");
872 Assert.AreEqual (0M, Math.Truncate (c), "#5");
874 Assert.IsTrue (Decimal.MaxValue == Math.Truncate (Decimal.MaxValue), "#6");
875 Assert.IsTrue (Decimal.MinValue == Math.Truncate (Decimal.MinValue), "#7");
879 public void TestDoubleRound2 ()
884 Assert.AreEqual (3.4D, Math.Round (a, 1), "#1");
885 Assert.AreEqual (3.5D, Math.Round (b, 1), "#2");
886 Assert.AreEqual (-0.1, Math.Round (-0.123456789, 1), "#3");
890 public void TestDoubleRound3 ()
892 Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.ToEven), "#1");
893 Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.AwayFromZero), "#2");
895 Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.ToEven), "#3");
896 Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.AwayFromZero), "#4");
898 Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.ToEven), "#5");
899 Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.AwayFromZero), "#6");
901 Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.ToEven), "#7");
902 Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.AwayFromZero), "#8");
904 Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.ToEven), "#9");
905 Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.AwayFromZero), "#A");
907 Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.ToEven), "#B");
908 Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.AwayFromZero), "#C");
910 Assert.AreEqual (1.2D, Math.Round (1.2345D, 1, MidpointRounding.ToEven), "#D");
911 Assert.AreEqual (1.2D, Math.Round (1.2345D, 1, MidpointRounding.AwayFromZero), "#E");
913 Assert.AreEqual (-1.2D, Math.Round (-1.2345D, 1, MidpointRounding.ToEven), "#F");
914 Assert.AreEqual (-1.2D, Math.Round (-1.2345D, 1, MidpointRounding.AwayFromZero), "#10");
916 Assert.AreEqual (1.23D, Math.Round (1.2345D, 2, MidpointRounding.ToEven), "#11");
917 Assert.AreEqual (1.23D, Math.Round (1.2345D, 2, MidpointRounding.AwayFromZero), "#12");
919 Assert.AreEqual (-1.23D, Math.Round (-1.2345D, 2, MidpointRounding.ToEven), "#13");
920 Assert.AreEqual (-1.23D, Math.Round (-1.2345D, 2, MidpointRounding.AwayFromZero), "#14");
922 Assert.AreEqual (1.234D, Math.Round (1.2345D, 3, MidpointRounding.ToEven), "#15");
923 Assert.AreEqual (1.235D, Math.Round (1.2345D, 3, MidpointRounding.AwayFromZero), "#16");
925 Assert.AreEqual (-1.234D, Math.Round (-1.2345D, 3, MidpointRounding.ToEven), "#17");
926 Assert.AreEqual (-1.235D, Math.Round (-1.2345D, 3, MidpointRounding.AwayFromZero), "#18");
928 Assert.AreEqual (1.2345D, Math.Round (1.2345D, 4, MidpointRounding.ToEven), "#19");
929 Assert.AreEqual (1.2345D, Math.Round (1.2345D, 4, MidpointRounding.AwayFromZero), "#1A");
931 Assert.AreEqual (-1.2345D, Math.Round (-1.2345D, 4, MidpointRounding.ToEven), "#1B");
932 Assert.AreEqual (-1.2345D, Math.Round (-1.2345D, 4, MidpointRounding.AwayFromZero), "#1C");
934 Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.ToEven), "#1D");
935 Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.AwayFromZero), "#1E");
937 Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.ToEven), "#1F");
938 Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.AwayFromZero), "#20");
940 Assert.AreEqual (1.5D, Math.Round (1.5432D, 1, MidpointRounding.ToEven), "#21");
941 Assert.AreEqual (1.5D, Math.Round (1.5432D, 1, MidpointRounding.AwayFromZero), "#22");
943 Assert.AreEqual (-1.5D, Math.Round (-1.5432D, 1, MidpointRounding.ToEven), "#23");
944 Assert.AreEqual (-1.5D, Math.Round (-1.5432D, 1, MidpointRounding.AwayFromZero), "#24");
946 Assert.AreEqual (1.54D, Math.Round (1.5432D, 2, MidpointRounding.ToEven), "#25");
947 Assert.AreEqual (1.54D, Math.Round (1.5432D, 2, MidpointRounding.AwayFromZero), "#26");
949 Assert.AreEqual (-1.54D, Math.Round (-1.5432D, 2, MidpointRounding.ToEven), "#27");
950 Assert.AreEqual (-1.54D, Math.Round (-1.5432D, 2, MidpointRounding.AwayFromZero), "#28");
952 Assert.AreEqual (1.543D, Math.Round (1.5432D, 3, MidpointRounding.ToEven), "#29");
953 Assert.AreEqual (1.543D, Math.Round (1.5432D, 3, MidpointRounding.AwayFromZero), "#2A");
955 Assert.AreEqual (-1.543D, Math.Round (-1.5432D, 3, MidpointRounding.ToEven), "#2B");
956 Assert.AreEqual (-1.543D, Math.Round (-1.5432D, 3, MidpointRounding.AwayFromZero), "#2C");
958 Assert.AreEqual (1.5432D, Math.Round (1.5432D, 4, MidpointRounding.ToEven), "#2D");
959 Assert.AreEqual (1.5432D, Math.Round (1.5432D, 4, MidpointRounding.AwayFromZero), "#2E");
961 Assert.AreEqual (-1.5432D, Math.Round (-1.5432D, 4, MidpointRounding.ToEven), "#2F");
962 Assert.AreEqual (-1.5432D, Math.Round (-1.5432D, 4, MidpointRounding.AwayFromZero), "#30");
964 Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.ToEven), "#31");
965 Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.AwayFromZero), "#32");
967 Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.ToEven), "#33");
968 Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.AwayFromZero), "#34");
970 Assert.AreEqual (63987.83594D, Math.Round (63987.83593942D, 5, MidpointRounding.ToEven), "#35");
971 Assert.AreEqual (63987.83594D, Math.Round (63987.83593942D, 5, MidpointRounding.AwayFromZero), "#36");
973 Assert.AreEqual (-63987.83594D, Math.Round (-63987.83593942D, 5, MidpointRounding.ToEven), "#37");
974 Assert.AreEqual (-63987.83594D, Math.Round (-63987.83593942D, 5, MidpointRounding.AwayFromZero), "#38");
976 Assert.AreEqual (63987.83593942D, Math.Round (63987.83593942D, 8, MidpointRounding.ToEven), "#39");
977 Assert.AreEqual (63987.83593942D, Math.Round (63987.83593942D, 8, MidpointRounding.AwayFromZero), "#3A");
979 Assert.AreEqual (-63987.83593942D, Math.Round (-63987.83593942D, 8, MidpointRounding.ToEven), "#3B");
980 Assert.AreEqual (-63987.83593942D, Math.Round (-63987.83593942D, 8, MidpointRounding.AwayFromZero), "#3C");
982 Assert.AreEqual (1, Math.Round (0.5, 0, MidpointRounding.AwayFromZero));
986 public void TestDecimalSign ()
991 Assert.IsTrue (Math.Sign (a) == -1, "#1");
992 Assert.IsTrue (Math.Sign (b) == 1, "#2");
993 Assert.IsTrue (Math.Sign (0M) == 0, "#3");
997 public void TestDoubleSign ()
1002 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1003 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1004 Assert.IsTrue (Math.Sign (0D) == 0, "#3");
1008 public void TestFloatSign ()
1013 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1014 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1015 Assert.IsTrue (Math.Sign (0F) == 0, "#3");
1019 public void TestIntSign ()
1024 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1025 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1026 Assert.IsTrue (Math.Sign (0) == 0, "#3");
1030 public void TestLongSign ()
1035 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1036 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1037 Assert.IsTrue (Math.Sign (0L) == 0, "#3");
1041 public void TestSbyteSign ()
1046 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1047 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1048 Assert.IsTrue (Math.Sign (0) == 0, "#3");
1052 public void TestShortSign ()
1057 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1058 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1059 Assert.IsTrue (Math.Sign (0) == 0, "#3");