Example #1
0
        public void PowWorks()
        {
            NumberHelper.AssertDoubleWithEpsilon8(Math.Pow(3, 0.5), 1.7320508075688772);

            NumberHelper.AssertDoubleWithEpsilon8(Math.Pow(3, 2), 9);
            NumberHelper.AssertDoubleWithEpsilon8(Math.Pow(2, 3), 8);
        }
Example #2
0
        public void IEEERemainderWorks()
        {
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(3.1, 4.0), -0.9);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(16.1, 4.0), 0.100000000000001);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(4.0, 16.1), 4.0);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(3.1, 3.2), -0.1);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(3.2, 3.1), 0.1);

            Assert.AreEqual(-1.0, Math.IEEERemainder(3.0, 2.0));
            Assert.AreEqual(0.0, Math.IEEERemainder(4.0, 2.0));
            Assert.AreEqual(1.0, Math.IEEERemainder(10.0, 3.0));
            Assert.AreEqual(-1.0, Math.IEEERemainder(11.0, 3.0));
            Assert.AreEqual(-1.0, Math.IEEERemainder(27.0, 4.0));
            Assert.AreEqual(-2.0, Math.IEEERemainder(28.0, 5.0));
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(17.8, 4.0), 1.8);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(17.8, 4.1), 1.4);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(-16.3, 4.1), 0.0999999999999979);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(17.8, -4.1), 1.4);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(-17.8, -4.1), -1.4);

            // Issue #3899
            NumberHelper.AssertDoubleWithEpsilon8(1, Math.IEEERemainder(-3, 2));
            NumberHelper.AssertDoubleWithEpsilon8(1, Math.IEEERemainder(5, 2));
            NumberHelper.AssertDoubleWithEpsilon8(2, Math.IEEERemainder(2, Double.NegativeInfinity));
            NumberHelper.AssertDoubleWithEpsilon8(-4.3, Math.IEEERemainder(-4.3, Double.NegativeInfinity));
        }
Example #3
0
 public void TestMathLog()
 {
     NumberHelper.AssertDoubleWithEpsilon8(1.09861228866811, Math.Log(3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NegativeInfinity, Math.Log(0.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log(-3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log(double.NaN));
     NumberHelper.AssertDoubleWithEpsilon8(double.PositiveInfinity, Math.Log(double.PositiveInfinity));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log(double.NegativeInfinity));
 }
Example #4
0
 public void TestMathLog10()
 {
     NumberHelper.AssertDoubleWithEpsilon8(0.477121254719662, Math.Log10(3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NegativeInfinity, Math.Log10(0.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log10(-3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log10(double.NaN));
     NumberHelper.AssertDoubleWithEpsilon8(double.PositiveInfinity, Math.Log10(double.PositiveInfinity));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log10(double.NegativeInfinity));
 }
Example #5
0
 public void TestMathLogWithBase()
 {
     NumberHelper.AssertDoubleWithEpsilon8(1.0, Math.Log(3.0, 3.0));
     NumberHelper.AssertDoubleWithEpsilon8(2.40217350273, Math.Log(14, 3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NegativeInfinity, Math.Log(0.0, 3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log(-3.0, 3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log(double.NaN, 3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.PositiveInfinity, Math.Log(double.PositiveInfinity, 3.0));
     NumberHelper.AssertDoubleWithEpsilon8(double.NaN, Math.Log(double.NegativeInfinity, 3.0));
 }
Example #6
0
 public static void TestSqrt()
 {
     NumberHelper.AssertDoubleWithEpsilon8(1.73205080756888, Math.Sqrt(3.0));
     Assert.AreEqual(0.0, Math.Sqrt(0.0));
     Assert.AreEqual(double.NaN, Math.Sqrt(-3.0));
     Assert.AreEqual(double.NaN, Math.Sqrt(double.NaN));
     Assert.AreEqual(double.PositiveInfinity, Math.Sqrt(double.PositiveInfinity));
     Assert.AreEqual(double.NaN, Math.Sqrt(double.NegativeInfinity));
     Assert.AreEqual(3, Math.Sqrt(9u));
     Assert.AreEqual(3, Math.Sqrt(9L));
 }
Example #7
0
        public void PropertiesWork()
        {
            var time = new TimeSpan(15, 10, 20, 5, 14);

            Assert.AreEqual(15, time.Days);
            Assert.AreEqual(10, time.Hours);
            Assert.AreEqual(20, time.Minutes);
            Assert.AreEqual(5, time.Seconds);
            Assert.AreEqual(14, time.Milliseconds);
            NumberHelper.AssertDoubleWithEpsilon8(15.430613587962963d, time.TotalDays);
            NumberHelper.AssertDoubleWithEpsilon8(370.33472611111108d, time.TotalHours);
            NumberHelper.AssertDoubleWithEpsilon8(22220.083566666668d, time.TotalMinutes);
            NumberHelper.AssertDoubleWithEpsilon8(1333205.014d, time.TotalSeconds);
            NumberHelper.AssertDoubleWithEpsilon8(1333205014.0d, time.TotalMilliseconds);
            Assert.AreEqual(15 * TimeSpan.TicksPerDay + 10 * TimeSpan.TicksPerHour + 20 * TimeSpan.TicksPerMinute + 5 * TimeSpan.TicksPerSecond + 14 * TimeSpan.TicksPerMillisecond, time.Ticks);
        }
Example #8
0
        public void IEEERemainderWorks()
        {
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(3.1, 4.0), -0.9);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(16.1, 4.0), 0.100000000000001);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(4.0, 16.1), 4.0);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(3.1, 3.2), -0.1);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(3.2, 3.1), 0.1);

            Assert.AreEqual(-1.0, Math.IEEERemainder(3.0, 2.0));
            Assert.AreEqual(0.0, Math.IEEERemainder(4.0, 2.0));
            Assert.AreEqual(1.0, Math.IEEERemainder(10.0, 3.0));
            Assert.AreEqual(-1.0, Math.IEEERemainder(11.0, 3.0));
            Assert.AreEqual(-1.0, Math.IEEERemainder(27.0, 4.0));
            Assert.AreEqual(-2.0, Math.IEEERemainder(28.0, 5.0));
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(17.8, 4.0), 1.8);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(17.8, 4.1), 1.4);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(-16.3, 4.1), 0.0999999999999979);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(17.8, -4.1), 1.4);
            NumberHelper.AssertDoubleWithEpsilon8(Math.IEEERemainder(-17.8, -4.1), -1.4);
        }
