Skip to content

Commit

Permalink
Documentation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
db47h committed May 21, 2020
1 parent cbe90f1 commit 33232a6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
const debugDecimal = true // enable for debugging

// DefaultDecimalPrec is the default minimum precision used when creating a new
// Decimal from a *big.Int, uint64, int64, or string. An uint64 requires up to
// 20 digits, which amounts to 2 x 19-digits Words (64 bits) or 3 x 9-digits
// Words (32 bits). Forcing the precision to 20 digits would result in 18 or 7
// unused digits. Using 34 instead gives a higher precision at no performance or
// memory cost on 64 bits platforms (but one more Word on 32 bits) and gives
// room for 2 to 4 extra digits of extra precision for internal computations at
// no added performance or memory cost. Also 34 digits matches the precision of
// IEEE-754 decimal128.
// Decimal from a *big.Int, *big.Rat, uint64, int64, or string. An uint64
// requires up to 20 digits, which amounts to 2 x 19-digits Words (64 bits) or 3
// x 9-digits Words (32 bits). Forcing the precision to 20 digits would result
// in 18 or 7 unused digits. Using 34 instead gives a higher precision at no
// performance or memory cost on 64 bits platforms (but one more Word on 32
// bits) and gives room for 2 to 4 extra digits of extra precision for internal
// computations at no added performance or memory cost. Also 34 digits matches
// the precision of IEEE-754 decimal128.
const DefaultDecimalPrec = 34

var decimalZero Decimal
Expand Down Expand Up @@ -892,7 +892,7 @@ func (z *Decimal) Set(x *Decimal) *Decimal {
// Conversion is performed using z's precision and rounding mode. Caveat: as a
// result this may lead to inconsistencies between the ouputs of x.Text and
// z.Text. To preserve this property, the conversion should be done using x's
// precision and rounding mode ToNearestEven:
// precision and rounding mode set to ToNearestEven:
//
// p, m := z.Prec(), z.Mode()
// z.SetPrec(0).SetMode(ToNearestEven).SetFloat(x)
Expand Down Expand Up @@ -942,7 +942,7 @@ func (z *Decimal) SetFloat(x *big.Float) *Decimal {
// SetFloat64 sets z to the (possibly rounded) value of x and returns z. If z's
// precision is 0, it is changed to 17 (and rounding will have no effect).
// SetFloat64 panics with ErrNaN if x is a NaN. Conversion is performed using
// z's precision and rounding mode. See caveat in (*Decimal).Float.
// z's precision and rounding mode. See caveat in (*Decimal).SetFloat.
func (z *Decimal) SetFloat64(x float64) *Decimal {
if z.prec == 0 {
z.prec = 17
Expand Down Expand Up @@ -1461,7 +1461,7 @@ func (z *Decimal) umul(x, y *Decimal) {

// Note: This is doing too much work if the precision
// of z is less than the sum of the precisions of x
// and y which is often the case (e.g., if all floats
// and y which is often the case (e.g., if all Decimals
// have the same precision).
// TODO(db47h) Optimize this for the common case.

Expand Down
2 changes: 1 addition & 1 deletion decimal_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (z *Decimal) pow2(n uint64) *Decimal {
return z
}

// Parse parses s which must contain a text representation of a floating- point
// Parse parses s which must contain a text representation of a floating-point
// number with a mantissa in the given conversion base (the exponent is always a
// decimal number), or a string representing an infinite value.
//
Expand Down
4 changes: 2 additions & 2 deletions decimal_marsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const decimalGobVersion byte = 1

// GobEncode implements the gob.GobEncoder interface.
// The Float value and all its attributes (precision,
// The Decimal value and all its attributes (precision,
// rounding mode, accuracy) are marshaled.
func (x *Decimal) GobEncode() ([]byte, error) {
if x == nil {
Expand Down Expand Up @@ -114,7 +114,7 @@ func (z *Decimal) UnmarshalText(text []byte) error {
// TODO(db47h): 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)
err = fmt.Errorf("decimal: cannot unmarshal %q into a *decimal.Decimal (%v)", text, err)
}
return err
}
2 changes: 1 addition & 1 deletion decimal_sqrt.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (z *Decimal) sqrtInverse(x *Decimal) {
u := newDecimal(z.prec)
v := newDecimal(z.prec)
for prec := z.prec + 2; t.prec < prec; {
// be less agressive than big.Float in precision increase
// be more conservative than big.Float in precision increase
// |√z - t| < 10**(-2*t.prec + 2) <= 10**-prec
t.prec = t.prec*2 - 2
u.prec = t.prec
Expand Down
12 changes: 6 additions & 6 deletions stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const (
inf
)

// RoundingMode determines how a Float value is rounded to the
// desired precision. Rounding may change the Float value; the
// rounding error is described by the Float's Accuracy.
// RoundingMode determines how a Decimal value is rounded to the
// desired precision. Rounding may change the Decimal value; the
// rounding error is described by the Decimal's Accuracy.
type RoundingMode byte

// These constants define supported rounding modes.
Expand All @@ -64,10 +64,10 @@ const (
//go:generate stringer -type=RoundingMode

// Accuracy describes the rounding error produced by the most recent
// operation that generated a Float value, relative to the exact value.
// operation that generated a Decimal value, relative to the exact value.
type Accuracy int8

// Constants describing the Accuracy of a Float.
// Constants describing the Accuracy of a Decimal.
const (
Below Accuracy = -1
Exact Accuracy = 0
Expand Down Expand Up @@ -231,7 +231,7 @@ func pow(x Word, n int) (p Word) {
return
}

// An ErrNaN panic is raised by a Float operation that would lead to
// An ErrNaN panic is raised by a Decimal operation that would lead to
// a NaN under IEEE-754 rules. An ErrNaN implements the error interface.
type ErrNaN struct {
msg string
Expand Down

0 comments on commit 33232a6

Please sign in to comment.