func (bed BinaryVarintEncoderDecoder) Decode(r io.Reader, n *big.Float) error {
	var isInteger int8
	var f float64
	var exponent int32
	n.SetUint64(0)

	if err := binary.Read(r, binary.BigEndian, &isInteger); err != nil {
		return err
	}

	if isInteger <= 0 {
		var x int64
		var err error
		if x, err = binary.ReadVarint(miniByteReader{r}); err != nil {
			return err
		}
		n.SetInt64(x)
		n.SetPrec(ENCODER_DECODER_PREC)
		return nil
	} else {
		if err := binary.Read(r, binary.BigEndian, &f); err != nil {
			return err
		}
		if err := binary.Read(r, binary.BigEndian, &exponent); err != nil {
			return err
		}
		bed.tmp.SetFloat64(f)
		bed.tmp.SetPrec(ENCODER_DECODER_PREC)
		n.SetMantExp(bed.tmp, int(exponent))
		return nil
	}
}
Exemple #2
0
func (bed BinaryEncoderDecoder) Decode(r io.Reader, n *big.Float) error {
	var f float64
	var exponent int32
	n.SetUint64(0)
	if err := binary.Read(r, binary.BigEndian, &f); err != nil {
		return err
	}
	if err := binary.Read(r, binary.BigEndian, &exponent); err != nil {
		return err
	}
	bed.tmp.SetFloat64(f)
	bed.tmp.SetPrec(ENCODER_DECODER_PREC)
	n.SetMantExp(bed.tmp, int(exponent))
	return nil
}