Skip to content

Commit

Permalink
doc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
db47h committed Jul 17, 2022
1 parent 83ef17a commit 4cdf299
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
3 changes: 2 additions & 1 deletion decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1521,8 +1521,9 @@ func (z *Decimal) round(sbit uint) {
// or when the rounding bit is zero. Avoid computation otherwise.
sbit = z.mant.sticky(r)
}
sbit &= 1 // be safe and ensure it's a single bit // cut off extra words
sbit &= 1 // be safe and ensure it's a single bit

// cut off extra words
n := (z.prec + (_DW - 1)) / _DW // mantissa length in words for desired precision
if m > n {
copy(z.mant, z.mant[m-n:]) // move n last words to front
Expand Down
20 changes: 8 additions & 12 deletions decimal_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (z *Decimal) scan(r io.ByteScanner, base int) (f *Decimal, b int, err error
default:
panic("unexpected exponent base")
}
// exp consumed - not needed anymoregri
// exp consumed - not needed anymore

// apply 10**exp10
if MinExp <= exp10 && exp10 <= MaxExp {
Expand Down Expand Up @@ -186,8 +186,8 @@ func (z *Decimal) pow2(n uint64) *Decimal {
// It sets z to the (possibly rounded) value of the corresponding floating-
// point value, and returns z, the actual base b, and an error err, if any. The
// entire string (not just a prefix) must be consumed for success. If z's
// precision is 0, it is changed to fit all digits of the mantissa before
// rounding takes effect. The number must be of the form:
// precision is 0, it is changed to DefaultDecimalPrec before rounding takes
// effect. The number must be of the form:
//
// number = [ sign ] ( float | "inf" | "Inf" ) .
// sign = "+" | "-" .
Expand All @@ -214,26 +214,22 @@ func (z *Decimal) pow2(n uint64) *Decimal {
// of 'p' or 'P', if present (an "e" or "E" exponent indicator cannot be
// distinguished from a mantissa digit).
//
// Note that rounding only happens if z's precision is not zero and less than
// the number of digits in the mantissa or with a base 2 exponent, in which case
// it is best to use ParseFloat then z.SetFloat.
//
// The returned *Decimal f is nil and the value of z is valid but not defined if
// The returned *Decimal d is nil and the value of z is valid but not defined if
// an error is reported.
//
func (z *Decimal) Parse(s string, base int) (f *Decimal, b int, err error) {
func (z *Decimal) Parse(s string, base int) (d *Decimal, b int, err error) {
// scan doesn't handle ±Inf
if len(s) == 3 && (s == "Inf" || s == "inf") {
f = z.SetInf(false)
d = z.SetInf(false)
return
}
if len(s) == 4 && (s[0] == '+' || s[0] == '-') && (s[1:] == "Inf" || s[1:] == "inf") {
f = z.SetInf(s[0] == '-')
d = z.SetInf(s[0] == '-')
return
}

r := strings.NewReader(s)
if f, b, err = z.scan(r, base); err != nil {
if d, b, err = z.scan(r, base); err != nil {
return
}

Expand Down
7 changes: 3 additions & 4 deletions decimal_marsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ func (x *Decimal) MarshalText() (text []byte, err error) {
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.
// 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 DefaultDecimalPrec before rounding takes effect.
func (z *Decimal) UnmarshalText(text []byte) error {
// TODO(db47h): get rid of the []byte/string conversion
_, _, err := z.Parse(string(text), 0)
Expand Down

0 comments on commit 4cdf299

Please sign in to comment.