Skip to content

Commit c86d464

Browse files
committed
math/big: shallow copies of Int/Rat/Float are not supported (documentation)
Fixes #28423. Change-Id: Ie57ade565d0407a4bffaa86fb4475ff083168e79 Reviewed-on: https://go-review.googlesource.com/c/145537 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 9ce87a6 commit c86d464

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/math/big/float.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const debugFloat = false // enable for debugging
4343
// precision of the argument with the largest precision value before any
4444
// rounding takes place, and the rounding mode remains unchanged. Thus,
4545
// uninitialized Floats provided as result arguments will have their
46-
// precision set to a reasonable value determined by the operands and
46+
// precision set to a reasonable value determined by the operands, and
4747
// their mode is the zero value for RoundingMode (ToNearestEven).
4848
//
4949
// By setting the desired precision to 24 or 53 and using matching rounding
@@ -56,6 +56,12 @@ const debugFloat = false // enable for debugging
5656
// The zero (uninitialized) value for a Float is ready to use and represents
5757
// the number +0.0 exactly, with precision 0 and rounding mode ToNearestEven.
5858
//
59+
// Operations always take pointer arguments (*Float) rather
60+
// than Float values, and each unique Float value requires
61+
// its own unique *Float pointer. To "copy" a Float value,
62+
// an existing (or newly allocated) Float must be set to
63+
// a new value using the Float.Set method; shallow copies
64+
// of Floats are not supported and may lead to errors.
5965
type Float struct {
6066
prec uint32
6167
mode RoundingMode

src/math/big/int.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import (
1515

1616
// An Int represents a signed multi-precision integer.
1717
// The zero value for an Int represents the value 0.
18+
//
19+
// Operations always take pointer arguments (*Int) rather
20+
// than Int values, and each unique Int value requires
21+
// its own unique *Int pointer. To "copy" an Int value,
22+
// an existing (or newly allocated) Int must be set to
23+
// a new value using the Int.Set method; shallow copies
24+
// of Ints are not supported and may lead to errors.
1825
type Int struct {
1926
neg bool // sign
2027
abs nat // absolute value of the integer

src/math/big/rat.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import (
1313

1414
// A Rat represents a quotient a/b of arbitrary precision.
1515
// The zero value for a Rat represents the value 0.
16+
//
17+
// Operations always take pointer arguments (*Rat) rather
18+
// than Rat values, and each unique Rat value requires
19+
// its own unique *Rat pointer. To "copy" a Rat value,
20+
// an existing (or newly allocated) Rat must be set to
21+
// a new value using the Rat.Set method; shallow copies
22+
// of Rats are not supported and may lead to errors.
1623
type Rat struct {
1724
// To make zero values for Rat work w/o initialization,
1825
// a zero value of b (len(b) == 0) acts like b == 1.

0 commit comments

Comments
 (0)