Esempio n. 1
0
 public EngValue(double amount, ExponentGroup groups)
 {
     this.Sign = Math.Sign(amount);
     amount    = Math.Abs(amount);
     if (num.IsInfinity(amount) || num.IsNaN(amount))
     {
         this.Scalar   = amount;
         this.Exponent = 0;
     }
     else
     {
         if (amount > 0.0)
         {
             if (amount > 1.0)
             {
                 this.Exponent = (int)(Math.Floor(Math.Log10(amount) / 3.0) * 3.0);
             }
             else
             {
                 this.Exponent = (int)(Math.Ceiling(Math.Log10(amount) / 3.0) * 3.0);
             }
             this.Scalar = amount * Math.Pow(10.0, -Exponent);
             // Make adjustments and groups
             if (groups == ExponentGroup.Engineering)
             {
                 while (this.Scalar > 1e3)
                 {
                     this.Scalar   /= 1e3;
                     this.Exponent += 3;
                 }
                 while (this.Scalar < 0.1)
                 {
                     this.Scalar   *= 1e3;
                     this.Exponent -= 3;
                 }
             }
             else if (groups == ExponentGroup.Scientific)
             {
                 while (this.Scalar > 10)
                 {
                     this.Scalar /= 10;
                     this.Exponent++;
                 }
                 while (this.Scalar < 0.1)
                 {
                     this.Scalar *= 10;
                     this.Exponent--;
                 }
             }
             else // no grouping
             {
                 // Do nothing
             }
         }
         else
         {
             this.Exponent = 0;
             this.Scalar   = 0;
         }
     }
 }
Esempio n. 2
0
 public EngValue(float amount, ExponentGroup groups) : this((double)amount, groups)
 {
 }