This commit is contained in:
Hassan Aminfar 2024-04-03 21:47:57 +00:00 committed by GitHub
commit ed0eb3d5be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1864,6 +1864,19 @@ func (d *Decimal) GobDecode(data []byte) error {
return d.UnmarshalBinary(data) return d.UnmarshalBinary(data)
} }
// GoString implements fmt.GoStringer and formats %#v to be printed in Go
// source code.
func (d *Decimal) GoString() string {
if d.value.IsInt64() {
return fmt.Sprintf("decimal.New(%d,%d)", d.value.Int64(), d.exp)
}
if d.value.Sign() < 0 {
return fmt.Sprintf("decimal.NewFromBigInt(new(big.Int).Neg(new(big.Int).SetBits(%#v)),%d)", d.value.Bits(), d.exp)
}
return fmt.Sprintf("decimal.NewFromBigInt(new(big.Int).SetBits(%#v),%d)", d.value.Bits(), d.exp)
}
// StringScaled first scales the decimal then calls .String() on it. // StringScaled first scales the decimal then calls .String() on it.
// //
// Deprecated: buggy and unintuitive. Use StringFixed instead. // Deprecated: buggy and unintuitive. Use StringFixed instead.
@ -2083,6 +2096,15 @@ func (d NullDecimal) MarshalText() (text []byte, err error) {
return d.Decimal.MarshalText() return d.Decimal.MarshalText()
} }
// GoString implements fmt.GoStringer and formats %#v to be printed in Go
// source code.
func (d NullDecimal) GoString() string {
if !d.Valid {
return "decimal.NullDecimal{Valid: false}"
}
return `decimal.NewNullDecimal(` + d.Decimal.GoString() + `)`
}
// Trig functions // Trig functions
// Atan returns the arctangent, in radians, of x. // Atan returns the arctangent, in radians, of x.