mirror of
https://github.com/autc04/Retro68.git
synced 2024-09-16 14:57:49 +00:00
34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// This file implements encoding/decoding of Floats.
|
|
|
|
package big
|
|
|
|
import "fmt"
|
|
|
|
// MarshalText implements the encoding.TextMarshaler interface.
|
|
// Only the Float value is marshaled (in full precision), other
|
|
// attributes such as precision or accuracy are ignored.
|
|
func (x *Float) MarshalText() (text []byte, err error) {
|
|
if x == nil {
|
|
return []byte("<nil>"), nil
|
|
}
|
|
var buf []byte
|
|
return x.Append(buf, 'g', -1), nil
|
|
}
|
|
|
|
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
|
// The result is rounded per the precision and rounding mode of z.
|
|
// If z's precision is 0, it is changed to 64 before rounding takes
|
|
// effect.
|
|
func (z *Float) UnmarshalText(text []byte) error {
|
|
// TODO(gri): get rid of the []byte/string conversion
|
|
_, _, err := z.Parse(string(text), 0)
|
|
if err != nil {
|
|
err = fmt.Errorf("math/big: cannot unmarshal %q into a *big.Float (%v)", text, err)
|
|
}
|
|
return err
|
|
}
|