mirror of
https://github.com/golang/go.git
synced 2025-05-20 23:03:26 +00:00
math/big: add comment about internal assumptions on nat values
Change-Id: I7ed40507a019c0bf521ba748fc22c03d74bb17b7 Reviewed-on: https://go-review.googlesource.com/100719 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
b46d398887
commit
7d4d2cb686
@ -5,6 +5,11 @@
|
|||||||
// This file implements unsigned multi-precision integers (natural
|
// This file implements unsigned multi-precision integers (natural
|
||||||
// numbers). They are the building blocks for the implementation
|
// numbers). They are the building blocks for the implementation
|
||||||
// of signed integers, rationals, and floating-point numbers.
|
// of signed integers, rationals, and floating-point numbers.
|
||||||
|
//
|
||||||
|
// Caution: This implementation relies on the function "alias"
|
||||||
|
// which assumes that (nat) slice capacities are never
|
||||||
|
// changed (no 3-operand slice expressions). If that
|
||||||
|
// changes, alias needs to be updated for correctness.
|
||||||
|
|
||||||
package big
|
package big
|
||||||
|
|
||||||
@ -352,6 +357,10 @@ func karatsuba(z, x, y nat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// alias reports whether x and y share the same base array.
|
// alias reports whether x and y share the same base array.
|
||||||
|
// Note: alias assumes that the capacity of underlying arrays
|
||||||
|
// is never changed for nat values; i.e. that there are
|
||||||
|
// no 3-operand slice expressions in this code (or worse,
|
||||||
|
// reflect-based operations to the same effect).
|
||||||
func alias(x, y nat) bool {
|
func alias(x, y nat) bool {
|
||||||
return cap(x) > 0 && cap(y) > 0 && &x[0:cap(x)][cap(x)-1] == &y[0:cap(y)][cap(y)-1]
|
return cap(x) > 0 && cap(y) > 0 && &x[0:cap(x)][cap(x)-1] == &y[0:cap(y)][cap(y)-1]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user