zhao
2021-07-07 2fdf959ac739edd6de84aa8053b8b9683dce8e8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Text;
using HH.WMS.Utils.NPOI.SS.Formula.Functions;
 
namespace HH.WMS.Utils.NPOI.SS.Formula.Eval
{
 
    public abstract class TwoOperandNumericOperation : Fixed2ArgFunction
    {
        //public int Type
        //{
        //    get
        //    {
        //        // TODO - remove
        //        throw new Exception("obsolete code should not be called");
        //    }
        //}
        protected double SingleOperandEvaluate(ValueEval arg, int srcCellRow, int srcCellCol)
        {
            ValueEval ve = OperandResolver.GetSingleValue(arg, srcCellRow, srcCellCol);
            return OperandResolver.CoerceValueToDouble(ve);
        }
 
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1)
        {
            double result;
            try
            {
                double d0 = SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double d1 = SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                result = Evaluate(d0, d1);
                if (result == 0.0)
                { // this '==' matches +0.0 and -0.0
                    // Excel Converts -0.0 to +0.0 for '*', '/', '%', '+' and '^'
                    if (!(this is SubtractEval))
                    {
                        return NumberEval.ZERO;
                    }
                }
                if (Double.IsNaN(result) || Double.IsInfinity(result))
                {
                    return ErrorEval.NUM_ERROR;
                }
            }
            catch (EvaluationException e)
            {
                return e.GetErrorEval();
            }
            return new NumberEval(result);
        }
 
        public abstract double Evaluate(double d0, double d1);
 
        public static HH.WMS.Utils.NPOI.SS.Formula.Functions.Function AddEval = new AddEval();
        public static HH.WMS.Utils.NPOI.SS.Formula.Functions.Function DivideEval = new DivideEval();
        public static HH.WMS.Utils.NPOI.SS.Formula.Functions.Function MultiplyEval = new MultiplyEval();
        public static HH.WMS.Utils.NPOI.SS.Formula.Functions.Function PowerEval = new PowerEval();
        public static HH.WMS.Utils.NPOI.SS.Formula.Functions.Function SubtractEval = new SubtractEval();
    }
}