1 // MathTest.cs 2 // 3 // Jon Guymon (guymon@slackworks.com) 4 // Pedro Martínez Juliá (yoros@wanadoo.es) 5 // 6 // (C) 2002 Jon Guymon 7 // Copyright (C) 2003 Pedro Martínez Juliá <yoros@wanadoo.es> 8 // Copyright (C) 2004 Novell (http://www.novell.com) 9 // 10 11 using System; 12 using NUnit.Framework; 13 14 namespace MonoTests.System 15 { 16 [TestFixture] 17 public class MathTest 18 { 19 private static double double_epsilon = 2.2204460492503131e-16; /* DBL_EPSILON = 2^-52 */ 20 21 static double x = 0.1234; 22 static double y = 12.345; 23 24 [Test] TestDecimalAbs()25 public void TestDecimalAbs () 26 { 27 decimal a = -9.0M; 28 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"); 35 } 36 37 [Test] TestDoubleAbs()38 public void TestDoubleAbs () 39 { 40 double a = -9.0D; 41 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"); 49 } 50 51 [Test] TestFloatAbs()52 public void TestFloatAbs () 53 { 54 float a = -9.0F; 55 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"); 63 } 64 65 [Test] TestLongAbs()66 public void TestLongAbs () 67 { 68 long a = -9L; 69 long b = Int64.MinValue; 70 71 Assert.IsTrue (9L == Math.Abs (a), "#1"); 72 try { 73 Math.Abs (b); 74 Assert.Fail ("#2"); 75 } catch (Exception e) { 76 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3"); 77 } 78 Assert.IsTrue (Int64.MaxValue == Math.Abs (Int64.MaxValue), "#4"); 79 } 80 81 [Test] TestIntAbs()82 public void TestIntAbs () 83 { 84 int a = -9; 85 int b = Int32.MinValue; 86 87 Assert.IsTrue (9 == Math.Abs (a), "#1"); 88 try { 89 Math.Abs (b); 90 Assert.Fail ("#2"); 91 } catch (Exception e) { 92 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3"); 93 } 94 Assert.IsTrue (Int32.MaxValue == Math.Abs (Int32.MaxValue), "#4"); 95 } 96 97 [Test] TestSbyteAbs()98 public void TestSbyteAbs () 99 { 100 sbyte a = -9; 101 sbyte b = SByte.MinValue; 102 103 Assert.IsTrue (9 == Math.Abs (a), "#1"); 104 try { 105 Math.Abs (b); 106 Assert.Fail ("#2"); 107 } catch (Exception e) { 108 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3"); 109 } 110 Assert.IsTrue (SByte.MaxValue == Math.Abs (SByte.MaxValue), "#4"); 111 } 112 113 [Test] TestShortAbs()114 public void TestShortAbs () 115 { 116 short a = -9; 117 short b = Int16.MinValue; 118 119 Assert.IsTrue (9 == Math.Abs (a), "#1"); 120 try { 121 Math.Abs (b); 122 Assert.Fail ("#2"); 123 } catch (Exception e) { 124 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#3"); 125 } 126 Assert.IsTrue (Int16.MaxValue == Math.Abs (Int16.MaxValue), "#4"); 127 } 128 129 [Test] TestAcos()130 public void TestAcos () 131 { 132 double a = Math.Acos (x); 133 double b = 1.4470809809523457; 134 135 bool regularTest = (Math.Abs (a - b) <= double_epsilon); 136 if (!regularTest){ 137 // 138 // On MacOS X libc acos (0.1234) returns 139 // 1.4470809809523455 (hex 0x3ff7273e62fda9ab) instead 140 // of 1.4470809809523457 (hex 0x3ff7273e62fda9ac) 141 // 142 // For now, let it go 143 // 144 if (a == 1.4470809809523455) 145 regularTest = true; 146 } 147 148 Assert.IsTrue (regularTest, a.ToString ("G99") + " != " + b.ToString ("G99")); 149 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))); 156 } 157 158 [Test] TestAsin()159 public void TestAsin () 160 { 161 double a = Math.Asin (x); 162 double b = 0.12371534584255098; 163 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))); 172 } 173 174 [Test] TestAtan()175 public void TestAtan () 176 { 177 double a = Math.Atan (x); 178 double b = 0.12277930094473837; 179 double c = 1.5707963267948966; 180 double d = -1.5707963267948966; 181 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")); 189 } 190 191 [Test] TestAtan2()192 public void TestAtan2 () 193 { 194 double a = Math.Atan2 (x, y); 195 double b = 0.0099956168687207747; 196 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))); 201 } 202 203 // The following test is for methods that are in ECMA but they are 204 // not implemented in MS.NET. I leave them commented. 205 /* 206 public void TestBigMul () { 207 int a = int.MaxValue; 208 int b = int.MaxValue; 209 210 Assert(((long)a * (long)b) == Math.BigMul(a,b)); 211 } 212 */ 213 214 [Test] TestCos()215 public void TestCos () 216 { 217 double a = Math.Cos (x); 218 double b = 0.99239587670489104; 219 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))); 225 } 226 227 [Test] TestCosh()228 public void TestCosh () 229 { 230 double a = Math.Cosh (x); 231 double b = 1.0076234465130722; 232 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))); 238 } 239 240 // The following test is for methods that are in ECMA but they are 241 // not implemented in MS.NET. I leave them commented. 242 /* 243 public void TestIntDivRem () { 244 int a = 5; 245 int b = 2; 246 int div = 0, rem = 0; 247 248 div = Math.DivRem (a, b, out rem); 249 250 Assert.IsTrue (rem == 1); 251 Assert.IsTrue (div == 2); 252 } 253 254 public void TestLongDivRem () { 255 long a = 5; 256 long b = 2; 257 long div = 0, rem = 0; 258 259 div = Math.DivRem (a, b, out rem); 260 261 Assert.IsTrue (rem == 1); 262 Assert.IsTrue (div == 2); 263 } 264 */ 265 266 [Test] TestSin()267 public void TestSin () 268 { 269 double a = Math.Sin (x); 270 double b = 0.12308705821137626; 271 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))); 277 } 278 279 [Test] TestSinh()280 public void TestSinh () 281 { 282 double a = Math.Sinh (x); 283 double b = 0.12371341868561381; 284 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))); 290 } 291 292 [Test] TestTan()293 public void TestTan () 294 { 295 double a = Math.Tan (x); 296 double b = 0.12403019913793806; 297 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))); 303 } 304 305 [Test] TestTanh()306 public void TestTanh () 307 { 308 double a = Math.Tanh (x); 309 double b = 0.12277743150353424; 310 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"); 319 } 320 321 [Test] TestSqrt()322 public void TestSqrt () 323 { 324 double a = Math.Sqrt (x); 325 double b = 0.35128336140500593; 326 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))); 332 } 333 334 [Test] TestExp()335 public void TestExp () 336 { 337 double a = Math.Exp (x); 338 double b = 1.1313368651986859; 339 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); 345 } 346 347 [Test] TestCeiling()348 public void TestCeiling () 349 { 350 int iTest = 1; 351 try { 352 double a = Math.Ceiling (1.5); 353 double b = 2; 354 355 iTest++; 356 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99") 357 + " != " + b.ToString ("G99")); 358 iTest++; 359 Assert.IsTrue (Math.Ceiling (double.NegativeInfinity) == double.NegativeInfinity); 360 iTest++; 361 Assert.IsTrue (Math.Ceiling (double.PositiveInfinity) == double.PositiveInfinity); 362 iTest++; 363 Assert.IsTrue (double.IsNaN (Math.Ceiling (double.NaN))); 364 365 iTest++; 366 Assert.IsTrue (Double.MaxValue == Math.Ceiling (Double.MaxValue)); 367 368 iTest++; 369 Assert.IsTrue (Double.MinValue == Math.Ceiling (Double.MinValue)); 370 } catch (Exception e) { 371 Assert.Fail ("Unexpected Exception at iTest=" + iTest + ": " + e); 372 } 373 } 374 375 [Test] TestDecimalCeiling()376 public void TestDecimalCeiling() 377 { 378 decimal a = Math.Ceiling(1.5M); 379 decimal b = 2M; 380 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"); 384 } 385 386 [Test] TestFloor()387 public void TestFloor () 388 { 389 double a = Math.Floor (1.5); 390 double b = 1; 391 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))); 397 398 Assert.IsTrue (Double.MaxValue == Math.Floor (Double.MaxValue)); 399 400 Assert.IsTrue (Double.MinValue == Math.Floor (Double.MinValue)); 401 } 402 403 [Test] TestIEEERemainder()404 public void TestIEEERemainder () 405 { 406 double a = Math.IEEERemainder (y, x); 407 double b = 0.0050000000000010592; 408 409 Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99") 410 + " != " + b.ToString ("G99")); 411 412 Assert.IsTrue (double.IsNaN (Math.IEEERemainder (y, 0)), "Positive 0"); 413 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"); 417 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"); 421 } 422 423 [Test] TestLog()424 public void TestLog () 425 { 426 double a = Math.Log (y); 427 double b = 2.513251122797143; 428 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))); 433 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); 437 } 438 439 [Test] TestLog2()440 public void TestLog2 () 441 { 442 double a = Math.Log (x, y); 443 double b = -0.83251695325303621; 444 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))); 454 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); 458 459 Assert.IsTrue (Double.IsNaN (Math.Log (x, double.PositiveInfinity))); 460 } 461 462 [Test] TestLog10()463 public void TestLog10 () 464 { 465 double a = Math.Log10 (x); 466 double b = -0.90868484030277719; 467 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))); 472 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); 476 477 } 478 479 [Test] TestPow()480 public void TestPow () 481 { 482 double precision; 483 #if MONODROID 484 // It fails on Nexus 9 with 485 // 486 // 1.3636094460602122 != 1.3636094460602119 487 // 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; 491 #else 492 precision = double_epsilon; 493 #endif 494 495 /* documentation cases : https://msdn.microsoft.com/en-us/library/system.math.pow%28v=vs.110%29.aspx */ 496 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"); 513 514 /* x = Any value except NaN; y = 0 -> 1 */ 515 Assert.AreEqual ((double) 1, Math.Pow (2, 0), "#15"); 516 517 /* x = NegativeInfinity; y < 0 -> 0 */ 518 Assert.AreEqual ((double) 0, Math.Pow (double.NegativeInfinity, -2), "#16"); 519 520 /* x = NegativeInfinity; y is a positive odd integer -> NegativeInfinity */ 521 Assert.AreEqual (double.NegativeInfinity, Math.Pow (double.NegativeInfinity, 3), "#17"); 522 523 /* x = NegativeInfinity; y is positive but not an odd integer -> PositiveInfinity */ 524 Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.NegativeInfinity, 2), "#18"); 525 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"); 528 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"); 532 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"); 536 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"); 540 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"); 544 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"); 548 549 /* x = 0; y < 0 -> PositiveInfinity */ 550 Assert.AreEqual (double.PositiveInfinity, Math.Pow (0, -2), "#30"); 551 552 /* x = 0; y > 0 -> PositiveInfinity */ 553 Assert.AreEqual ((double) 0, Math.Pow (0, +2), "#31"); 554 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"); 561 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"); 565 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"); 569 570 /* other cases */ 571 572 double a = Math.Pow (y, x); 573 double b = 1.363609446060212; 574 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"); 578 579 Assert.AreEqual (Math.Pow (double.PositiveInfinity, double.NegativeInfinity), (double) 0, "#44"); 580 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"); 585 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"); 593 } 594 595 [Test] TestByteMax()596 public void TestByteMax () 597 { 598 byte a = 1; 599 byte b = 2; 600 601 Assert.IsTrue (b == Math.Max (a, b), "#1"); 602 Assert.IsTrue (b == Math.Max (b, a), "#2"); 603 } 604 605 [Test] TestDecimalMax()606 public void TestDecimalMax () 607 { 608 decimal a = 1.5M; 609 decimal b = 2.5M; 610 611 Assert.IsTrue (b == Math.Max (a, b), "#1"); 612 Assert.IsTrue (b == Math.Max (b, a), "#2"); 613 } 614 615 [Test] TestDoubleMax()616 public void TestDoubleMax () 617 { 618 double a = 1.5D; 619 double b = 2.5D; 620 621 Assert.IsTrue (b == Math.Max (a, b), "#1"); 622 Assert.IsTrue (b == Math.Max (b, a), "#2"); 623 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"); 627 } 628 629 [Test] TestFloatMax()630 public void TestFloatMax () 631 { 632 float a = 1.5F; 633 float b = 2.5F; 634 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"); 640 } 641 642 [Test] TestIntMax()643 public void TestIntMax () 644 { 645 int a = 1; 646 int b = 2; 647 int c = 100; 648 int d = -2147483647; 649 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"); 654 } 655 656 [Test] TestLongMax()657 public void TestLongMax () 658 { 659 long a = 1L; 660 long b = 2L; 661 662 Assert.IsTrue (b == Math.Max (a, b), "#1"); 663 Assert.IsTrue (b == Math.Max (b, a), "#2"); 664 } 665 666 [Test] TestSbyteMax()667 public void TestSbyteMax () 668 { 669 sbyte a = 1; 670 sbyte b = 2; 671 672 Assert.IsTrue (b == Math.Max (a, b), "#1"); 673 Assert.IsTrue (b == Math.Max (b, a), "#2"); 674 } 675 676 [Test] TestShortMax()677 public void TestShortMax () 678 { 679 short a = 1; 680 short b = 2; 681 682 Assert.IsTrue (b == Math.Max (a, b), "#1"); 683 Assert.IsTrue (b == Math.Max (b, a), "#2"); 684 } 685 686 [Test] TestUintMax()687 public void TestUintMax () 688 { 689 uint a = 1U; 690 uint b = 2U; 691 692 Assert.IsTrue (b == Math.Max (a, b), "#1"); 693 Assert.IsTrue (b == Math.Max (b, a), "#2"); 694 } 695 696 [Test] TestUlongMax()697 public void TestUlongMax () 698 { 699 ulong a = 1UL; 700 ulong b = 2UL; 701 702 Assert.IsTrue (b == Math.Max (a, b), "#1"); 703 Assert.IsTrue (b == Math.Max (b, a), "#2"); 704 } 705 706 [Test] TestUshortMax()707 public void TestUshortMax () 708 { 709 ushort a = 1; 710 ushort b = 2; 711 712 Assert.IsTrue (b == Math.Max (a, b), "#1"); 713 Assert.IsTrue (b == Math.Max (b, a), "#2"); 714 } 715 716 [Test] TestByteMin()717 public void TestByteMin () 718 { 719 byte a = 1; 720 byte b = 2; 721 722 Assert.IsTrue (a == Math.Min (a, b), "#1"); 723 Assert.IsTrue (a == Math.Min (b, a), "#2"); 724 } 725 726 [Test] TestDecimalMin()727 public void TestDecimalMin () 728 { 729 decimal a = 1.5M; 730 decimal b = 2.5M; 731 732 Assert.IsTrue (a == Math.Min (a, b), "#1"); 733 Assert.IsTrue (a == Math.Min (b, a), "#2"); 734 } 735 736 [Test] TestDoubleMin()737 public void TestDoubleMin () 738 { 739 double a = 1.5D; 740 double b = 2.5D; 741 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"); 747 } 748 749 [Test] TestFloatMin()750 public void TestFloatMin () 751 { 752 float a = 1.5F; 753 float b = 2.5F; 754 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"); 760 } 761 762 [Test] TestIntMin()763 public void TestIntMin () 764 { 765 int a = 1; 766 int b = 2; 767 768 Assert.IsTrue (a == Math.Min (a, b), "#1"); 769 Assert.IsTrue (a == Math.Min (b, a), "#2"); 770 } 771 772 [Test] TestLongMin()773 public void TestLongMin () 774 { 775 long a = 1L; 776 long b = 2L; 777 778 Assert.IsTrue (a == Math.Min (a, b), "#1"); 779 Assert.IsTrue (a == Math.Min (b, a), "#2"); 780 } 781 782 [Test] TestSbyteMin()783 public void TestSbyteMin () 784 { 785 sbyte a = 1; 786 sbyte b = 2; 787 788 Assert.IsTrue (a == Math.Min (a, b), "#1"); 789 Assert.IsTrue (a == Math.Min (b, a), "#2"); 790 } 791 792 [Test] TestShortMin()793 public void TestShortMin () 794 { 795 short a = 1; 796 short b = 2; 797 798 Assert.IsTrue (a == Math.Min (a, b), "#1"); 799 Assert.IsTrue (a == Math.Min (b, a), "#2"); 800 } 801 802 [Test] TestUintMin()803 public void TestUintMin () 804 { 805 uint a = 1U; 806 uint b = 2U; 807 808 Assert.IsTrue (a == Math.Min (a, b), "#1"); 809 Assert.IsTrue (a == Math.Min (b, a), "#2"); 810 } 811 812 [Test] TestUlongMin()813 public void TestUlongMin () 814 { 815 ulong a = 1UL; 816 ulong b = 2UL; 817 818 Assert.IsTrue (a == Math.Min (a, b), "#1"); 819 Assert.IsTrue (a == Math.Min (b, a), "#2"); 820 } 821 822 [Test] TestUshortMin()823 public void TestUshortMin () 824 { 825 ushort a = 1; 826 ushort b = 2; 827 828 Assert.IsTrue (a == Math.Min (a, b), "#1"); 829 Assert.IsTrue (a == Math.Min (b, a), "#2"); 830 } 831 832 [Test] TestDecimalRound()833 public void TestDecimalRound () 834 { 835 decimal a = 1.5M; 836 decimal b = 2.5M; 837 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"); 842 } 843 844 [Test] TestDecimalRound2()845 public void TestDecimalRound2 () 846 { 847 decimal a = 3.45M; 848 decimal b = 3.46M; 849 850 Assert.AreEqual (3.4M, Math.Round (a, 1), "#1"); 851 Assert.AreEqual (3.5M, Math.Round (b, 1), "#2"); 852 } 853 854 [Test] TestDoubleRound()855 public void TestDoubleRound () 856 { 857 double a = 1.5D; 858 double b = 2.5D; 859 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"); 864 } 865 866 [Test] TestDoubleTruncate()867 public void TestDoubleTruncate () 868 { 869 double a = 1.2D; 870 double b = 2.8D; 871 double c = 0D; 872 873 Assert.AreEqual (1D, Math.Truncate (a), "#1"); 874 Assert.AreEqual (2D, Math.Truncate (b), "#2"); 875 876 Assert.AreEqual (-1D, Math.Truncate (a * -1D), "#3"); 877 Assert.AreEqual (-2D, Math.Truncate (b * -1D), "#4"); 878 879 Assert.AreEqual (0D, Math.Truncate (c), "#5"); 880 881 Assert.IsTrue (Double.MaxValue == Math.Truncate (Double.MaxValue), "#6"); 882 Assert.IsTrue (Double.MinValue == Math.Truncate (Double.MinValue), "#7"); 883 } 884 885 [Test] TestDecimalTruncate()886 public void TestDecimalTruncate () 887 { 888 decimal a = 1.2M; 889 decimal b = 2.8M; 890 decimal c = 0M; 891 892 Assert.AreEqual (1M, Math.Truncate (a), "#1"); 893 Assert.AreEqual (2M, Math.Truncate (b), "#2"); 894 895 Assert.AreEqual (-1M, Math.Truncate (a * -1M), "#3"); 896 Assert.AreEqual (-2M, Math.Truncate (b * -1M), "#4"); 897 898 Assert.AreEqual (0M, Math.Truncate (c), "#5"); 899 900 Assert.IsTrue (Decimal.MaxValue == Math.Truncate (Decimal.MaxValue), "#6"); 901 Assert.IsTrue (Decimal.MinValue == Math.Truncate (Decimal.MinValue), "#7"); 902 } 903 904 [Test] TestDoubleRound2()905 public void TestDoubleRound2 () 906 { 907 double a = 3.45D; 908 double b = 3.46D; 909 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"); 913 } 914 915 [Test] TestDoubleRound3()916 public void TestDoubleRound3 () 917 { 918 Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.ToEven), "#1"); 919 Assert.AreEqual (1D, Math.Round (1D, 0, MidpointRounding.AwayFromZero), "#2"); 920 921 Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.ToEven), "#3"); 922 Assert.AreEqual (-1D, Math.Round (-1D, 0, MidpointRounding.AwayFromZero), "#4"); 923 924 Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.ToEven), "#5"); 925 Assert.AreEqual (1D, Math.Round (1D, 1, MidpointRounding.AwayFromZero), "#6"); 926 927 Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.ToEven), "#7"); 928 Assert.AreEqual (-1D, Math.Round (-1D, 1, MidpointRounding.AwayFromZero), "#8"); 929 930 Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.ToEven), "#9"); 931 Assert.AreEqual (1D, Math.Round (1.2345D, 0, MidpointRounding.AwayFromZero), "#A"); 932 933 Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.ToEven), "#B"); 934 Assert.AreEqual (-1D, Math.Round (-1.2345D, 0, MidpointRounding.AwayFromZero), "#C"); 935 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"); 938 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"); 941 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"); 944 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"); 947 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"); 950 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"); 953 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"); 956 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"); 959 960 Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.ToEven), "#1D"); 961 Assert.AreEqual (2D, Math.Round (1.5432D, 0, MidpointRounding.AwayFromZero), "#1E"); 962 963 Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.ToEven), "#1F"); 964 Assert.AreEqual (-2D, Math.Round (-1.5432D, 0, MidpointRounding.AwayFromZero), "#20"); 965 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"); 968 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"); 971 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"); 974 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"); 977 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"); 980 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"); 983 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"); 986 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"); 989 990 Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.ToEven), "#31"); 991 Assert.AreEqual (63988D, Math.Round (63987.83593942D, 0, MidpointRounding.AwayFromZero), "#32"); 992 993 Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.ToEven), "#33"); 994 Assert.AreEqual (-63988D, Math.Round (-63987.83593942D, 0, MidpointRounding.AwayFromZero), "#34"); 995 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"); 998 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"); 1001 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"); 1004 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"); 1007 1008 Assert.AreEqual (1, Math.Round (0.5, 0, MidpointRounding.AwayFromZero)); 1009 } 1010 1011 [Test] TestDecimalSign()1012 public void TestDecimalSign () 1013 { 1014 decimal a = -5M; 1015 decimal b = 5M; 1016 1017 Assert.IsTrue (Math.Sign (a) == -1, "#1"); 1018 Assert.IsTrue (Math.Sign (b) == 1, "#2"); 1019 Assert.IsTrue (Math.Sign (0M) == 0, "#3"); 1020 } 1021 1022 [Test] TestDoubleSign()1023 public void TestDoubleSign () 1024 { 1025 double a = -5D; 1026 double b = 5D; 1027 1028 Assert.IsTrue (Math.Sign (a) == -1, "#1"); 1029 Assert.IsTrue (Math.Sign (b) == 1, "#2"); 1030 Assert.IsTrue (Math.Sign (0D) == 0, "#3"); 1031 } 1032 1033 [Test] TestFloatSign()1034 public void TestFloatSign () 1035 { 1036 float a = -5F; 1037 float b = 5F; 1038 1039 Assert.IsTrue (Math.Sign (a) == -1, "#1"); 1040 Assert.IsTrue (Math.Sign (b) == 1, "#2"); 1041 Assert.IsTrue (Math.Sign (0F) == 0, "#3"); 1042 } 1043 1044 [Test] TestIntSign()1045 public void TestIntSign () 1046 { 1047 int a = -5; 1048 int b = 5; 1049 1050 Assert.IsTrue (Math.Sign (a) == -1, "#1"); 1051 Assert.IsTrue (Math.Sign (b) == 1, "#2"); 1052 Assert.IsTrue (Math.Sign (0) == 0, "#3"); 1053 } 1054 1055 [Test] TestLongSign()1056 public void TestLongSign () 1057 { 1058 long a = -5L; 1059 long b = 5L; 1060 1061 Assert.IsTrue (Math.Sign (a) == -1, "#1"); 1062 Assert.IsTrue (Math.Sign (b) == 1, "#2"); 1063 Assert.IsTrue (Math.Sign (0L) == 0, "#3"); 1064 } 1065 1066 [Test] TestSbyteSign()1067 public void TestSbyteSign () 1068 { 1069 sbyte a = -5; 1070 sbyte b = 5; 1071 1072 Assert.IsTrue (Math.Sign (a) == -1, "#1"); 1073 Assert.IsTrue (Math.Sign (b) == 1, "#2"); 1074 Assert.IsTrue (Math.Sign (0) == 0, "#3"); 1075 } 1076 1077 [Test] TestShortSign()1078 public void TestShortSign () 1079 { 1080 short a = -5; 1081 short b = 5; 1082 1083 Assert.IsTrue (Math.Sign (a) == -1, "#1"); 1084 Assert.IsTrue (Math.Sign (b) == 1, "#2"); 1085 Assert.IsTrue (Math.Sign (0) == 0, "#3"); 1086 } 1087 } 1088 } 1089