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 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)));
151 public void TestAsin ()
153 double a = Math.Asin (x);
154 double b = 0.12371534584255098;
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)));
167 public void TestAtan ()
169 double a = Math.Atan (x);
170 double b = 0.12277930094473837;
171 double c = 1.5707963267948966;
172 double d = -1.5707963267948966;
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"));
184 public void TestAtan2 ()
186 double a = Math.Atan2 (x, y);
187 double b = 0.0099956168687207747;
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)));
195 // The following test is for methods that are in ECMA but they are
196 // not implemented in MS.NET. I leave them commented.
198 public void TestBigMul () {
199 int a = int.MaxValue;
200 int b = int.MaxValue;
202 Assert(((long)a * (long)b) == Math.BigMul(a,b));
207 public void TestCos ()
209 double a = Math.Cos (x);
210 double b = 0.99239587670489104;
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)));
220 public void TestCosh ()
222 double a = Math.Cosh (x);
223 double b = 1.0076234465130722;
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)));
232 // The following test is for methods that are in ECMA but they are
233 // not implemented in MS.NET. I leave them commented.
235 public void TestIntDivRem () {
238 int div = 0, rem = 0;
240 div = Math.DivRem (a, b, out rem);
242 Assert.IsTrue (rem == 1);
243 Assert.IsTrue (div == 2);
246 public void TestLongDivRem () {
249 long div = 0, rem = 0;
251 div = Math.DivRem (a, b, out rem);
253 Assert.IsTrue (rem == 1);
254 Assert.IsTrue (div == 2);
259 public void TestSin ()
261 double a = Math.Sin (x);
262 double b = 0.12308705821137626;
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)));
272 public void TestSinh ()
274 double a = Math.Sinh (x);
275 double b = 0.12371341868561381;
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)));
285 public void TestTan ()
287 double a = Math.Tan (x);
288 double b = 0.12403019913793806;
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)));
298 public void TestTanh ()
300 double a = Math.Tanh (x);
301 double b = 0.12277743150353424;
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");
314 public void TestSqrt ()
316 double a = Math.Sqrt (x);
317 double b = 0.35128336140500593;
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)));
327 public void TestExp ()
329 double a = Math.Exp (x);
330 double b = 1.1313368651986859;
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);
340 public void TestCeiling ()
344 double a = Math.Ceiling (1.5);
348 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
349 + " != " + b.ToString ("G99"));
351 Assert.IsTrue (Math.Ceiling (double.NegativeInfinity) == double.NegativeInfinity);
353 Assert.IsTrue (Math.Ceiling (double.PositiveInfinity) == double.PositiveInfinity);
355 Assert.IsTrue (double.IsNaN (Math.Ceiling (double.NaN)));
358 Assert.IsTrue (Double.MaxValue == Math.Ceiling (Double.MaxValue));
361 Assert.IsTrue (Double.MinValue == Math.Ceiling (Double.MinValue));
362 } catch (Exception e) {
363 Assert.Fail ("Unexpected Exception at iTest=" + iTest + ": " + e);
369 public void TestDecimalCeiling()
371 decimal a = Math.Ceiling(1.5M);
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");
381 public void TestFloor ()
383 double a = Math.Floor (1.5);
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)));
392 Assert.IsTrue (Double.MaxValue == Math.Floor (Double.MaxValue));
394 Assert.IsTrue (Double.MinValue == Math.Floor (Double.MinValue));
398 public void TestIEEERemainder ()
400 double a = Math.IEEERemainder (y, x);
401 double b = 0.0050000000000007816;
403 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
404 + " != " + b.ToString ("G99"));
406 Assert.IsTrue (double.IsNaN (Math.IEEERemainder (y, 0)), "Positive 0");
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");
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");
418 public void TestLog ()
420 double a = Math.Log (y);
421 double b = 2.513251122797143;
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)));
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);
434 public void TestLog2 ()
436 double a = Math.Log (x, y);
437 double b = -0.83251695325303621;
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)));
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);
456 public void TestLog10 ()
458 double a = Math.Log10 (x);
459 double b = -0.90868484030277719;
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)));
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);
473 public void TestPow ()
478 double a = Math.Pow (y, x);
479 double b = 1.363609446060212;
481 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99") + " != " + b.ToString ("G99"));
483 Assert.IsTrue (double.IsNaN (Math.Pow (y, double.NaN)));
485 Assert.IsTrue (double.IsNaN (Math.Pow (double.NaN, x)));
487 Assert.IsTrue (double.IsNegativeInfinity (Math.Pow (double.NegativeInfinity, 1)),
488 "Math.Pow(double.NegativeInfinity, 1) should be NegativeInfinity");
490 Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.NegativeInfinity, 2)),
491 "Math.Pow(double.NegativeInfinity, 2) should be PositiveInfinity");
493 // MS docs say this should be 0
495 Assert.IsTrue (double.IsNaN (Math.Pow (1, double.NegativeInfinity)));
497 Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, double.NegativeInfinity),
498 "Math.Pow(double.PositiveInfinity, double.NegativeInfinity)");
500 Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.PositiveInfinity, 1)),
501 "Math.Pow(double.PositiveInfinity, 1) should be PositiveInfinity");
503 // MS docs say this should be PositiveInfinity
505 Assert.IsTrue (double.IsNaN (Math.Pow (1, double.PositiveInfinity)),
506 "Math.Pow(1, double.PositiveInfinity) should be NaN");
509 Assert.IsTrue (Double.IsNaN (Math.Pow (1, Double.NaN)),
510 "Math.Pow(1, NaN) should be NaN");
513 Assert.IsTrue (Double.IsNaN (Math.Pow (Double.NaN, 0)),
514 "Math.Pow(NaN, 0) should be NaN");
517 Assert.IsTrue (1.0 == Math.Pow (-1, Double.MaxValue),
518 "Math.Pow(-1, MaxValue) should be 1.0");
521 Assert.IsTrue (1.0 == Math.Pow (-1, Double.MinValue),
522 "Math.Pow(-1, MinValue) should be 1.0");
525 Assert.IsTrue (Double.IsPositiveInfinity (Math.Pow (Double.MinValue,
526 Double.MaxValue)), "Math.Pow(MinValue, MaxValue) should be +Infinity");
529 Assert.IsTrue (0.0 == Math.Pow (Double.MinValue, Double.MinValue),
530 "Math.Pow(MinValue, MinValue) should be 0.0");
533 // The following bugs were present because we tried to outsmart the C Pow:
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);
554 public void TestByteMax ()
559 Assert.IsTrue (b == Math.Max (a, b), "#1");
560 Assert.IsTrue (b == Math.Max (b, a), "#2");
564 public void TestDecimalMax ()
569 Assert.IsTrue (b == Math.Max (a, b), "#1");
570 Assert.IsTrue (b == Math.Max (b, a), "#2");
574 public void TestDoubleMax ()
579 Assert.IsTrue (b == Math.Max (a, b), "#1");
580 Assert.IsTrue (b == Math.Max (b, a), "#2");
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");
588 public void TestFloatMax ()
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");
601 public void TestIntMax ()
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");
615 public void TestLongMax ()
620 Assert.IsTrue (b == Math.Max (a, b), "#1");
621 Assert.IsTrue (b == Math.Max (b, a), "#2");
625 public void TestSbyteMax ()
630 Assert.IsTrue (b == Math.Max (a, b), "#1");
631 Assert.IsTrue (b == Math.Max (b, a), "#2");
635 public void TestShortMax ()
640 Assert.IsTrue (b == Math.Max (a, b), "#1");
641 Assert.IsTrue (b == Math.Max (b, a), "#2");
645 public void TestUintMax ()
650 Assert.IsTrue (b == Math.Max (a, b), "#1");
651 Assert.IsTrue (b == Math.Max (b, a), "#2");
655 public void TestUlongMax ()
660 Assert.IsTrue (b == Math.Max (a, b), "#1");
661 Assert.IsTrue (b == Math.Max (b, a), "#2");
665 public void TestUshortMax ()
670 Assert.IsTrue (b == Math.Max (a, b), "#1");
671 Assert.IsTrue (b == Math.Max (b, a), "#2");
675 public void TestByteMin ()
680 Assert.IsTrue (a == Math.Min (a, b), "#1");
681 Assert.IsTrue (a == Math.Min (b, a), "#2");
685 public void TestDecimalMin ()
690 Assert.IsTrue (a == Math.Min (a, b), "#1");
691 Assert.IsTrue (a == Math.Min (b, a), "#2");
695 public void TestDoubleMin ()
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");
708 public void TestFloatMin ()
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");
721 public void TestIntMin ()
726 Assert.IsTrue (a == Math.Min (a, b), "#1");
727 Assert.IsTrue (a == Math.Min (b, a), "#2");
731 public void TestLongMin ()
736 Assert.IsTrue (a == Math.Min (a, b), "#1");
737 Assert.IsTrue (a == Math.Min (b, a), "#2");
741 public void TestSbyteMin ()
746 Assert.IsTrue (a == Math.Min (a, b), "#1");
747 Assert.IsTrue (a == Math.Min (b, a), "#2");
751 public void TestShortMin ()
756 Assert.IsTrue (a == Math.Min (a, b), "#1");
757 Assert.IsTrue (a == Math.Min (b, a), "#2");
761 public void TestUintMin ()
766 Assert.IsTrue (a == Math.Min (a, b), "#1");
767 Assert.IsTrue (a == Math.Min (b, a), "#2");
771 public void TestUlongMin ()
776 Assert.IsTrue (a == Math.Min (a, b), "#1");
777 Assert.IsTrue (a == Math.Min (b, a), "#2");
781 public void TestUshortMin ()
786 Assert.IsTrue (a == Math.Min (a, b), "#1");
787 Assert.IsTrue (a == Math.Min (b, a), "#2");
791 public void TestDecimalRound ()
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");
803 public void TestDecimalRound2 ()
808 Assert.AreEqual (3.4M, Math.Round (a, 1), "#1");
809 Assert.AreEqual (3.5M, Math.Round (b, 1), "#2");
813 public void TestDoubleRound ()
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");
826 public void TestDoubleTruncate ()
832 Assert.AreEqual (1D, Math.Truncate (a), "#1");
833 Assert.AreEqual (2D, Math.Truncate (b), "#2");
835 Assert.AreEqual (-1D, Math.Truncate (a * -1D), "#3");
836 Assert.AreEqual (-2D, Math.Truncate (b * -1D), "#4");
838 Assert.AreEqual (0D, Math.Truncate (c), "#5");
840 Assert.IsTrue (Double.MaxValue == Math.Truncate (Double.MaxValue), "#6");
841 Assert.IsTrue (Double.MinValue == Math.Truncate (Double.MinValue), "#7");
845 public void TestDecimalTruncate ()
851 Assert.AreEqual (1M, Math.Truncate (a), "#1");
852 Assert.AreEqual (2M, Math.Truncate (b), "#2");
854 Assert.AreEqual (-1M, Math.Truncate (a * -1M), "#3");
855 Assert.AreEqual (-2M, Math.Truncate (b * -1M), "#4");
857 Assert.AreEqual (0M, Math.Truncate (c), "#5");
859 Assert.IsTrue (Decimal.MaxValue == Math.Truncate (Decimal.MaxValue), "#6");
860 Assert.IsTrue (Decimal.MinValue == Math.Truncate (Decimal.MinValue), "#7");
865 public void TestDoubleRound2 ()
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");
877 public void TestDoubleRound3 ()
879 Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.ToEven), "#1");
880 Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.AwayFromZero), "#2");
882 Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.ToEven), "#3");
883 Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.AwayFromZero), "#4");
885 Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.ToEven), "#5");
886 Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.AwayFromZero), "#6");
888 Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.ToEven), "#7");
889 Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.AwayFromZero), "#8");
891 Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.ToEven), "#9");
892 Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.AwayFromZero), "#A");
894 Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.ToEven), "#B");
895 Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.AwayFromZero), "#C");
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");
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");
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");
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");
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");
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");
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");
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");
921 Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.ToEven), "#1D");
922 Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.AwayFromZero), "#1E");
924 Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.ToEven), "#1F");
925 Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.AwayFromZero), "#20");
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");
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");
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");
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");
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");
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");
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");
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");
951 Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.ToEven), "#31");
952 Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.AwayFromZero), "#32");
954 Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.ToEven), "#33");
955 Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.AwayFromZero), "#34");
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");
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");
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");
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");
969 Assert.AreEqual (1, Math.Round (0.5, 0, MidpointRounding.AwayFromZero));
974 public void TestDecimalSign ()
979 Assert.IsTrue (Math.Sign (a) == -1, "#1");
980 Assert.IsTrue (Math.Sign (b) == 1, "#2");
981 Assert.IsTrue (Math.Sign (0M) == 0, "#3");
985 public void TestDoubleSign ()
990 Assert.IsTrue (Math.Sign (a) == -1, "#1");
991 Assert.IsTrue (Math.Sign (b) == 1, "#2");
992 Assert.IsTrue (Math.Sign (0D) == 0, "#3");
996 public void TestFloatSign ()
1001 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1002 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1003 Assert.IsTrue (Math.Sign (0F) == 0, "#3");
1007 public void TestIntSign ()
1012 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1013 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1014 Assert.IsTrue (Math.Sign (0) == 0, "#3");
1018 public void TestLongSign ()
1023 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1024 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1025 Assert.IsTrue (Math.Sign (0L) == 0, "#3");
1029 public void TestSbyteSign ()
1034 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1035 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1036 Assert.IsTrue (Math.Sign (0) == 0, "#3");
1040 public void TestShortSign ()
1045 Assert.IsTrue (Math.Sign (a) == -1, "#1");
1046 Assert.IsTrue (Math.Sign (b) == 1, "#2");
1047 Assert.IsTrue (Math.Sign (0) == 0, "#3");