Example #9
0
        public static void TestIEEERemainder()
        {
            // Originally as drawn by Vladimir, descriptions added by Fabricio
            Assert.AreEqual(-1, Math.Round(Math.IEEERemainder(3, 2), 1), "Math.IEEERemainder(3, 2) == -1");
            Assert.AreEqual(0, Math.Round(Math.IEEERemainder(4, 2), 1), "Math.IEEERemainder(4, 2) == 0");
            Assert.AreEqual(1, Math.Round(Math.IEEERemainder(10, 3), 1), "Math.IEEERemainder(10, 3) == 1");
            Assert.AreEqual(-1, Math.Round(Math.IEEERemainder(11, 3), 1), "Math.IEEERemainder(11, 3) == -1");
            Assert.AreEqual(-1, Math.Round(Math.IEEERemainder(27, 4), 1), "Math.IEEERemainder(27, 4) == -1");
            Assert.AreEqual(-2, Math.Round(Math.IEEERemainder(28, 5), 1), "Math.IEEERemainder(28, 5) == -2");
            Assert.AreEqual(1.8, Math.Round(Math.IEEERemainder(17.8, 4), 1), "Math.IEEERemainder(17.8, 4) == 1.8");
            Assert.AreEqual(1.4, Math.Round(Math.IEEERemainder(17.8, 4.1), 1), "Math.IEEERemainder(17.8, 4.1) == 1.4");
            Assert.AreEqual(0.1, Math.Round(Math.IEEERemainder(-16.3, 4.1), 1), "Math.IEEERemainder(-16.3, 4.1) == 0.1");
            Assert.AreEqual(1.4, Math.Round(Math.IEEERemainder(17.8, -4.1), 1), "Math.IEEERemainder(17.8, -4.1) == 1.4");
            Assert.AreEqual(-1.4, Math.Round(Math.IEEERemainder(-17.8, -4.1), 1), "Math.IEEERemainder(-17.8, -4.1) == -1.4");
            Assert.AreEqual(1, Math.Round(Math.IEEERemainder(-3, 2), 1), "Math.IEEERemainder(-3, 2) == 1");
            Assert.AreEqual(1, Math.Round(Math.IEEERemainder(5, 2), 1), "Math.IEEERemainder(5, 2) == 1");
            Assert.AreEqual(2, Math.Round(Math.IEEERemainder(2, Double.NegativeInfinity), 1), "Math.IEEERemainder(2, Double.NegativeInfinity) == 2");
            Assert.AreEqual(-4.3, Math.Round(Math.IEEERemainder(-4.3, Double.NegativeInfinity), 1), "Math.IEEERemainder(-4.3, Double.NegativeInfinity) == -4.3");

            // Tests in Batch1.Math.IEEERemainderWorks()
            NumberHelper.AssertDoubleWithEpsilon8(-1, Math.Round(Math.IEEERemainder(3, 2), 1));
            NumberHelper.AssertDoubleWithEpsilon8(0, Math.Round(Math.IEEERemainder(4, 2), 1));
            NumberHelper.AssertDoubleWithEpsilon8(1, Math.Round(Math.IEEERemainder(10, 3), 1));
            NumberHelper.AssertDoubleWithEpsilon8(-1, Math.Round(Math.IEEERemainder(11, 3), 1));
            NumberHelper.AssertDoubleWithEpsilon8(-1, Math.Round(Math.IEEERemainder(27, 4), 1));
            NumberHelper.AssertDoubleWithEpsilon8(-2, Math.Round(Math.IEEERemainder(28, 5), 1));
            NumberHelper.AssertDoubleWithEpsilon8(1.8, Math.Round(Math.IEEERemainder(17.8, 4), 1));
            NumberHelper.AssertDoubleWithEpsilon8(1.4, Math.Round(Math.IEEERemainder(17.8, 4.1), 1));
            NumberHelper.AssertDoubleWithEpsilon8(0.1, Math.Round(Math.IEEERemainder(-16.3, 4.1), 1));
            NumberHelper.AssertDoubleWithEpsilon8(1.4, Math.Round(Math.IEEERemainder(17.8, -4.1), 1));
            NumberHelper.AssertDoubleWithEpsilon8(-1.4, Math.Round(Math.IEEERemainder(-17.8, -4.1), 1));
            NumberHelper.AssertDoubleWithEpsilon8(1, Math.Round(Math.IEEERemainder(-3, 2), 1));
            NumberHelper.AssertDoubleWithEpsilon8(1, Math.Round(Math.IEEERemainder(5, 2), 1));
            NumberHelper.AssertDoubleWithEpsilon8(2, Math.Round(Math.IEEERemainder(2, Double.NegativeInfinity), 1));
            NumberHelper.AssertDoubleWithEpsilon8(-4.3, Math.Round(Math.IEEERemainder(-4.3, Double.NegativeInfinity), 1));
        }
