示例#1
0
 public override float Eval()
 {
     if (right.Eval() == 0.0f)
     {
         ErrorExeption.customExeption("Error: Attempt to divide by 0");
         throw new ArgumentException("Attempt to divide by 0");
     }
     return((right.Eval() != 0.0f) ? (left.Eval() / right.Eval()):float.MaxValue);
 }
示例#2
0
        //Парсинг числа
        private Operation parseNumber()
        {
            Operation result = null;
            float     val    = 0.0f;
            int       start  = position;

            while (position < sourceStr.Length && (char.IsDigit(sourceStr [position]) || sourceStr [position] == '.' || sourceStr [position] == 'e'))
            {
                ++position;
            }

            try{
                val = float.Parse(sourceStr.Substring(start, position - start));
            } catch {
                ErrorExeption.customExeption("Can't parse '" + sourceStr.Substring(start));
                throw new ArgumentException("Can't parse '" + sourceStr.Substring(start));
            }
            result = new Number(val);
            return(result);
        }