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 =
26 static double x = 0.1234;
27 static double y = 12.345;
30 public void TestDecimalAbs ()
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");
43 public void TestDoubleAbs ()
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");
57 public void TestFloatAbs ()
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");
71 public void TestLongAbs ()
74 long b = Int64.MinValue;
76 Assert.IsTrue (9L == Math.Abs (a), "#1");
80 } catch (Exception e) {
81 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
83 Assert.IsTrue (Int64.MaxValue == Math.Abs (Int64.MaxValue), "#4");
87 public void TestIntAbs ()
90 int b = Int32.MinValue;
92 Assert.IsTrue (9 == Math.Abs (a), "#1");
96 } catch (Exception e) {
97 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
99 Assert.IsTrue (Int32.MaxValue == Math.Abs (Int32.MaxValue), "#4");
103 public void TestSbyteAbs ()
106 sbyte b = SByte.MinValue;
108 Assert.IsTrue (9 == Math.Abs (a), "#1");
112 } catch (Exception e) {
113 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
115 Assert.IsTrue (SByte.MaxValue == Math.Abs (SByte.MaxValue), "#4");
119 public void TestShortAbs ()
122 short b = Int16.MinValue;
124 Assert.IsTrue (9 == Math.Abs (a), "#1");
128 } catch (Exception e) {
129 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3");
131 Assert.IsTrue (Int16.MaxValue == Math.Abs (Int16.MaxValue), "#4");
135 public void TestAcos ()
137 double a = Math.Acos (x);
138 double b = 1.4470809809523457;
140 bool regularTest = (Math.Abs (a - b) <= double_epsilon);
143 // On MacOS X libc acos (0.1234) returns
144 // 1.4470809809523455 (hex 0x3ff7273e62fda9ab) instead
145 // of 1.4470809809523457 (hex 0x3ff7273e62fda9ac)
147 // For now, let it go
149 if (a == 1.4470809809523455)
153 Assert.IsTrue (regularTest, a.ToString ("G99") + " != " + b.ToString ("G99"));
155 Assert.IsTrue (double.IsNaN (Math.Acos (-1.01D)));
156 Assert.IsTrue (double.IsNaN (Math.Acos (1.01D)));
157 Assert.IsTrue (double.IsNaN (Math.Acos (Double.MinValue)));
158 Assert.IsTrue (double.IsNaN (Math.Acos (Double.MaxValue)));
159 Assert.IsTrue (double.IsNaN (Math.Acos (Double.NegativeInfinity)));
160 Assert.IsTrue (double.IsNaN (Math.Acos (Double.PositiveInfinity)));
164 public void TestAsin ()
166 double a = Math.Asin (x);
167 double b = 0.12371534584255098;
169 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
170 + " != " + b.ToString ("G99"));
171 Assert.IsTrue (double.IsNaN (Math.Asin (-1.01D)));
172 Assert.IsTrue (double.IsNaN (Math.Asin (1.01D)));
173 Assert.IsTrue (double.IsNaN (Math.Asin (Double.MinValue)));
174 Assert.IsTrue (double.IsNaN (Math.Asin (Double.MaxValue)));
175 Assert.IsTrue (double.IsNaN (Math.Asin (Double.NegativeInfinity)));
176 Assert.IsTrue (double.IsNaN (Math.Asin (Double.PositiveInfinity)));
180 public void TestAtan ()
182 double a = Math.Atan (x);
183 double b = 0.12277930094473837;
184 double c = 1.5707963267948966;
185 double d = -1.5707963267948966;
187 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), "#1: " + a.ToString ("G99")
188 + " != " + b.ToString ("G99"));
189 Assert.IsTrue (double.IsNaN (Math.Atan (double.NaN)), "should return NaN");
190 Assert.IsTrue (Math.Abs ((double) Math.Atan (double.PositiveInfinity) - c) <= 0.0000000000000001,
191 "#2: " + Math.Atan (double.PositiveInfinity).ToString ("G99") + " != " + c.ToString ("G99"));
192 Assert.IsTrue (Math.Abs ((double) Math.Atan (double.NegativeInfinity) - d) <= 0.0000000000000001,
193 "#3: " + Math.Atan (double.NegativeInfinity).ToString ("G99") + " != " + d.ToString ("G99"));
197 public void TestAtan2 ()
199 double a = Math.Atan2 (x, y);
200 double b = 0.0099956168687207747;
202 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
203 + " != " + b.ToString ("G99"));
204 Assert.IsTrue (double.IsNaN (Math.Acos (-2D)));
205 Assert.IsTrue (double.IsNaN (Math.Acos (2D)));
208 // The following test is for methods that are in ECMA but they are
209 // not implemented in MS.NET. I leave them commented.
211 public void TestBigMul () {
212 int a = int.MaxValue;
213 int b = int.MaxValue;
215 Assert(((long)a * (long)b) == Math.BigMul(a,b));
220 public void TestCos ()
222 double a = Math.Cos (x);
223 double b = 0.99239587670489104;
225 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
226 + " != " + b.ToString ("G99"));
227 Assert.IsTrue (double.IsNaN (Math.Cos (Double.NaN)));
228 Assert.IsTrue (double.IsNaN (Math.Cos (Double.NegativeInfinity)));
229 Assert.IsTrue (double.IsNaN (Math.Cos (Double.PositiveInfinity)));
233 public void TestCosh ()
235 double a = Math.Cosh (x);
236 double b = 1.0076234465130722;
238 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
239 + " != " + b.ToString ("G99"));
240 Assert.IsTrue (Math.Cosh (double.NegativeInfinity) == double.PositiveInfinity);
241 Assert.IsTrue (Math.Cosh (double.PositiveInfinity) == double.PositiveInfinity);
242 Assert.IsTrue (double.IsNaN (Math.Cosh (double.NaN)));
245 // The following test is for methods that are in ECMA but they are
246 // not implemented in MS.NET. I leave them commented.
248 public void TestIntDivRem () {
251 int div = 0, rem = 0;
253 div = Math.DivRem (a, b, out rem);
255 Assert.IsTrue (rem == 1);
256 Assert.IsTrue (div == 2);
259 public void TestLongDivRem () {
262 long div = 0, rem = 0;
264 div = Math.DivRem (a, b, out rem);
266 Assert.IsTrue (rem == 1);
267 Assert.IsTrue (div == 2);
272 public void TestSin ()
274 double a = Math.Sin (x);
275 double b = 0.12308705821137626;
277 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
278 + " != " + b.ToString ("G99"));
279 Assert.IsTrue (double.IsNaN (Math.Sin (Double.NaN)));
280 Assert.IsTrue (double.IsNaN (Math.Sin (Double.NegativeInfinity)));
281 Assert.IsTrue (double.IsNaN (Math.Sin (Double.PositiveInfinity)));
285 public void TestSinh ()
287 double a = Math.Sinh (x);
288 double b = 0.12371341868561381;
290 Assert.IsTrue (Math.Abs (a - b) <= 0.0000000000000001, a.ToString ("G99")
291 + " != " + b.ToString ("G99"));
292 Assert.IsTrue (double.IsNaN (Math.Sinh (Double.NaN)));
293 Assert.IsTrue (double.IsNegativeInfinity (Math.Sinh (Double.NegativeInfinity)));
294 Assert.IsTrue (double.IsPositiveInfinity (Math.Sinh (Double.PositiveInfinity)));
298 public void TestTan ()
300 double a = Math.Tan (x);
301 double b = 0.12403019913793806;
303 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
304 + " != " + b.ToString ("G99"));
305 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.NaN)));
306 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.PositiveInfinity)));
307 Assert.IsTrue (Double.IsNaN (Math.Tan (Double.NegativeInfinity)));
311 public void TestTanh ()
313 double a = Math.Tanh (x);
314 double b = 0.12277743150353424;
316 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
317 + " != " + b.ToString ("G99"));
318 Assert.IsTrue (Double.IsNaN (Math.Tanh (Double.NaN)),
319 "Tanh(NaN) should be NaN");
320 Assert.IsTrue (1 == Math.Tanh (Double.PositiveInfinity),
321 "Tanh(+Infinity) should be 1");
322 Assert.IsTrue (-1 == Math.Tanh (Double.NegativeInfinity),
323 "Tanh(-Infinity) should be -1");
327 public void TestSqrt ()
329 double a = Math.Sqrt (x);
330 double b = 0.35128336140500593;
332 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
333 + " != " + b.ToString ("G99"));
334 Assert.IsTrue (Double.IsNaN (Math.Sqrt (Double.NaN)));
335 Assert.IsTrue (Double.IsPositiveInfinity (Math.Sqrt (Double.PositiveInfinity)));
336 Assert.IsTrue (Double.IsNaN (Math.Sqrt (Double.NegativeInfinity)));
340 public void TestExp ()
342 double a = Math.Exp (x);
343 double b = 1.1313368651986859;
345 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
346 + " != " + b.ToString ("G99"));
347 Assert.IsTrue (double.IsNaN (Math.Exp (double.NaN)));
348 Assert.IsTrue (Math.Exp (double.NegativeInfinity) == 0);
349 Assert.IsTrue (Math.Exp (double.PositiveInfinity) == double.PositiveInfinity);
353 public void TestCeiling ()
357 double a = Math.Ceiling (1.5);
361 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
362 + " != " + b.ToString ("G99"));
364 Assert.IsTrue (Math.Ceiling (double.NegativeInfinity) == double.NegativeInfinity);
366 Assert.IsTrue (Math.Ceiling (double.PositiveInfinity) == double.PositiveInfinity);
368 Assert.IsTrue (double.IsNaN (Math.Ceiling (double.NaN)));
371 Assert.IsTrue (Double.MaxValue == Math.Ceiling (Double.MaxValue));
374 Assert.IsTrue (Double.MinValue == Math.Ceiling (Double.MinValue));
375 } catch (Exception e) {
376 Assert.Fail ("Unexpected Exception at iTest=" + iTest + ": " + e);
382 public void TestDecimalCeiling()
384 decimal a = Math.Ceiling(1.5M);
387 Assert.IsTrue (a == b, "#1");
388 Assert.IsTrue (Decimal.MaxValue == Math.Ceiling(Decimal.MaxValue), "#2");
389 Assert.IsTrue (Decimal.MinValue == Math.Ceiling(Decimal.MinValue), "#3");
394 public void TestFloor ()
396 double a = Math.Floor (1.5);
399 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
400 + " != " + b.ToString ("G99"));
401 Assert.IsTrue (Math.Floor (double.NegativeInfinity) == double.NegativeInfinity);
402 Assert.IsTrue (Math.Floor (double.PositiveInfinity) == double.PositiveInfinity);
403 Assert.IsTrue (double.IsNaN (Math.Floor (double.NaN)));
405 Assert.IsTrue (Double.MaxValue == Math.Floor (Double.MaxValue));
407 Assert.IsTrue (Double.MinValue == Math.Floor (Double.MinValue));
411 public void TestIEEERemainder ()
413 double a = Math.IEEERemainder (y, x);
414 double b = 0.0050000000000007816;
416 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
417 + " != " + b.ToString ("G99"));
419 Assert.IsTrue (double.IsNaN (Math.IEEERemainder (y, 0)), "Positive 0");
421 // http://www.obtuse.com/resources/negative_zero.html
422 double n0 = BitConverter.Int64BitsToDouble (Int64.MinValue);
423 Assert.IsTrue (double.IsNaN (Math.IEEERemainder (n0, 0)), "Negative 0");
425 // the "zero" remainder of negative number is negative
426 long result = BitConverter.DoubleToInt64Bits (Math.IEEERemainder (-1, 1));
427 Assert.AreEqual (Int64.MinValue, result, "Negative Dividend");
431 public void TestLog ()
433 double a = Math.Log (y);
434 double b = 2.513251122797143;
436 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
437 + " != " + b.ToString ("G99"));
438 Assert.IsTrue (double.IsNaN (Math.Log (-1)));
439 Assert.IsTrue (double.IsNaN (Math.Log (double.NaN)));
441 // MS docs say this should be PositiveInfinity
442 Assert.IsTrue (Math.Log (0) == double.NegativeInfinity);
443 Assert.IsTrue (Math.Log (double.PositiveInfinity) == double.PositiveInfinity);
447 public void TestLog2 ()
449 double a = Math.Log (x, y);
450 double b = -0.83251695325303621;
452 Assert.IsTrue ((Math.Abs (a - b) <= 1e-14), a + " != " + b
453 + " because diff is " + Math.Abs (a - b));
454 Assert.IsTrue (double.IsNaN (Math.Log (-1, y)));
455 Assert.IsTrue (double.IsNaN (Math.Log (double.NaN, y)));
456 Assert.IsTrue (double.IsNaN (Math.Log (x, double.NaN)));
457 Assert.IsTrue (double.IsNaN (Math.Log (double.NegativeInfinity, y)));
458 Assert.IsTrue (double.IsNaN (Math.Log (x, double.NegativeInfinity)));
459 Assert.IsTrue (double.IsNaN (Math.Log (double.PositiveInfinity, double.PositiveInfinity)));
460 Assert.IsTrue (double.IsNaN (Math.Log (2, 1)));
462 // MS docs say this should be PositiveInfinity
463 Assert.IsTrue (Math.Log (0, y) == double.NegativeInfinity);
464 Assert.IsTrue (Math.Log (double.PositiveInfinity, y) == double.PositiveInfinity);
465 Assert.IsTrue (Math.Log (x, double.PositiveInfinity) == 0);
469 public void TestLog10 ()
471 double a = Math.Log10 (x);
472 double b = -0.90868484030277719;
474 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
475 + " != " + b.ToString ("G99"));
476 Assert.IsTrue (double.IsNaN (Math.Log10 (-1)));
477 Assert.IsTrue (double.IsNaN (Math.Log10 (double.NaN)));
479 // MS docs say this should be PositiveInfinity
480 Assert.IsTrue (Math.Log10 (0) == double.NegativeInfinity);
481 Assert.IsTrue (Math.Log10 (double.PositiveInfinity) == double.PositiveInfinity);
486 public void TestPow ()
491 double a = Math.Pow (y, x);
492 double b = 1.363609446060212;
494 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99") + " != " + b.ToString ("G99"));
496 Assert.IsTrue (double.IsNaN (Math.Pow (y, double.NaN)));
498 Assert.IsTrue (double.IsNaN (Math.Pow (double.NaN, x)));
500 Assert.IsTrue (double.IsNegativeInfinity (Math.Pow (double.NegativeInfinity, 1)),
501 "Math.Pow(double.NegativeInfinity, 1) should be NegativeInfinity");
503 Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.NegativeInfinity, 2)),
504 "Math.Pow(double.NegativeInfinity, 2) should be PositiveInfinity");
506 // MS docs say this should be 0
508 Assert.IsTrue (double.IsNaN (Math.Pow (1, double.NegativeInfinity)));
510 Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, double.NegativeInfinity),
511 "Math.Pow(double.PositiveInfinity, double.NegativeInfinity)");
513 Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.PositiveInfinity, 1)),
514 "Math.Pow(double.PositiveInfinity, 1) should be PositiveInfinity");
516 // MS docs say this should be PositiveInfinity
518 Assert.IsTrue (double.IsNaN (Math.Pow (1, double.PositiveInfinity)),
519 "Math.Pow(1, double.PositiveInfinity) should be NaN");
522 Assert.IsTrue (Double.IsNaN (Math.Pow (1, Double.NaN)),
523 "Math.Pow(1, NaN) should be NaN");
526 Assert.IsTrue (Double.IsNaN (Math.Pow (Double.NaN, 0)),
527 "Math.Pow(NaN, 0) should be NaN");
530 Assert.IsTrue (1.0 == Math.Pow (-1, Double.MaxValue),
531 "Math.Pow(-1, MaxValue) should be 1.0");
534 Assert.IsTrue (1.0 == Math.Pow (-1, Double.MinValue),
535 "Math.Pow(-1, MinValue) should be 1.0");
538 Assert.IsTrue (Double.IsPositiveInfinity (Math.Pow (Double.MinValue,
539 Double.MaxValue)), "Math.Pow(MinValue, MaxValue) should be +Infinity");
542 Assert.IsTrue (0.0 == Math.Pow (Double.MinValue, Double.MinValue),
543 "Math.Pow(MinValue, MinValue) should be 0.0");
546 // The following bugs were present because we tried to outsmart the C Pow:
548 double infinity = Double.PositiveInfinity;
549 Assert.IsTrue (Math.Pow (0.5, infinity) == 0.0,
550 "Math.Pow(0.5, Infinity) == 0.0");
551 Assert.IsTrue (Math.Pow (0.5, -infinity) == infinity,
552 "Math.Pow(0.5, -Infinity) == Infinity");
553 Assert.IsTrue (Math.Pow (2, infinity) == infinity,
554 "Math.Pow(2, Infinity) == Infinity");
555 Assert.IsTrue (Math.Pow (2, -infinity) == 0.0,
556 "Math.Pow(2, -Infinity) == 0");
557 Assert.IsTrue (Math.Pow (infinity, 0) == 1.0,
558 "Math.Pow(Infinity, 0) == 1.0");
559 Assert.IsTrue (Math.Pow (-infinity, 0) == 1.0,
560 "Math.Pow(-Infinity, 0) == 1.0");
561 } catch (Exception e) {
562 Assert.Fail ("Unexpected exception at iTest=" + iTest + ". e=" + e);
567 public void TestByteMax ()
572 Assert.IsTrue (b == Math.Max (a, b), "#1");
573 Assert.IsTrue (b == Math.Max (b, a), "#2");
577 public void TestDecimalMax ()
582 Assert.IsTrue (b == Math.Max (a, b), "#1");
583 Assert.IsTrue (b == Math.Max (b, a), "#2");
587 public void TestDoubleMax ()
592 Assert.IsTrue (b == Math.Max (a, b), "#1");
593 Assert.IsTrue (b == Math.Max (b, a), "#2");
595 Assert.IsTrue (Double.IsNaN (Math.Max (Double.NaN, Double.NaN)), "#3");
596 Assert.IsTrue (Double.IsNaN (Math.Max (Double.NaN, a)), "#4");
597 Assert.IsTrue (Double.IsNaN (Math.Max (b, Double.NaN)), "#5");
601 public void TestFloatMax ()
606 Assert.IsTrue (b == Math.Max (a, b), "#1");
607 Assert.IsTrue (b == Math.Max (b, a), "#2");
608 Assert.IsTrue (Single.IsNaN (Math.Max (Single.NaN, Single.NaN)), "#3");
609 Assert.IsTrue (Single.IsNaN (Math.Max (Single.NaN, a)), "#4");
610 Assert.IsTrue (Single.IsNaN (Math.Max (b, Single.NaN)), "#5");
614 public void TestIntMax ()
621 Assert.AreEqual (b, Math.Max (a, b), "#1");
622 Assert.AreEqual (b, Math.Max (b, a), "#2");
623 Assert.AreEqual (c, Math.Max (c, d), "#3");
624 Assert.AreEqual (c, Math.Max (d, c), "#4");
628 public void TestLongMax ()
633 Assert.IsTrue (b == Math.Max (a, b), "#1");
634 Assert.IsTrue (b == Math.Max (b, a), "#2");
638 public void TestSbyteMax ()
643 Assert.IsTrue (b == Math.Max (a, b), "#1");
644 Assert.IsTrue (b == Math.Max (b, a), "#2");
648 public void TestShortMax ()
653 Assert.IsTrue (b == Math.Max (a, b), "#1");
654 Assert.IsTrue (b == Math.Max (b, a), "#2");
658 public void TestUintMax ()
663 Assert.IsTrue (b == Math.Max (a, b), "#1");
664 Assert.IsTrue (b == Math.Max (b, a), "#2");
668 public void TestUlongMax ()
673 Assert.IsTrue (b == Math.Max (a, b), "#1");
674 Assert.IsTrue (b == Math.Max (b, a), "#2");
678 public void TestUshortMax ()
683 Assert.IsTrue (b == Math.Max (a, b), "#1");
684 Assert.IsTrue (b == Math.Max (b, a), "#2");
688 public void TestByteMin ()
693 Assert.IsTrue (a == Math.Min (a, b), "#1");
694 Assert.IsTrue (a == Math.Min (b, a), "#2");
698 public void TestDecimalMin ()
703 Assert.IsTrue (a == Math.Min (a, b), "#1");
704 Assert.IsTrue (a == Math.Min (b, a), "#2");
708 public void TestDoubleMin ()
713 Assert.IsTrue (a == Math.Min (a, b), "#1");
714 Assert.IsTrue (a == Math.Min (b, a), "#2");
715 Assert.IsTrue (Double.IsNaN (Math.Min (Double.NaN, Double.NaN)), "#3");
716 Assert.IsTrue (Double.IsNaN (Math.Min (Double.NaN, a)), "#4");
717 Assert.IsTrue (Double.IsNaN (Math.Min (b, Double.NaN)), "#5");
721 public void TestFloatMin ()
726 Assert.IsTrue (a == Math.Min (a, b), "#1");
727 Assert.IsTrue (a == Math.Min (b, a), "#2");
728 Assert.IsTrue (Single.IsNaN (Math.Min (Single.NaN, Single.NaN)), "#3");
729 Assert.IsTrue (Single.IsNaN (Math.Min (Single.NaN, a)), "#4");
730 Assert.IsTrue (Single.IsNaN (Math.Min (b, Single.NaN)), "#5");
734 public void TestIntMin ()
739 Assert.IsTrue (a == Math.Min (a, b), "#1");
740 Assert.IsTrue (a == Math.Min (b, a), "#2");
744 public void TestLongMin ()
749 Assert.IsTrue (a == Math.Min (a, b), "#1");
750 Assert.IsTrue (a == Math.Min (b, a), "#2");
754 public void TestSbyteMin ()
759 Assert.IsTrue (a == Math.Min (a, b), "#1");
760 Assert.IsTrue (a == Math.Min (b, a), "#2");
764 public void TestShortMin ()
769 Assert.IsTrue (a == Math.Min (a, b), "#1");
770 Assert.IsTrue (a == Math.Min (b, a), "#2");
774 public void TestUintMin ()
779 Assert.IsTrue (a == Math.Min (a, b), "#1");
780 Assert.IsTrue (a == Math.Min (b, a), "#2");
784 public void TestUlongMin ()
789 Assert.IsTrue (a == Math.Min (a, b), "#1");
790 Assert.IsTrue (a == Math.Min (b, a), "#2");
794 public void TestUshortMin ()
799 Assert.IsTrue (a == Math.Min (a, b), "#1");
800 Assert.IsTrue (a == Math.Min (b, a), "#2");
804 public void TestDecimalRound ()
809 Assert.IsTrue (Math.Round (a) == 2, "#1");
810 Assert.IsTrue (Math.Round (b) == 2, "#2");
811 Assert.IsTrue (Decimal.MaxValue == Math.Round (Decimal.MaxValue), "#3");
812 Assert.IsTrue (Decimal.MinValue == Math.Round (Decimal.MinValue), "#4");
816 public void TestDecimalRound2 ()
821 Assert.AreEqual (3.4M, Math.Round (a, 1), "#1");
822 Assert.AreEqual (3.5M, Math.Round (b, 1), "#2");
826 public void TestDoubleRound ()
831 Assert.AreEqual (2D, Math.Round (a), "#1");
832 Assert.AreEqual (2D, Math.Round (b), "#2");
833 Assert.IsTrue (Double.MaxValue == Math.Round (Double.MaxValue), "#3");
834 Assert.IsTrue (Double.MinValue == Math.Round (Double.MinValue), "#4");
839 public void TestDoubleTruncate ()
845 Assert.AreEqual (1D, Math.Truncate (a), "#1");
846 Assert.AreEqual (2D, Math.Truncate (b), "#2");
848 Assert.AreEqual (-1D, Math.Truncate (a * -1D), "#3");
849 Assert.AreEqual (-2D, Math.Truncate (b * -1D), "#4");
851 Assert.AreEqual (0D, Math.Truncate (c), "#5");
853 Assert.IsTrue (Double.MaxValue == Math.Truncate (Double.MaxValue), "#6");
854 Assert.IsTrue (Double.MinValue == Math.Truncate (Double.MinValue), "#7");
858 public void TestDecimalTruncate ()
864 Assert.AreEqual (1M, Math.Truncate (a), "#1");
865 Assert.AreEqual (2M, Math.Truncate (b), "#2");
867 Assert.AreEqual (-1M, Math.Truncate (a * -1M), "#3");
868 Assert.AreEqual (-2M, Math.Truncate (b * -1M), "#4");
870 Assert.AreEqual (0M, Math.Truncate (c), "#5");
872 Assert.IsTrue (Decimal.MaxValue == Math.Truncate (Decimal.MaxValue), "#6");
873 Assert.IsTrue (Decimal.MinValue == Math.Truncate (Decimal.MinValue), "#7");
878 public void TestDoubleRound2 ()
883 Assert.AreEqual (3.4D, Math.Round (a, 1), "#1");
884 Assert.AreEqual (3.5D, Math.Round (b, 1), "#2");
885 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));
987 public void TestDecimalSign ()
992 Assert.IsTrue (Math.Sign (a) == -1, "#1");
993 Assert.IsTrue (Math.Sign (b) == 1, "#2");
994 Assert.IsTrue (Math.Sign (0M) == 0, "#3");
998 public void TestDoubleSign ()
1003 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1004 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1005 Assert.IsTrue (Math.Sign (0D) == 0, "#3");
1009 public void TestFloatSign ()
1014 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1015 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1016 Assert.IsTrue (Math.Sign (0F) == 0, "#3");
1020 public void TestIntSign ()
1025 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1026 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1027 Assert.IsTrue (Math.Sign (0) == 0, "#3");
1031 public void TestLongSign ()
1036 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1037 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1038 Assert.IsTrue (Math.Sign (0L) == 0, "#3");
1042 public void TestSbyteSign ()
1047 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1048 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1049 Assert.IsTrue (Math.Sign (0) == 0, "#3");
1053 public void TestShortSign ()
1058 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1059 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1060 Assert.IsTrue (Math.Sign (0) == 0, "#3");