示例#1
0
        public void Lessers()
        {
            SqlDouble Test1  = new SqlDouble(1.8e100);
            SqlDouble Test11 = new SqlDouble(1.8e100);
            SqlDouble Test2  = new SqlDouble(64e164);

            // LessThan()
            Assert.True(!SqlDouble.LessThan(Test1, Test11).Value);
            Assert.True(!SqlDouble.LessThan(Test2, Test1).Value);
            Assert.True(SqlDouble.LessThan(Test11, Test2).Value);

            // LessThanOrEqual ()
            Assert.True(SqlDouble.LessThanOrEqual(Test1, Test2).Value);
            Assert.True(!SqlDouble.LessThanOrEqual(Test2, Test1).Value);
            Assert.True(SqlDouble.LessThanOrEqual(Test11, Test1).Value);
            Assert.True(SqlDouble.LessThanOrEqual(Test11, SqlDouble.Null).IsNull);
        }
示例#2
0
        public void Lessers()
        {
            SqlDouble Test1  = new SqlDouble(1.8e100);
            SqlDouble Test11 = new SqlDouble(1.8e100);
            SqlDouble Test2  = new SqlDouble(64e164);

            // LessThan()
            Assert.IsTrue(!SqlDouble.LessThan(Test1, Test11).Value, "#J01");
            Assert.IsTrue(!SqlDouble.LessThan(Test2, Test1).Value, "#J02");
            Assert.IsTrue(SqlDouble.LessThan(Test11, Test2).Value, "#J03");

            // LessThanOrEqual ()
            Assert.IsTrue(SqlDouble.LessThanOrEqual(Test1, Test2).Value, "#J04");
            Assert.IsTrue(!SqlDouble.LessThanOrEqual(Test2, Test1).Value, "#J05");
            Assert.IsTrue(SqlDouble.LessThanOrEqual(Test11, Test1).Value, "#J06");
            Assert.IsTrue(SqlDouble.LessThanOrEqual(Test11, SqlDouble.Null).IsNull, "#J07");
        }
