예제 #1
0
        public override DL GetDL()
        {
            DL   x   = E.GetDL();
            long p10 = (long)Util.PowerTen(DTI.Scale(Type));

            return((ee) => x(ee) * p10);
        }
예제 #2
0
        public override DL GetDL()
        {
            DD    x   = E.GetDD();
            ulong p10 = Util.PowerTen(DTI.Scale(Type));

            return((ee) => (long)(x(ee) * p10));
        }
예제 #3
0
  public Exp Convert( DataType t )
  {
    if ( t < DataType.Decimal ) t = DTI.Base( t );

    if ( Type == t ) return this;
    else if ( Type == DataType.Bigint ) return 
        t == DataType.String ? (Exp) new IntToStringExp( this )
      : t == DataType.Double ? (Exp) new IntToDoubleExp( this )
      : t >= DataType.Decimal ? (Exp) new IntToDecimalExp( this, t )
      : null;
    else if ( Type == DataType.Double ) return 
       t == DataType.String ? (Exp) new DoubleToStringExp( this )
     : t == DataType.Bigint ? (Exp) new DoubleToIntExp( this )
     : t >= DataType.Decimal ? (Exp) new DoubleToDecimalExp( this, t )
     : null;
    else if ( Type >= DataType.Decimal )
    {
      if ( t == DataType.String ) return new DecimalToStringExp( this );
      else if ( t == DataType.Double ) return new DecimalToDoubleExp( this );
      else if ( t >= DataType.Decimal )
      {
        int amount = DTI.Scale( t ) - DTI.Scale( Type );
        return amount == 0 ? (Exp) this
        : amount > 0 ? (Exp) new ExpScale( this, t, amount )
        : (Exp) new ExpScaleReduce( this, t, -amount );
      }
    }
    else if ( Type == DataType.Binary && t == DataType.String )
      return new BinaryToStringExp( this );
    else if ( Type == DataType.Bool && t == DataType.String )
      return new BoolToStringExp( this );
    else if ( Type == DataType.ScaledInt && t >= DataType.Decimal ) return this;
    return null;
  }
예제 #4
0
        public override DD GetDD()
        {
            DL     x   = E.GetDL();
            double p10 = Util.PowerTen(DTI.Scale(E.Type));

            return((ee) => (double)x(ee) / p10);
        }
예제 #5
0
        public static string D2S(long v, DataType t)
        {
            decimal d     = v;
            int     scale = DTI.Scale(t);

            d = d / Util.PowerTen(scale);
            return(d.ToString("F" + scale, System.Globalization.CultureInfo.InvariantCulture));
        }
예제 #6
0
  public override DataType TypeCheck( SqlExec e )
  {
    DataType tL = Left.TypeCheck( e );
    DataType tR = Right.TypeCheck( e );

    if ( tL == DataType.Bigint && tR == DataType.Double )
    {
      Left = new IntToDoubleExp(Left);
      tL = DataType.Double;
    }
    else if ( tR == DataType.Bigint && tL == DataType.Double )
    {
      Right = new IntToDoubleExp(Right);
      tR = DataType.Double;
    }
    else if ( Operator != Token.VBar && ( tL >= DataType.Decimal || tR >= DataType.Decimal ) )
    {
      if ( tR == DataType.Bigint ) tR = DTI.Decimal(18,0);
      else if ( tL == DataType.Bigint ) tL = DTI.Decimal(18,0);
      else if ( tR == DataType.Float ) { Right = Right.Convert( tL ); tR = tL; }
      else if ( tL == DataType.Float ) { Left = Left.Convert( tR ); tL = tR; }

      int sL = DTI.Scale(tL);
      int sR = DTI.Scale(tR);

      if ( sL < 0 || sR < 0 ) e.Error( "Type error involving decimal" );

      switch( Operator )
      {
        case Token.Divide: tL = DTI.Decimal( 18, sL - sR ); break;
        case Token.Times:  tL = DTI.Decimal( 18, sL + sR );  break;
        case Token.Percent: break; 
        default: 
          if ( sL > sR ) { Right = new ExpScale( Right, tL, sL - sR ); tR = tL; }
          else if ( sL < sR ) { Left = new ExpScale( Left, tR, sR - sL ); tL = tR; }
          break;
      }
      tR = tL;
    }    
    if ( tL == tR )
    {
      if ( Operator <= Token.NotEqual ) 
        Type = DataType.Bool;
      else 
      {
        Type = tL;
        if ( !TokenInfo.OperatorValid( Operator, tL ) ) 
          e.Error ( "Type error " + TokenInfo.Name(Operator) + " not valid for type " + DTI.Name(tL) );
      }
    }
    else if ( tL == DataType.String && Operator == Token.VBar )
    {
      Type = DataType.String;
      Right = Right.Convert( DataType.String );
    }
    else e.Error( "Binary operator datatype error");
    return Type;
  }
예제 #7
0
 public override Value Eval( EvalEnv e )
 {
   Value v = E.Eval( e );
   decimal d = v.L;
   int scale = DTI.Scale( E.Type );
   d = d / Util.PowerTen( scale );
   v.O = d.ToString( "F" + scale, System.Globalization.CultureInfo.InvariantCulture );
   return v;
 }  
예제 #8
0
 long DoParse(string s, DataType t)
 {
     try
     {
         return((long)(decimal.Parse(s) * Util.PowerTen(DTI.Scale(t))));
     }
     catch (System.Exception)
     {
         throw new System.Exception("Cannot convert '" + s + "' to decimal");
     }
 }
        public override Value Eval(EvalEnv e)
        {
            string   s = (string)Arg[0].Eval(e)._O;
            DataType t = (DataType)Arg[1].Eval(e).L;

            try
            {
                Value result = new Value();
                result.L = (long)(decimal.Parse(s) * Util.PowerTen(DTI.Scale(t)));
                return(result);
            }
            catch (System.Exception)
            {
                throw new System.Exception("Error converting [" + s + "] to decimal");
            }
        }
예제 #10
0
 public override Value Eval( EvalEnv e )
 {
   Value v = E.Eval( e );
   v.L = (long) ( v.L * (long)Util.PowerTen( DTI.Scale( Type ) ) );
   return v;
 }  
예제 #11
0
 public override Value Eval( EvalEnv e )
 {
   Value v = E.Eval( e );
   v.D = ((double)v.L) / Util.PowerTen( DTI.Scale( E.Type ) );
   return v;
 }