Example #1
0
 private void Write(BinaryWriter writer, double? value, DoubleRange valueNormalizationRange)
 {
     if (value == null)
     {
         WriteDefault(writer);
     }
     else
     {
         double currentValue = OriginalValueRange.Denormalize(valueNormalizationRange.Cut(value.Value), valueNormalizationRange);
         switch (ItemType)
         {
             case BinaryItemType.Boolean:
                 writer.Write(currentValue >= 0.5);
                 return;
             case BinaryItemType.Byte:
                 writer.Write((byte)Math.Round(currentValue));
                 return;
             case BinaryItemType.Int16:
                 writer.Write((short)Math.Round(currentValue));
                 return;
             case BinaryItemType.Int32:
                 writer.Write((int)Math.Round(currentValue));
                 return;
             case BinaryItemType.Int64:
                 writer.Write((long)Math.Round(currentValue));
                 return;
             case BinaryItemType.UInt16:
                 writer.Write((ushort)Math.Round(currentValue));
                 return;
             case BinaryItemType.UInt32:
                 writer.Write((uint)Math.Round(currentValue));
                 return;
             case BinaryItemType.UInt64:
                 writer.Write((ulong)Math.Round(currentValue));
                 return;
             case BinaryItemType.Float:
                 writer.Write((float)currentValue);
                 return;
             case BinaryItemType.Double:
                 writer.Write(currentValue);
                 return;
         }
     }
 }
Example #2
0
 protected internal override Feature CreateFeature(IEnumerator<double?> valueEnumerator, DoubleRange valueNormalizationRange)
 {
     double? value = GetNext(valueEnumerator);
     if (value.HasValue) value = (double?)OriginalValueRange.Denormalize(valueNormalizationRange.Cut(value.Value), valueNormalizationRange);
     return new ValueFeature(this, value);
 }