示例#3
0
        public override object Aggregate(int[] records, AggregateType kind)
        {
            bool hasData = false;

            try
            {
                switch (kind)
                {
                case AggregateType.Sum:
                    SqlDouble sum = 0.0d;
                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        checked { sum += _values[record]; }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(sum);
                    }
                    return(_nullValue);

                case AggregateType.Mean:
                    SqlDouble meanSum   = 0.0d;
                    int       meanCount = 0;
                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        checked { meanSum += _values[record]; }
                        meanCount++;
                        hasData = true;
                    }
                    if (hasData)
                    {
                        SqlDouble mean = 0.0d;
                        checked { mean = (meanSum / meanCount); }
                        return(mean);
                    }
                    return(_nullValue);

                case AggregateType.Var:
                case AggregateType.StDev:
                    int       count  = 0;
                    SqlDouble var    = 0.0d;
                    SqlDouble prec   = 0.0d;
                    SqlDouble dsum   = 0.0d;
                    SqlDouble sqrsum = 0.0d;

                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        dsum   += _values[record];
                        sqrsum += _values[record] * _values[record];
                        count++;
                    }

                    if (count > 1)
                    {
                        var  = count * sqrsum - (dsum * dsum);
                        prec = var / (dsum * dsum);

                        // we are dealing with the risk of a cancellation error
                        // double is guaranteed only for 15 digits so a difference
                        // with a result less than 1e-15 should be considered as zero

                        if ((prec < 1e-15) || (var < 0))
                        {
                            var = 0;
                        }
                        else
                        {
                            var /= (count * (count - 1));
                        }

                        if (kind == AggregateType.StDev)
                        {
                            return(Math.Sqrt(var.Value));
                        }
                        return(var);
                    }
                    return(_nullValue);

                case AggregateType.Min:
                    SqlDouble min = SqlDouble.MaxValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }
                        if ((SqlDouble.LessThan(_values[record], min)).IsTrue)
                        {
                            min = _values[record];
                        }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(min);
                    }
                    return(_nullValue);

                case AggregateType.Max:
                    SqlDouble max = SqlDouble.MinValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }
                        if ((SqlDouble.GreaterThan(_values[record], max)).IsTrue)
                        {
                            max = _values[record];
                        }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(max);
                    }
                    return(_nullValue);

                case AggregateType.First:     // Does not seem to be implemented
                    if (records.Length > 0)
                    {
                        return(_values[records[0]]);
                    }
                    return(null !);   // no data => null

                case AggregateType.Count:
                    count = 0;
                    for (int i = 0; i < records.Length; i++)
                    {
                        if (!IsNull(records[i]))
                        {
                            count++;
                        }
                    }
                    return(count);
                }
            }
            catch (OverflowException)
            {
                throw ExprException.Overflow(typeof(SqlDouble));
            }
            throw ExceptionBuilder.AggregateException(kind, _dataType);
        }
        public override object Aggregate(int[] records, AggregateType kind)
        {
            bool flag = false;

            try
            {
                int       num;
                SqlDouble num2;
                SqlDouble num3;
                int       num4;
                int       num5;
                int       num6;
                int       num7;
                int       num8;
                int       num9;
                int       num10;
                int       num11;
                SqlDouble minValue;
                int       num13;
                SqlDouble maxValue;
                SqlDouble num15;
                int       num16;
                SqlDouble num17;
                SqlDouble num18;
                int[]     numArray;
                SqlDouble num19;
                int       num21;
                int[]     numArray2;
                int       num22;
                int[]     numArray3;
                switch (kind)
                {
                case AggregateType.Sum:
                    num18     = 0.0;
                    numArray3 = records;
                    num10     = 0;
                    goto Label_007F;

                case AggregateType.Mean:
                    num17     = 0.0;
                    num16     = 0;
                    numArray2 = records;
                    num9      = 0;
                    goto Label_00F8;

                case AggregateType.Min:
                    maxValue = SqlDouble.MaxValue;
                    num6     = 0;
                    goto Label_031B;

                case AggregateType.Max:
                    minValue = SqlDouble.MinValue;
                    num5     = 0;
                    goto Label_039A;

                case AggregateType.First:
                    if (records.Length <= 0)
                    {
                        return(null);
                    }
                    return(this.values[records[0]]);

                case AggregateType.Count:
                    num  = 0;
                    num4 = 0;
                    goto Label_03FF;

                case AggregateType.Var:
                case AggregateType.StDev:
                    num      = 0;
                    num2     = 0.0;
                    num19    = 0.0;
                    num3     = 0.0;
                    num15    = 0.0;
                    numArray = records;
                    num8     = 0;
                    goto Label_01EE;

                default:
                    goto Label_0424;
                }
Label_004B:
                num22 = numArray3[num10];
                if (!this.IsNull(num22))
                {
                    num18 += this.values[num22];
                    flag   = true;
                }
                num10++;
Label_007F:
                if (num10 < numArray3.Length)
                {
                    goto Label_004B;
                }
                if (flag)
                {
                    return(num18);
                }
                return(base.NullValue);

Label_00BE:
                num21 = numArray2[num9];
                if (!this.IsNull(num21))
                {
                    num17 += this.values[num21];
                    num16++;
                    flag = true;
                }
                num9++;
Label_00F8:
                if (num9 < numArray2.Length)
                {
                    goto Label_00BE;
                }
                if (flag)
                {
                    return(num17 / ((double)num16));
                }
                return(base.NullValue);

Label_0186:
                num7 = numArray[num8];
                if (!this.IsNull(num7))
                {
                    num3  += this.values[num7];
                    num15 += this.values[num7] * this.values[num7];
                    num++;
                }
                num8++;
Label_01EE:
                if (num8 < numArray.Length)
                {
                    goto Label_0186;
                }
                if (num <= 1)
                {
                    return(base.NullValue);
                }
                num2  = ((SqlDouble)(num * num15)) - (num3 * num3);
                num19 = num2 / (num3 * num3);
                bool x = num19 < 1E-15;
                if (!SqlBoolean.op_True(x))
                {
                }
                if (SqlBoolean.op_True(x | (num2 < 0.0)))
                {
                    num2 = 0.0;
                }
                else
                {
                    num2 /= (double)(num * (num - 1));
                }
                if (kind == AggregateType.StDev)
                {
                    return(Math.Sqrt(num2.Value));
                }
                return(num2);

Label_02CB:
                num13 = records[num6];
                if (!this.IsNull(num13))
                {
                    if (SqlDouble.LessThan(this.values[num13], maxValue).IsTrue)
                    {
                        maxValue = this.values[num13];
                    }
                    flag = true;
                }
                num6++;
Label_031B:
                if (num6 < records.Length)
                {
                    goto Label_02CB;
                }
                if (flag)
                {
                    return(maxValue);
                }
                return(base.NullValue);

Label_034A:
                num11 = records[num5];
                if (!this.IsNull(num11))
                {
                    if (SqlDouble.GreaterThan(this.values[num11], minValue).IsTrue)
                    {
                        minValue = this.values[num11];
                    }
                    flag = true;
                }
                num5++;
Label_039A:
                if (num5 < records.Length)
                {
                    goto Label_034A;
                }
                if (flag)
                {
                    return(minValue);
                }
                return(base.NullValue);

Label_03E9:
                if (!this.IsNull(records[num4]))
                {
                    num++;
                }
                num4++;
Label_03FF:
                if (num4 < records.Length)
                {
                    goto Label_03E9;
                }
                return(num);
            }
            catch (OverflowException)
            {
                throw ExprException.Overflow(typeof(SqlDouble));
            }
Label_0424:
            throw ExceptionBuilder.AggregateException(kind, base.DataType);
        }