summaryrefslogtreecommitdiff
path: root/tests/src/CoreMangLib/cti/system/math/mathtestlib.cs
blob: 1d27627ef6fc357c604ba46cd4bf24a22c38c4a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;

/// <summary>
/// Summary description for Class1
/// </summary>
public class MathTestLib
{
    private static Decimal epsilon = new Decimal(0.000001D);

    public static Decimal Epsilon
    {
        get
        {
            return epsilon;
        }
        set
        {
            epsilon = Convert.ToDecimal(value);
        }
    }

    public static bool DoubleIsWithinEpsilon(double x, double y)
    {
        Decimal dx = new Decimal(x);
        Decimal dy = new Decimal(y);
        Decimal diff = Math.Abs(Decimal.Subtract(dx, dy));
        return diff.CompareTo(Epsilon) <= 0;
    }

    public static bool FloatIsWithinEpsilon(float x, float y)
    {
        Decimal dx = new Decimal(x);
        Decimal dy = new Decimal(y);
        Decimal diff = Math.Abs(Decimal.Subtract(dx, dy));
        return diff.CompareTo(Epsilon) <= 0;
    }
}