public override bool ReadNullableSingle(out Single?result) { this.DiscardCompletedStacks(); if (this._itemsCount.Count == 0) { result = default(Single? ); return(false); } if (!this._root.ReadSubtreeNullableSingle(out result)) { return(false); } if (this._root.IsArrayHeader) { this._itemsCount.Push(this._root.ItemsCount); this._unpacked.Push(0); this._isMap.Push(false); } else if (this._root.IsMapHeader) { this._itemsCount.Push(this._root.ItemsCount * 2); this._unpacked.Push(0); this._isMap.Push(true); } else { this._unpacked.Push(this._unpacked.Pop() + 1); } return(true); }
public Single?ToSingleNullable(object x, bool useDefaultForNull = false) { Single?result = null; try { if (!DBNull.Value.Equals(x)) { if (x != null) { result = System.Convert.ToSingle(x); } else { if (useDefaultForNull) { result = 0; } } } } catch { result = 0; } return(result); }
public Int32 ReadNullableFloat(ref Single?value) { if ((mStream == null) || (mReader == null) || ((mStream.Length - mStream.Position) < (sizeof(Single)) + 2)) { return(AResult.AE_FAIL); } mReader.ReadSByte(); Boolean hasValue = mReader.ReadBoolean(); if (hasValue) { if (mIsLittleEndian) { value = mReader.ReadSingle(); } else { UInt32 val = mReader.ReadUInt32(); val = ByteOrder.Swap32(val); Byte[] b = BitConverter.GetBytes(val); value = BitConverter.ToSingle(b, 0); } } else { value = null; } return(AResult.AS_OK); }
/// <summary> /// 给当前实体赋值 /// </summary> protected override void SetValues(WeiSha.Data.IRowReader reader) { if ((false == reader.IsDBNull(_.Tq_Id))) { this._Tq_Id = reader.GetInt32(_.Tq_Id); } if ((false == reader.IsDBNull(_.Qk_Id))) { this._Qk_Id = reader.GetInt32(_.Qk_Id); } if ((false == reader.IsDBNull(_.Tp_Id))) { this._Tp_Id = reader.GetInt32(_.Tp_Id); } if ((false == reader.IsDBNull(_.Tq_Number))) { this._Tq_Number = reader.GetFloat(_.Tq_Number); } if ((false == reader.IsDBNull(_.Tq_Percent))) { this._Tq_Percent = reader.GetInt32(_.Tq_Percent); } if ((false == reader.IsDBNull(_.Tq_Type))) { this._Tq_Type = reader.GetInt32(_.Tq_Type); } if ((false == reader.IsDBNull(_.Org_ID))) { this._Org_ID = reader.GetInt32(_.Org_ID); } if ((false == reader.IsDBNull(_.Org_Name))) { this._Org_Name = reader.GetString(_.Org_Name); } }
public NullableHandlingTest( Single?fuzzyNullableSingle = null, Single?defaultNullableSingle = null) { this.FuzzyNullableSingle = fuzzyNullableSingle; this.DefaultNullableSingle = defaultNullableSingle; }
public override bool Equals(object x, object y) { //get boxed values. Single?xTyped = (Single?)x; return(xTyped.Equals(y)); }
public static Single Max(Single?a, Single?b, Single defaultValue = Single.MinValue) { var aValue = a.GetValueOrDefault(defaultValue); var bValue = b.GetValueOrDefault(defaultValue); return(aValue > bValue ? aValue : bValue); }
private static void AddRow(List <Dictionary <string, object> > ret, int id, string firstName, double something, decimal salary, DateTime birthday, bool iS, Guid guid, Single?age, float floatValue, float?floatNullableValue, DateTimeOffset dateTimeOffset, DateTimeOffset?dateTimeOffsetNullable) { Dictionary <string, object> row = new Dictionary <string, object>() { { "Id", id }, { "FirstName", firstName }, { "Something", something }, { "Salary", salary }, { "Birthday", birthday }, { "Is", iS }, { "PropertyGuid", guid }, { "Age", age }, { "Float", floatValue }, { "FloatNullable", floatNullableValue }, { "DateTimeOffset", dateTimeOffset }, { "DateTimeOffsetNullable", dateTimeOffsetNullable } }; ret.Add(row); }
internal BinaryFormatter WriteNullableSingle(Single?value) { WriteTypeID(TypeID.NullableSingle); WriteNullableValue(value.HasValue, () => this.Writer.WriteBytes(BitConverter.GetBytes(value.Value))); return(this); }
/// <summary> /// Determines whether this <see cref="Ray"/> intersects a specified <see cref="Plane"/>. /// </summary> /// <param name="plane">The <see cref="Plane"/> to evaluate.</param> /// <param name="result">The distance along the ray at which it intersects the plane, or <see langword="null"/> if there is no intersection.</param> public void Intersects(ref Plane plane, out Single?result) { var normalDotDirection = plane.Normal.X * Direction.X + plane.Normal.Y * Direction.Y + plane.Normal.Z * Direction.Z; if (MathUtil.IsApproximatelyZero(normalDotDirection)) { result = null; } else { var normalDotPosition = plane.Normal.X * Position.X + plane.Normal.Y * Position.Y + plane.Normal.Z * Position.Z; var distance = -(normalDotPosition + plane.D) / normalDotDirection; if (MathUtil.IsApproximatelyZero(distance)) { result = 0f; } else { if (distance < 0) { result = null; } else { result = distance; } } } }
/// <summary> /// Determines whether this <see cref="Ray"/> intersects a specified <see cref="BoundingSphere"/>. /// </summary> /// <param name="sphere">The <see cref="BoundingSphere"/> to evaluate.</param> /// <param name="result">The distance along the ray at which it intersects the sphere, or <see langword="null"/> if there is no intersection.</param> public void Intersects(ref BoundingSphere sphere, out Single?result) { var radiusSquared = sphere.Radius * sphere.Radius; var offset = sphere.Center - Position; var offsetLengthSquared = offset.LengthSquared(); if (offsetLengthSquared < radiusSquared) { result = 0.0f; return; } Vector3.Dot(ref Direction, ref offset, out Single distanceToCenter); if (distanceToCenter < 0) { result = null; return; } var distanceToCenterSquared = distanceToCenter * distanceToCenter; var distanceToSphere = radiusSquared + distanceToCenterSquared - offsetLengthSquared; result = (distanceToSphere < 0) ? null : distanceToCenter - (Single?)Math.Sqrt(distanceToSphere); }
public Entry( [JsonProperty("boolean_type")] Boolean?booleanType, [JsonProperty("string_type")] String stringType, [JsonProperty("datetime_type")] DateTime?datetimeType, [JsonProperty("unsigned_32")] UInt32?unsigned32, [JsonProperty("unsigned_64")] UInt64?unsigned64, [JsonProperty("signed_32")] Int32?signed32, [JsonProperty("signed_64")] Int64?signed64, [JsonProperty("float_type")] Single?floatType, [JsonProperty("double_type")] Double?doubleType, [JsonProperty("bytes_type")] Byte[] bytesType, [JsonProperty("any_type")] Object anyType, [JsonProperty("array_type")] List <Entry> arrayType, [JsonProperty("array_of_array_type")] List <List <Entry> > arrayOfArrayType, [JsonProperty("map_type")] Dictionary <String, Entry> mapType ) { this.booleanType = booleanType; this.stringType = stringType; this.datetimeType = datetimeType; this.unsigned32 = unsigned32; this.unsigned64 = unsigned64; this.signed32 = signed32; this.signed64 = signed64; this.floatType = floatType; this.doubleType = doubleType; this.bytesType = bytesType; this.anyType = anyType; this.arrayType = arrayType; this.arrayOfArrayType = arrayOfArrayType; this.mapType = mapType; }
public void TestDoubleToSingleNullable() { // Test conversion of source type minimum value Double source = Double.MinValue; Assert.IsInstanceOfType(source, typeof(Double)); Single?result = source.ToSingleNullable(); // Here we would expect this conversion to fail (and return null), // since the source type's minimum value (-1.7976931348623157E+308) is less than the target type's minimum value (-3.40282347E+38). Assert.IsNull(result); // Test conversion of source type value 42 to target type source = 42d; Assert.IsInstanceOfType(source, typeof(Double)); result = source.ToSingleNullable(); Assert.AreEqual(42f, result); Assert.IsInstanceOfType(result, typeof(Single)); // Test conversion of source type maximum value source = Double.MaxValue; Assert.IsInstanceOfType(source, typeof(Double)); result = source.ToSingleNullable(); // Here we would expect this conversion to fail (and return null), // since the source type's maximum value (1.7976931348623157E+308) is greater than the target type's maximum value (3.40282347E+38). Assert.IsNull(result); }
/// <summary> /// Determines whether the nullable single value is in valid range. /// </summary> /// <param name="value">The value.</param> /// <param name="min">The min value.</param> /// <param name="max">The max value.</param> public static void IsInValidRange(Single?value, string min, string max) { if (!value.HasValue) { return; } IsInValidRange(value.Value, min, max); }
public Bier(int bierNr, string naam, int brouwerNr, int soortNr, Single?alcohol) { BierNr = bierNr; Naam = naam; BrouwerNr = brouwerNr; SoortNr = soortNr; Alcohol = alcohol; }
public void TestFuzzyNullableSingle_IsFuzzy(Single?value1, Single?value2) { var obj1 = new NullableHandlingTest(fuzzyNullableSingle: value1); var obj2 = new NullableHandlingTest(fuzzyNullableSingle: value2); Assert.Equal(obj1, obj2); Assert.Equal(obj1.GetHashCode(), obj2.GetHashCode()); }
/// <summary> /// 转换为Single类型数据(可空类型) /// </summary> /// <returns>返回值</returns> /// <param name="column">列名</param> public Single?GetSingleNullable(string column) { Single?data = (_reader.IsDBNull(_reader.GetOrdinal(column))) ? (Single?)null : Single.Parse(_reader[column].ToString()); return(data); }
private void TestFromBoolean(_Boolean x, Single?expectedValue) { _Single expr = (_Single)x; var dbExpr = (DbCastExpression)expr.DbExpression; dbExpr.Verify(x, typeof(bool?), typeof(Single?)); expr.VerifyEval(expectedValue); }
/// <summary> /// Writes a <see langword="null"/>able single-precision floating point value to the stream. /// </summary> /// <param name="writer">The <see cref="BinaryWriter"/> with which to write the value.</param> /// <param name="value">The value to write.</param> public static void Write(this BinaryWriter writer, Single?value) { writer.Write(value.HasValue); if (value.HasValue) { writer.Write(value.GetValueOrDefault()); } }
/// <summary> /// /// </summary> /// <param name="colorName"></param> /// <param name="colorCode"></param> /// <param name="significantFigure"></param> /// <param name="multiplier"></param> /// <param name="tolerancePercent"></param> public ResistorColor(RingColor colorName, string colorCode, UInt16?significantFigure, Int16?multiplier, Single?tolerancePercent) { ColorName = colorName; ColorCode = colorCode; SignificantFigure = significantFigure; Multiplier = multiplier; TolerancePercent = tolerancePercent; }
static void WriteNullableSingle(BinaryWriter bw, Single?val) { bw.Write(val != null); if (val != null) { bw.Write((Single)val); } }
internal PanelSpecification(IApi platform) { panelPhysicalSize = platform.sys_GetPrimaryPanelPhysicalSize (); panelPhysicalAspectRatio = panelPhysicalSize.HasValue ? (Single) panelPhysicalSize.Value.X / (Single) panelPhysicalSize.Value.Y : (Single?) null; panelType = platform.sys_GetPrimaryPanelType (); }
private void TestFromSingle(Single?x, Int32?expectedValue) { _Single column1 = x; _Int32 expr = (_Int32)column1; var dbExpr = (DbCastExpression)expr.DbExpression; dbExpr.Verify(column1, typeof(Single?), typeof(Int32?)); expr.VerifyEval(expectedValue); }
private static byte ToByte(Single?value) { if (value.HasValue) { return((byte)Math.Min(Math.Max(value.Value, 0), 255)); } return(0); }
private void TestFromSingle(Single?x, Double?expectedValue) { _Single column1 = x; _Double expr = (_Double)column1; var dbExpr = (DbCastExpression)expr.DbExpression; dbExpr.Verify(column1, typeof(Single?), typeof(Double?)); expr.VerifyEval(expectedValue); }
public virtual void CyclicFloat() { Single?[] array = new Single?[3]; array[0] = Single.MaxValue; array[1] = Single.MinValue; array[2] = array[0]; Single?[] result = CheckCyclic <Single?[]>(array); }
private void TestNegate(Single?x, Single?expectedValue) { _Single column = x; var expr = -column; var dbExpr = (DbUnaryExpression)expr.DbExpression; dbExpr.Verify(DbUnaryExpressionKind.Negate, column); expr.VerifyEval(expectedValue); }
private void TestCastToString(Single?x, String expectedValue) { _Single column1 = x; _String expr = (_String)column1; var dbExpr = (DbCastExpression)expr.DbExpression; dbExpr.Verify(column1, typeof(Single?), typeof(String)); expr.VerifyEval(expectedValue); }
private void TestFromString(String x, Single?expectedValue) { _String column1 = x; _Single expr = (_Single)column1; var dbExpr = (DbCastExpression)expr.DbExpression; dbExpr.Verify(column1, typeof(String), typeof(Single?)); expr.VerifyEval(expectedValue); }
private void TestFromDecimal(Decimal?x, Single?expectedValue) { _Decimal column1 = x; _Single expr = (_Single)column1; var dbExpr = (DbCastExpression)expr.DbExpression; dbExpr.Verify(column1, typeof(Decimal?), typeof(Single?)); expr.VerifyEval(expectedValue); }
private void TestFromInt32(Int32?x, Single?expectedValue) { _Int32 column1 = x; _Single expr = (_Single)column1; var dbExpr = (DbCastExpression)expr.DbExpression; dbExpr.Verify(column1, typeof(Int32?), typeof(Single?)); expr.VerifyEval(expectedValue); }
public Guid IngredientId; //KPC Shopping Ingredient ID #endregion Fields #region Constructors public PantryItem(Ingredients.IngredientUsage usage) { IngredientId = usage.Ingredient.Id; //Need to convert IngredientUsage into proper Pantry form if (usage.Amount != null) { var toUnit = Unit.GetDefaultUnitType(usage.Ingredient.ConversionType); if (UnitConverter.CanConvert(usage.Form.FormUnitType, toUnit)) { Amt = UnitConverter.Convert(usage.Amount, toUnit).SizeHigh; //Always take high amount for pantry items } else //Find conversion path { var amount = FormConversion.GetNativeAmountForUsage(usage.Ingredient, usage); Amt = UnitConverter.Convert(amount, toUnit).SizeHigh; //Always take high amount for pantry items } } else { Amt = null; } }
/// <summary> /// Specifies that subsequent comparisons should be within the specified delta. /// </summary> /// <param name="delta">The delta value to set.</param> /// <returns>The result object.</returns> public SingleResult WithinDelta(Single delta) { this.delta = delta; return this; }
/// <summary> /// Specifies that subsequent comparisons should be within the specified delta. /// </summary> /// <param name="delta">The delta value to set.</param> /// <returns>The result object.</returns> public RadiansResult WithinDelta(Single delta) { this.delta = delta; return this; }