public static SqlDoubleRegularArray Parse(SqlString s) { if (s.IsNull) { return(Null); } return(new SqlDoubleRegularArray(SqlFormatting.ParseRegular <Double?>(s.Value, t => !t.Equals(SqlFormatting.NullText, StringComparison.InvariantCultureIgnoreCase) ? SqlDouble.Parse(t).Value : default(Double?)))); }
public static SqlBoolean op_Explicit(SqlDouble x) { if (x.IsNull) return SqlBoolean.Null; return new SqlBoolean(x.Value != 0.0D); }
public int SortValues(SqlDouble a, SqlDouble b) { //Short hand if PercentileCalculatorement to determine if 'a' is less then/equal to or greater than 'b' return(a < b ? (a == b ? 0 : -1) : 1); }
public override object Aggregate(int[] records, AggregateType kind) { bool hasData = false; try { switch (kind) { case AggregateType.Sum: SqlInt64 sum = 0; foreach (int record in records) { if (IsNull(record)) { continue; } checked { sum += _values[record]; } hasData = true; } if (hasData) { return(sum); } return(_nullValue); case AggregateType.Mean: SqlInt64 meanSum = 0; int meanCount = 0; foreach (int record in records) { if (IsNull(record)) { continue; } checked { meanSum += (_values[record]).ToSqlInt64(); } meanCount++; hasData = true; } if (hasData) { SqlInt16 mean = 0; checked { mean = (meanSum / meanCount).ToSqlInt16(); } return(mean); } return(_nullValue); case AggregateType.Var: case AggregateType.StDev: int count = 0; SqlDouble var = 0; SqlDouble prec = 0; SqlDouble dsum = 0; SqlDouble sqrsum = 0; foreach (int record in records) { if (IsNull(record)) { continue; } dsum += (_values[record]).ToSqlDouble(); sqrsum += (_values[record]).ToSqlDouble() * (_values[record]).ToSqlDouble(); 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 = var / (count * (count - 1)); } if (kind == AggregateType.StDev) { return(Math.Sqrt(var.Value)); } return(var); } return(_nullValue); case AggregateType.Min: SqlInt16 min = SqlInt16.MaxValue; for (int i = 0; i < records.Length; i++) { int record = records[i]; if (IsNull(record)) { continue; } if ((SqlInt16.LessThan(_values[record], min)).IsTrue) { min = _values[record]; } hasData = true; } if (hasData) { return(min); } return(_nullValue); case AggregateType.Max: SqlInt16 max = SqlInt16.MinValue; for (int i = 0; i < records.Length; i++) { int record = records[i]; if (IsNull(record)) { continue; } if ((SqlInt16.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(SqlInt16)); } throw ExceptionBuilder.AggregateException(kind, _dataType); }
public void ArithmeticOperators() { SqlDouble Test0 = new SqlDouble(0); SqlDouble Test1 = new SqlDouble(24E+100); SqlDouble Test2 = new SqlDouble(64E+164); SqlDouble Test3 = new SqlDouble(12E+100); SqlDouble Test4 = new SqlDouble(1E+10); SqlDouble Test5 = new SqlDouble(2E+10); // "+"-operator Assert.Equal(3E+10, Test4 + Test5); try { SqlDouble test = SqlDouble.MaxValue + SqlDouble.MaxValue; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // "/"-operator Assert.Equal(2, Test1 / Test3); try { SqlDouble test = Test3 / Test0; Assert.False(true); } catch (DivideByZeroException e) { Assert.Equal(typeof(DivideByZeroException), e.GetType()); } // "*"-operator Assert.Equal(2e20, Test4 * Test5); try { SqlDouble test = SqlDouble.MaxValue * Test1; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // "-"-operator Assert.Equal(12e100, Test1 - Test3); try { SqlDouble test = SqlDouble.MinValue - SqlDouble.MaxValue; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } }
public void ConversionDoubleOverflowException() { SqlDouble test = (new SqlString("4e400")).ToSqlDouble(); }
public static SqlDouble addTax(SqlDouble originalAmount) { SqlDouble taxAmount = originalAmount * SALES_TAX; return(originalAmount + taxAmount); }
public static void GetEventData_FillRow(object source, out SqlInt32 seriesID, out SqlString characteristic, out DateTime time, out SqlDouble value) { DataPoint dataPoint = source as DataPoint; if ((object)dataPoint == null) { throw new InvalidOperationException("FillRow source is not a DataPoint"); } seriesID = dataPoint.SeriesID; characteristic = dataPoint.Characteristic; time = dataPoint.Time; value = ToSqlDouble(dataPoint.Value); }
/// <summary> /// Purpose: Select method. This method will Select one existing row from the database, based on the Primary Key. /// </summary> /// <returns>DataTable object if succeeded, otherwise an Exception is thrown. </returns> /// <remarks> /// Properties needed for this method: /// <UL> /// <LI>NPayrollID</LI> /// <LI>NEmployeeID</LI> /// </UL> /// Properties set after a succesful call of this method: /// <UL> /// <LI>ErrorCode</LI> /// <LI>NPayrollID</LI> /// <LI>NEmployeeID</LI> /// <LI>NNormalOT</LI> /// <LI>NPublicHolidayOT</LI> /// <LI>NOffDayOT</LI> /// <LI>NPartTimeWorkHours</LI> /// <LI>NALEntitlementHours</LI> /// <LI>NPHEntitlementHours</LI> /// <LI>MServiceReimbursements</LI> /// <LI>NTotalLateness</LI> /// <LI>NUnpaidAL</LI> /// <LI>NUnpaidTO</LI> /// <LI>NUnpaidMedical</LI> /// <LI>MCommission</LI> /// <LI>MCommissionLatenessPenalty</LI> /// </UL> /// Will fill all properties corresponding with a field in the table with the value of the row selected. /// </remarks> public override DataTable SelectOne() { SqlCommand cmdToExecute = new SqlCommand(); cmdToExecute.CommandText = "dbo.[sp_tblPayrollEntries_SelectOne]"; cmdToExecute.CommandType = CommandType.StoredProcedure; DataTable toReturn = new DataTable("tblPayrollEntries"); SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute); // Use base class' connection object cmdToExecute.Connection = _mainConnection; try { cmdToExecute.Parameters.Add(new SqlParameter("@inPayrollID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _nPayrollID)); cmdToExecute.Parameters.Add(new SqlParameter("@inEmployeeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _nEmployeeID)); cmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode)); if (_mainConnectionIsCreatedLocal) { // Open connection. _mainConnection.Open(); } else { if (_mainConnectionProvider.IsTransactionPending) { cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction; } } // Execute query. adapter.Fill(toReturn); _errorCode = (SqlInt32)cmdToExecute.Parameters["@iErrorCode"].Value; if (_errorCode != (int)LLBLError.AllOk) { // Throw error. throw new Exception("Stored Procedure 'sp_tblPayrollEntries_SelectOne' reported the ErrorCode: " + _errorCode); } if (toReturn.Rows.Count > 0) { _nPayrollID = (Int32)toReturn.Rows[0]["nPayrollID"]; _nEmployeeID = (Int32)toReturn.Rows[0]["nEmployeeID"]; _nNormalOT = toReturn.Rows[0]["nNormalOT"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nNormalOT"]; _nPublicHolidayOT = toReturn.Rows[0]["nPublicHolidayOT"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nPublicHolidayOT"]; _nOffDayOT = toReturn.Rows[0]["nOffDayOT"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nOffDayOT"]; _nPartTimeWorkHours = toReturn.Rows[0]["nPartTimeWorkHours"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nPartTimeWorkHours"]; _nALEntitlementHours = toReturn.Rows[0]["nALEntitlementHours"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nALEntitlementHours"]; _nPHEntitlementHours = toReturn.Rows[0]["nPHEntitlementHours"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nPHEntitlementHours"]; _mServiceReimbursements = toReturn.Rows[0]["mServiceReimbursements"] == System.DBNull.Value ? SqlMoney.Null : (Decimal)toReturn.Rows[0]["mServiceReimbursements"]; _nTotalLateness = toReturn.Rows[0]["nTotalLateness"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nTotalLateness"]; _nUnpaidAL = toReturn.Rows[0]["nUnpaidAL"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nUnpaidAL"]; _nUnpaidTO = toReturn.Rows[0]["nUnpaidTO"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nUnpaidTO"]; _nUnpaidMedical = toReturn.Rows[0]["nUnpaidMedical"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["nUnpaidMedical"]; _mCommission = toReturn.Rows[0]["mCommission"] == System.DBNull.Value ? SqlMoney.Null : (Decimal)toReturn.Rows[0]["mCommission"]; _mCommissionLatenessPenalty = toReturn.Rows[0]["mCommissionLatenessPenalty"] == System.DBNull.Value ? SqlMoney.Null : (Decimal)toReturn.Rows[0]["mCommissionLatenessPenalty"]; } return(toReturn); } catch (Exception ex) { // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("TblPayrollEntries::SelectOne::Error occured.", ex); } finally { if (_mainConnectionIsCreatedLocal) { // Close connection. _mainConnection.Close(); } cmdToExecute.Dispose(); adapter.Dispose(); } }
public static SqlDouble BankersRound(SqlDouble value, SqlInt16 places) { Double myValue = value.Value; return(Math.Round(myValue, places.Value, MidpointRounding.ToEven)); }
public static void GetFaultData_FillRow(object source, out SqlString algorithm, out DateTime time, out SqlDouble value) { FaultDataPoint dataPoint = source as FaultDataPoint; if ((object)dataPoint == null) { throw new InvalidOperationException("FillRow source is not a DataPoint"); } algorithm = dataPoint.Algorithm; time = dataPoint.Time; value = ToSqlDouble(dataPoint.Value); }
public static void NumRun2UDF(SqlBinary byteCode, ref SqlDouble output, SqlBinary arg0, SqlBinary arg1) { output = NumRun2(byteCode.Value, arg0.Value, arg1.Value); }
public static void NumRun0UDF(SqlBinary byteCode, ref SqlDouble output) { output = NumRun0(byteCode.Value); }
public static void NumRun4UDF(SqlBinary byteCode, ref SqlDouble output, SqlBinary arg0, SqlBinary arg1, SqlBinary arg2, SqlBinary arg3) { output = NumRun4(byteCode.Value, arg0.Value, arg1.Value, arg2.Value, arg3.Value); }
public static void ShortestPath(SqlInt64 startNode, SqlInt64 endNode, SqlInt32 maxNodesToCheck, out SqlString pathResult, out SqlDouble distResult) { Dictionary <long, double> distance = new Dictionary <long, double>(); // curr shortest distance (double) from startNode to (key) node Dictionary <long, long> previous = new Dictionary <long, long>(); // predecessor values to construct the actual path when done Dictionary <long, bool> beenAdded = new Dictionary <long, bool>(); // has node been added to the queue yet? Once added, we don't want to add again long startNodeAsLong = (long)startNode; long endNodeAsLong = (long)endNode; int maxNodesToCheckAsInt = (int)maxNodesToCheck; MyPriorityQueue PQ = new MyPriorityQueue(); //initialize start node distance[startNodeAsLong] = 0.0; // distance from start node to itself is 0 previous[startNodeAsLong] = -1; // -1 is the code for undefined. PQ.Enqueue(new NodeDistance(startNodeAsLong, 0.0)); // the queue holds distance information because Enqueue and Dequeue need it to keep queue ordered by priority. alt approach would be to store only node IDs and then do a distance lookup beenAdded[startNodeAsLong] = true; double alt = 0.0; //'test distance' try { while (PQ.Count() > 0 && beenAdded.Count < maxNodesToCheckAsInt) { NodeDistance u = PQ.Dequeue();// node with shortest distance from start if (u.nodeID == endNode) { break;// found the target end node } //fetch all neighbors (v) of u List <Tuple <long, double> > neighbors = new List <Tuple <long, double> >(); neighbors = FetchNeighbors(u.nodeID); foreach (var v in neighbors) // if there are no neighbors, this loop will exit immediately { if (beenAdded.ContainsKey(v.Item1) == false) //first appearance of node v { distance[v.Item1] = double.MaxValue; //stand-in for infinity previous[v.Item1] = -1; //undefined PQ.Enqueue(new NodeDistance(v.Item1, double.MaxValue)); //maxValue is a dummy value beenAdded[v.Item1] = true; } //alt = distance[u.nodeID] + 1.0; // if all edge weights are just hops can simplify to this alt = distance[u.nodeID] + v.Item2; // alt = dist(start-to-u) + dist(u-to-v), so alt is total distance from start to v if (alt < distance[v.Item1]) // is alt a new, shorter distance from start to v? { distance[v.Item1] = alt; previous[v.Item1] = u.nodeID; PQ.ChangePriority(v.Item1, alt); // this will change the distance/priority } } } // extract the shortest path as a string from the previous[] array pathResult = "NOTREACHABLE"; // default result string distResult = -1.0; // distance result defaults to -1 == unreachable if (distance.ContainsKey(endNodeAsLong) == true) // endNode was encountered at some point in the algorithm { double sp = distance[endNodeAsLong]; // shortest path distance if (sp != double.MaxValue) // we have a reachable path { pathResult = ""; long currNode = endNodeAsLong; while (currNode != startNodeAsLong) // construct the path as semicolon delimited string { pathResult += currNode.ToString() + ";"; currNode = previous[currNode]; } pathResult += startNode.ToString(); // tack on the start node distResult = sp; // the distance result } } } catch (Exception ex) // typically Out Of Memory or a Command TimeOut { pathResult = ex.ToString(); distResult = -1.0; } }
private object GetValueFromSourceRow(int columnOrdinal, _SqlMetaData metadata, int[] UseSqlValue, int destRowIndex) { if (UseSqlValue[destRowIndex] == 0) { UseSqlValue[destRowIndex] = -1; if ((metadata.metaType.NullableType == 0x6a) || (metadata.metaType.NullableType == 0x6c)) { Type fieldType = null; switch (this._rowSourceType) { case ValueSourceType.IDataReader: if (this._SqlDataReaderRowSource != null) { fieldType = this._SqlDataReaderRowSource.GetFieldType(columnOrdinal); } break; case ValueSourceType.DataTable: case ValueSourceType.RowArray: fieldType = this._currentRow.Table.Columns[columnOrdinal].DataType; break; } if ((typeof(SqlDecimal) == fieldType) || (typeof(decimal) == fieldType)) { UseSqlValue[destRowIndex] = 4; } else if ((typeof(SqlDouble) == fieldType) || (typeof(double) == fieldType)) { UseSqlValue[destRowIndex] = 5; } else if ((typeof(SqlSingle) == fieldType) || (typeof(float) == fieldType)) { UseSqlValue[destRowIndex] = 10; } } } switch (this._rowSourceType) { case ValueSourceType.IDataReader: if (this._SqlDataReaderRowSource == null) { return(((IDataReader)this._rowSource).GetValue(columnOrdinal)); } switch (UseSqlValue[destRowIndex]) { case 4: return(this._SqlDataReaderRowSource.GetSqlDecimal(columnOrdinal)); case 5: return(new SqlDecimal(this._SqlDataReaderRowSource.GetSqlDouble(columnOrdinal).Value)); case 10: return(new SqlDecimal((double)this._SqlDataReaderRowSource.GetSqlSingle(columnOrdinal).Value)); } return(this._SqlDataReaderRowSource.GetValue(columnOrdinal)); case ValueSourceType.DataTable: case ValueSourceType.RowArray: { object obj2 = this._currentRow[columnOrdinal]; if (((obj2 == null) || (DBNull.Value == obj2)) || (((10 != UseSqlValue[destRowIndex]) && (5 != UseSqlValue[destRowIndex])) && (4 != UseSqlValue[destRowIndex]))) { return(obj2); } INullable nullable = obj2 as INullable; if ((nullable != null) && nullable.IsNull) { return(obj2); } SqlBuffer.StorageType type2 = (SqlBuffer.StorageType)UseSqlValue[destRowIndex]; switch (type2) { case SqlBuffer.StorageType.Decimal: if (nullable == null) { return(new SqlDecimal((decimal)obj2)); } return((SqlDecimal)obj2); case SqlBuffer.StorageType.Double: { if (nullable == null) { double d = (double)obj2; if (double.IsNaN(d)) { return(obj2); } return(new SqlDecimal(d)); } SqlDouble num4 = (SqlDouble)obj2; return(new SqlDecimal(num4.Value)); } } if (type2 != SqlBuffer.StorageType.Single) { return(obj2); } if (nullable != null) { SqlSingle num5 = (SqlSingle)obj2; return(new SqlDecimal((double)num5.Value)); } float f = (float)obj2; if (float.IsNaN(f)) { return(obj2); } return(new SqlDecimal((double)f)); } } throw ADP.NotSupported(); }
/// <summary> /// Purpose: Select method. This method will Select one existing row from the database, based on the Primary Key. /// </summary> /// <returns>DataTable object if succeeded, otherwise an Exception is thrown. </returns> /// <remarks> /// Properties needed for this method: /// <UL> /// <LI>StrBankCode</LI> /// <LI>NMonth</LI> /// </UL> /// Properties set after a succesful call of this method: /// <UL> /// <LI>ErrorCode</LI> /// <LI>StrBankCode</LI> /// <LI>NMonth</LI> /// <LI>DInterestRate</LI> /// </UL> /// Will fill all properties corresponding with a field in the table with the value of the row selected. /// </remarks> public override DataTable SelectOne() { SqlCommand cmdToExecute = new SqlCommand(); cmdToExecute.CommandText = "dbo.[sp_tblBankIPPRate_SelectOne]"; cmdToExecute.CommandType = CommandType.StoredProcedure; DataTable toReturn = new DataTable("tblBankIPPRate"); SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute); // Use base class' connection object cmdToExecute.Connection = _mainConnection; try { cmdToExecute.Parameters.Add(new SqlParameter("@sstrBankCode", SqlDbType.Char, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _strBankCode)); cmdToExecute.Parameters.Add(new SqlParameter("@inMonth", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _nMonth)); cmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode)); if (_mainConnectionIsCreatedLocal) { // Open connection. _mainConnection.Open(); } else { if (_mainConnectionProvider.IsTransactionPending) { cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction; } } // Execute query. adapter.Fill(toReturn); _errorCode = (SqlInt32)cmdToExecute.Parameters["@iErrorCode"].Value; if (_errorCode != (int)LLBLError.AllOk) { // Throw error. throw new Exception("Stored Procedure 'sp_tblBankIPPRate_SelectOne' reported the ErrorCode: " + _errorCode); } if (toReturn.Rows.Count > 0) { _strBankCode = (string)toReturn.Rows[0]["strBankCode"]; _nMonth = (Int32)toReturn.Rows[0]["nMonth"]; _dInterestRate = toReturn.Rows[0]["dInterestRate"] == System.DBNull.Value ? SqlDouble.Null : (double)toReturn.Rows[0]["dInterestRate"]; } return(toReturn); } catch (Exception ex) { // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("TblBankIPPRate::SelectOne::Error occured.", ex); } finally { if (_mainConnectionIsCreatedLocal) { // Close connection. _mainConnection.Close(); } cmdToExecute.Dispose(); adapter.Dispose(); } }
public void SqlDoubleToSqlString() { SqlDouble testDouble = new SqlDouble(64E+64); Assert.Equal(6.4E+65.ToString(), ((SqlString)testDouble).Value); }
public void SqlDoubleToSqlString() { SqlDouble TestDouble = new SqlDouble(64E+64); Assert.AreEqual("6.4E+65", ((SqlString)TestDouble).Value, "#V01"); }
public void SqlDoubleToSqlDecimal() { SqlDouble test = new SqlDouble(12E+10); Assert.Equal(120000000000m, ((SqlDecimal)test).Value); }
public static SqlDouble VirtualDryAirTemp(SqlDouble airTemp, SqlDouble dewpointTemp, SqlDouble stationPressure) { return((airTemp + 273.15) / (1 - 0.379 * ((6.11 * Math.Pow(10, (7.5 * (double)dewpointTemp) / (237.7 + (double)dewpointTemp))) / (double)stationPressure))); }
public static double?ToNullable(this SqlDouble @this) => @this.IsNull ? (double?)null : @this.Value;
public void Conversions() { SqlDouble Test0 = new SqlDouble(0); SqlDouble Test1 = new SqlDouble(250); SqlDouble Test2 = new SqlDouble(64e64); SqlDouble Test3 = new SqlDouble(64e164); SqlDouble TestNull = SqlDouble.Null; // ToSqlBoolean () Assert.True(Test1.ToSqlBoolean().Value); Assert.True(!Test0.ToSqlBoolean().Value); Assert.True(TestNull.ToSqlBoolean().IsNull); // ToSqlByte () Assert.Equal((byte)250, Test1.ToSqlByte().Value); Assert.Equal((byte)0, Test0.ToSqlByte().Value); try { SqlByte b = (byte)Test2.ToSqlByte(); Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlDecimal () Assert.Equal(250.00000000000000M, Test1.ToSqlDecimal().Value); Assert.Equal(0, Test0.ToSqlDecimal().Value); try { SqlDecimal test = Test3.ToSqlDecimal().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlInt16 () Assert.Equal((short)250, Test1.ToSqlInt16().Value); Assert.Equal((short)0, Test0.ToSqlInt16().Value); try { SqlInt16 test = Test2.ToSqlInt16().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlInt32 () Assert.Equal(250, Test1.ToSqlInt32().Value); Assert.Equal(0, Test0.ToSqlInt32().Value); try { SqlInt32 test = Test2.ToSqlInt32().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlInt64 () Assert.Equal(250, Test1.ToSqlInt64().Value); Assert.Equal(0, Test0.ToSqlInt64().Value); try { SqlInt64 test = Test2.ToSqlInt64().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlMoney () Assert.Equal(250.0000M, Test1.ToSqlMoney().Value); Assert.Equal(0, Test0.ToSqlMoney().Value); try { SqlMoney test = Test2.ToSqlMoney().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlSingle () Assert.Equal(250, Test1.ToSqlSingle().Value); Assert.Equal(0, Test0.ToSqlSingle().Value); try { SqlSingle test = Test2.ToSqlSingle().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlString () Assert.Equal(250.ToString(), Test1.ToSqlString().Value); Assert.Equal(0.ToString(), Test0.ToSqlString().Value); Assert.Equal(6.4E+65.ToString(), Test2.ToSqlString().Value); // ToString () Assert.Equal(250.ToString(), Test1.ToString()); Assert.Equal(0.ToString(), Test0.ToString()); Assert.Equal(6.4E+65.ToString(), Test2.ToString()); }
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); }
public void GetXsdTypeTest() { XmlQualifiedName qualifiedName = SqlDouble.GetXsdType(null); Assert.Equal("double", qualifiedName.Name); }
// devnote: This method should not be used with SqlDbType.Date and SqlDbType.DateTime2. // With these types the values should be used directly as CLR types instead of being converted to a SqlValue internal static object GetSqlValueFromComVariant(object comVal) { object sqlVal = null; if ((null != comVal) && (DBNull.Value != comVal)) { if (comVal is float) { sqlVal = new SqlSingle((float)comVal); } else if (comVal is string) { sqlVal = new SqlString((string)comVal); } else if (comVal is double) { sqlVal = new SqlDouble((double)comVal); } else if (comVal is byte[]) { sqlVal = new SqlBinary((byte[])comVal); } else if (comVal is char) { sqlVal = new SqlString(((char)comVal).ToString()); } else if (comVal is char[]) { sqlVal = new SqlChars((char[])comVal); } else if (comVal is System.Guid) { sqlVal = new SqlGuid((Guid)comVal); } else if (comVal is bool) { sqlVal = new SqlBoolean((bool)comVal); } else if (comVal is byte) { sqlVal = new SqlByte((byte)comVal); } else if (comVal is short) { sqlVal = new SqlInt16((short)comVal); } else if (comVal is int) { sqlVal = new SqlInt32((int)comVal); } else if (comVal is long) { sqlVal = new SqlInt64((long)comVal); } else if (comVal is decimal) { sqlVal = new SqlDecimal((decimal)comVal); } else if (comVal is DateTime) { // devnote: Do not use with SqlDbType.Date and SqlDbType.DateTime2. See comment at top of method. sqlVal = new SqlDateTime((DateTime)comVal); } else if (comVal is XmlReader) { sqlVal = new SqlXml((XmlReader)comVal); } else if (comVal is TimeSpan || comVal is DateTimeOffset) { sqlVal = comVal; } #if DEBUG else { Debug.Fail("unknown SqlType class stored in sqlVal"); } #endif } return(sqlVal); }
public void SqlTypes_SqlDouble() { NpgsqlParameter parameter; SqlDouble value = new SqlDouble(4.5D); #if NET_2_0 parameter = new NpgsqlParameter (); parameter.NpgsqlValue = value; Assert.AreEqual (NpgsqlDbType.Float, parameter.NpgsqlDbType, "#A:NpgsqlDbType"); Assert.AreEqual (value, parameter.NpgsqlValue, "#A:NpgsqlValue"); Assert.AreEqual (value, parameter.Value, "#A:Value"); parameter = new NpgsqlParameter (); parameter.NpgsqlValue = SqlDouble.Null; Assert.AreEqual (NpgsqlDbType.Float, parameter.NpgsqlDbType, "#B:NpgsqlDbType"); Assert.AreEqual (SqlDouble.Null, parameter.NpgsqlValue, "#B:NpgsqlValue"); Assert.AreEqual (SqlDouble.Null, parameter.Value, "#B:Value"); #endif parameter = new NpgsqlParameter(); parameter.Value = value; Assert.AreEqual(NpgsqlDbType.Float, parameter.NpgsqlDbType, "#C:NpgsqlDbType"); #if NET_2_0 Assert.AreEqual (value, parameter.NpgsqlValue, "#C:NpgsqlValue"); #endif Assert.AreEqual(value, parameter.Value, "#C:Value"); }
//private List<SqlDouble> AccumilatedData; //private SqlDouble PercentileNth; //private SqlDouble Result; public SqlDecimal GetTIRCalculator(List <SqlDecimal> AmountColl, SqlDecimal nun_pag) { Decimal LOW_RATE = Convert.ToDecimal(0.10); Decimal HIGH_RATE = Convert.ToDecimal(0.50); Decimal MAX_ITERATION = 1000; Decimal PRECISION_REQ = Convert.ToDecimal(0.00000001); Int32 i = 0, j = 0; Decimal m = Convert.ToDecimal(0.00); Decimal old = Convert.ToDecimal(0.00); Decimal neww = Convert.ToDecimal(0.00); Decimal oldguessRate = LOW_RATE; Decimal newguessRate = LOW_RATE; Decimal guessRate = LOW_RATE; Decimal lowGuessRate = LOW_RATE; Decimal highGuessRate = HIGH_RATE; Decimal npv = Convert.ToDecimal(0.00); SqlDouble denom = 0.0; for (i = 0; i < MAX_ITERATION; i++) { npv = Convert.ToDecimal(0.00); for (j = 1; j <= nun_pag; j++) { denom = (1 + System.Math.Pow(Convert.ToInt32(guessRate), j)); npv = npv + Convert.ToDecimal((AmountColl[j] / denom)); } /* Stop checking once the required precision is achieved */ if ((npv > 0) && (npv < PRECISION_REQ)) { break; } if (old == 0) { old = npv; } else { old = neww; } neww = npv; if (i > 0) { if (old < neww) { if (old < 0 && neww < 0) { highGuessRate = newguessRate; } else { lowGuessRate = newguessRate; } } else { if (old > 0 && neww > 0) { lowGuessRate = newguessRate; } else { highGuessRate = newguessRate; } } } oldguessRate = guessRate; guessRate = (lowGuessRate + highGuessRate) / 2; newguessRate = guessRate; } return(guessRate); }