示例#1
0
        /// <summary>
        /// Compare to other objects
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public int CompareTo(object o)
        {
            if (o == null)
            {
                return(1);  // null sorts before current
            }
            double c1 = this.ValueD;
            double c2 = c1;

            if (o is Oilfield_Constant)
            {
                Oilfield_Constant c = (Oilfield_Constant)o;
                c2 = c.ValueD;
            }
            if (o is double)
            {
                c2 = (double)o;
            }
            if (c1 < c2)
            {
                return(-1);
            }
            if (c1 > c2)
            {
                return(1);
            }
            return(0);
        }
示例#2
0
 /// <summary>
 /// Determine whether two constants are almost (i.e. within the tolerance) equivalent.
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <param name="tolerance"></param>
 /// <returns></returns>
 static public bool IsEqual(object a, object b, double tolerance)
 {
     if (a == null && b == null)
     {
         return(true);
     }
     if (a == null)
     {
         return(false);
     }
     if (b == null)
     {
         return(false);
     }
     if (a is Oilfield_Constant && b is Oilfield_Constant)
     {
         Oilfield_Constant a1 = (Oilfield_Constant)a;
         Oilfield_Constant b1 = (Oilfield_Constant)b;
         if (Math.Abs(a1 - b1) < tolerance)
         {
             return(true);
         }
         return(false);
     }
     if (a is Oilfield_Constant && b is double)
     {
         Oilfield_Constant a1 = (Oilfield_Constant)a;
         double            b1 = (double)b;
         if (Math.Abs(a1 - b1) < tolerance)
         {
             return(true);
         }
         return(false);
     }
     if (a is double && b is Oilfield_Constant)
     {
         double            a1 = (double)a;
         Oilfield_Constant b1 = (Oilfield_Constant)b;
         if (Math.Abs(a1 - b1) < tolerance)
         {
             return(true);
         }
         return(false);
     }
     if (a is double && b is double)
     {
         double a1 = (double)a;
         double b1 = (double)b;
         if (Math.Abs(a1 - b1) < tolerance)
         {
             return(true);
         }
         return(false);
     }
     return(false);
 }
示例#3
0
        /// <summary>
        /// Creates a deep copy of this constant
        /// </summary>
        /// <returns></returns>
        public virtual Oilfield_Constant Clone()
        {
            Oilfield_Constant tmp = new Oilfield_Constant();

            tmp.Name        = this.Name;
            tmp.Unit        = this.Unit;
            tmp.Value       = this.Value;
            tmp.Description = this.Description;
            return(tmp);
        }
示例#4
0
 /// <summary>
 /// Is this class equivalent to another object?
 /// </summary>
 /// <param name="o"></param>
 /// <returns></returns>
 public override bool Equals(object o)
 {
     if (o == null)
     {
         return(false);
     }
     if (o is Oilfield_Constant)
     {
         Oilfield_Constant c = (Oilfield_Constant)o;
         return(this.Value == c.Value && this.Unit == c.Unit);
     }
     if (o is double)
     {
         double c = (double)o;
         return(this.ValueD == c);
     }
     if (o is string)
     {
         string c = (string)o;
         return(this.Value == c);
     }
     return(false);
 }