RiakClient.Erlang.OtpInputStream.ReadDouble C# (CSharp) Method

ReadDouble() public method

Read an Erlang float from the stream.
public ReadDouble ( ) : double
return double
        public double ReadDouble()
        {
            double d;
            byte tag = Read1SkipVersion();
            switch (tag)
            {
                case OtpExternal.FloatTag:
                    byte[] b = new byte[OtpExternal.FloatByteLength];
                    ReadN(b);
                    string ds = Encoding.ASCII.GetString(b);
                    NumberStyles style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite;
                    if (!double.TryParse(ds, style, NumberFormatInfo.InvariantInfo, out d))
                    {
                        throw new InvalidOperationException(string.Format("invalid float encoding: \"{0}\"", ds));
                    }

                    break;
                case OtpExternal.NewFloatTag:
                    d = BitConverter.Int64BitsToDouble(ReadBE(8));
                    break;
                default:
                    throw OnBadTag(tag, OtpExternal.NewFloatTag);
            }

            return d;
        }

Usage Example

 public void Read_FloatAsDouble(byte[] buf, double want)
 {
     using (var s = new OtpInputStream(buf))
     {
         double got = s.ReadDouble();
         Assert.AreEqual(want, got);
     }
 }