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);
}
}
/** * 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(); }