Example #10
0
 public void LogWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Log(0.5), -0.6931471805599453);
 }
Example #11
0
 public void Atan2Works()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Atan2(1, 2), 0.4636476090008061);
 }
Example #12
0
 public void CosWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Cos(0.5), 0.8775825618903728);
 }
Example #13
0
 public void SqrtWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Sqrt((double)3m), 1.73205080756888);
 }
Example #14
0
 public void TanWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Tan(0.5), 0.5463024898437905);
 }
Example #15
0
 public void SinWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Sin(0.5), 0.479425538604203);
 }
Example #16
0
 public void AsinWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Asin(0.5), 0.5235987755982989);
 }
Example #17
0
 public void CoshWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Cosh(0.1), 1.0050041680558035E+000);
 }
Example #18
0
 public void AcosWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Acos(0.5), 1.0471975511965979);
 }
Example #19
0
 public void SinhWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Sinh(-0.98343), -1.1497925156481d);
 }
Example #20
0
 public void ConstantsWork_N2473()
 {
     NumberHelper.AssertDoubleWithEpsilon8(E2, 2.718281828459045);
     NumberHelper.AssertDoubleWithEpsilon8(PI2, 3.141592653589793);
 }
Example #21
0
 public void TanhWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Tanh(5.4251848), 0.999961205877d);
 }
Example #22
0
 public void ExpWorks()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.Exp(0.5), 1.6487212707001282);
 }
Example #23
0
 public void ConstantsWork()
 {
     NumberHelper.AssertDoubleWithEpsilon8(Math.E, 2.718281828459045);
     NumberHelper.AssertDoubleWithEpsilon8(Math.PI, 3.141592653589793);
 }