Пример #1
0
 public override UnitConverter Concatenate(UnitConverter converter)
 {
     if (converter is MultiplyConverter)
     {
         return(ValueOf(factor * ((MultiplyConverter)converter).factor));
     }
     else if (converter is RationalConverter)
     {
         RationalConverter rc = (RationalConverter)converter;
         double            f  = this.factor * rc.dividend / rc.divisor;
         return(ValueOf(f));
     }
     else if (converter is ConstantConverter)
     {
         return(ValueOf(factor * ((ConstantConverter)converter).constant));
     }
     else
     {
         return(base.Concatenate(converter));
     }
 }
Пример #2
0
 public override UnitConverter Concatenate(UnitConverter converter)
 {
     if (converter is RationalConverter)
     {
         RationalConverter rc  = (RationalConverter)converter;
         long   dividendLong   = dividend * rc.dividend;
         long   divisorLong    = divisor * rc.divisor;
         double dividendDouble = ((double)dividend) * rc.dividend;
         double divisorDouble  = ((double)divisor) * rc.divisor;
         if ((dividendLong != dividendDouble) || (divisorLong != divisorDouble))
         {
             return(new MultiplyConverter(dividendDouble / divisorDouble));
         }
         long gcd = Gcd(dividendLong, divisorLong);
         return(ValueOf(dividendLong / gcd, divisorLong / gcd));
     }
     else if (converter is MultiplyConverter)
     {
         return(converter.Concatenate(this));
     }
     else if (converter is ConstantConverter)
     {
         var factor = dividend * ((ConstantConverter)converter).constant / dividend;
         if (factor == 0)
         {
             return(new ConstantConverter(0));
         }
         else
         {
             return(new MultiplyConverter(factor));
         }
     }
     else
     {
         return(base.Concatenate(converter));
     }
 }