ReadFloat64 reads a float64 from the reader. (If the value on the wire is encoded as a float32, it will be up-cast to a float64.)
()
| 585 | // (If the value on the wire is encoded as a float32, |
| 586 | // it will be up-cast to a float64.) |
| 587 | func (m *Reader) ReadFloat64() (f float64, err error) { |
| 588 | var p []byte |
| 589 | p, err = m.R.Peek(9) |
| 590 | if err != nil { |
| 591 | // we'll allow a conversion from float32 to float64, |
| 592 | // since we don't lose any precision |
| 593 | if err == io.EOF && len(p) > 0 && p[0] == mfloat32 { |
| 594 | ef, err := m.ReadFloat32() |
| 595 | return float64(ef), err |
| 596 | } |
| 597 | return |
| 598 | } |
| 599 | if p[0] != mfloat64 { |
| 600 | // see above |
| 601 | if p[0] == mfloat32 { |
| 602 | ef, err := m.ReadFloat32() |
| 603 | return float64(ef), err |
| 604 | } |
| 605 | err = badPrefix(Float64Type, p[0]) |
| 606 | return |
| 607 | } |
| 608 | f = math.Float64frombits(getMuint64(p)) |
| 609 | _, err = m.R.Skip(9) |
| 610 | return |
| 611 | } |
| 612 | |
| 613 | // ReadFloat32 reads a float32 from the reader |
| 614 | func (m *Reader) ReadFloat32() (f float32, err error) { |