K2Informatics.Erlnet.OtpInputStream.read_double C# (CSharp) Method

read_double() public method

public read_double ( ) : double
return double
        public double read_double()
        {
            int tag;

            // parse the stream
            tag = read1skip_version();

            switch (tag)
            {
                case OtpExternal.newFloatTag:
                    {
                        return BitConverter.ToDouble(BitConverter.GetBytes(readBE(8)), 0);
                    }
                case OtpExternal.floatTag:
                    {
                        byte[] strbuf = new byte[31];
                        String str;
                        double val;

                        // get the string
                        this.readN(strbuf);
                        str = OtpErlangString.newString(strbuf);

                        if (!Double.TryParse(str, out val))
                        {
                            throw new OtpErlangDecodeException("Invalid float format: '" + str + "'");
                        }

                        return val;
                    }
                default:
                    throw new OtpErlangDecodeException("Wrong tag encountered, expected "
                                       + OtpExternal.newFloatTag + ", got " + tag);
            }
        }

Usage Example

Ejemplo n.º 1
0
 /**
  * Create an Erlang float from a stream containing a double encoded in
  * Erlang external format.
  *
  * @param buf
  *                the stream containing the encoded value.
  *
  * @exception OtpErlangDecodeException
  *                    if the buffer does not contain a valid external
  *                    representation of an Erlang float.
  */
 public OtpErlangDouble(OtpInputStream buf)
 {
     d = buf.read_double();
 }