Source/NFX.Erlang/ErlInputStream.cs
/// <summary>
/// Read an Erlang float from the stream
/// </summary>
Read an Erlang float from the stream
Read an Erlang float from the stream
public ErlDouble ReadDouble()
      {
        var tag = readTag();
        double value;
        switch (tag)
        {
          case ErlExternalTag.NewFloat:
            checkSpace(8);
            byte[] b;
            int offset;
            if (BitConverter.IsLittleEndian)
            {
              b = new byte[8];
              offset = 0;
              Array.Copy(m_Buffer, m_Position, b, 0, b.Length);
              Array.Reverse(b);
            }
            else
            {
              b = m_Buffer;
              offset = m_Position;
            }
            value = BitConverter.ToDouble(b, offset);
            m_Position += 8;
            break;
          case ErlExternalTag.Float:
            checkSpace(31);
            var s = m_Encoding.GetString(m_Buffer, m_Position, 31);
            if (!double.TryParse(s, out value))
              throw new ErlException(StringConsts.ERL_INVALID_VALUE_ERROR, s);
            m_Position += 31;
            break;
          default:
            throw new ErlException(StringConsts.ERL_INVALID_TERM_TYPE_ERROR,
                "double", tag.ToString());
        }
        return new ErlDouble(value);
      }
public ErlDouble ReadDouble ( ) { var tag = readTag ( ) ; double value ; switch ( tag ) { case ErlExternalTag . NewFloat : checkSpace ( 8 ) ; byte [ ] b ; int offset ; if ( BitConverter . IsLittleEndian ) { b = new byte [ 8 ] ; offset = 0 ; Array . Copy ( m_Buffer , m_Position , b , 0 , b . Length ) ; Array . Reverse ( b ) ; } else { b = m_Buffer ; offset = m_Position ; } value = BitConverter . ToDouble ( b , offset ) ; m_Position += 8 ; break ; case ErlExternalTag . Float : checkSpace ( 31 ) ; var s = m_Encoding . GetString ( m_Buffer , m_Position , 31 ) ; if ( ! double . TryParse ( s , out value ) ) throw new ErlException ( StringConsts . ERL_INVALID_VALUE_ERROR , s ) ; m_Position += 31 ; break ; default : throw new ErlException ( StringConsts . ERL_INVALID_TERM_TYPE_ERROR , " " , tag . ToString ( ) ) ; } return new ErlDouble ( value ) ; }
Read an Erlang float from the stream
Read an Erlang float from the stream
// IEEE 754 decoder