Esempio n. 1
0
        public void WriteFloat(double value)
        {
            this.ThrowIfDisposed();
            this.PrepareValue();

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (!this.forceFloat64 && value == (float)value)
            {
                // TODO: Increase testing coverage
                this.containerStack.IncreaseCurrentContainerLength(5);
                this.dataBuffer.WriteByte(TidFloatByte | 4);
                this.dataBuffer.WriteUint32(BitConverterEx.SingleToInt32Bits((float)value));
            }
            else
            {
                this.containerStack.IncreaseCurrentContainerLength(9);
                this.dataBuffer.WriteByte(TidFloatByte | 8);

                if (double.IsNaN(value))
                {
                    // Double.NaN is different between C# and Java
                    // For consistency, map NaN to the long value for NaN in Java
                    this.dataBuffer.WriteUint64(0x7ff8000000000000L);
                }
                else
                {
                    this.dataBuffer.WriteUint64(BitConverter.DoubleToInt64Bits(value));
                }
            }

            this.FinishValue();
        }