aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorLasse Folger <lassefolger@google.com>2022-04-05 09:19:57 +0200
committerLasse Folger <lassefolger@google.com>2022-04-05 18:53:15 +0200
commit4739b353bb878f29ee78e1cd7eaf3d8f32199798 (patch)
tree40bb8ba155a8dc87b4794a4fcf224d03f555502c /src/math
parent9d6ab825f6fe125f7ce630e103b887e580403802 (diff)
parentc18f398f32c45afe2e9a81a6d885a4e0183cd649 (diff)
downloadgo-4739b353bb878f29ee78e1cd7eaf3d8f32199798.tar.xz
[dev.boringcrypto] all: merge master into dev.boringcrypto
Change-Id: Iaf618444dd2d99721c19708df9ce2c1f35854efd
Diffstat (limited to 'src/math')
-rw-r--r--src/math/big/arith_test.go2
-rw-r--r--src/math/big/float.go3
-rw-r--r--src/math/big/floatconv.go2
-rw-r--r--src/math/big/int.go6
-rw-r--r--src/math/big/intconv.go2
-rw-r--r--src/math/big/nat.go8
-rw-r--r--src/math/big/natconv.go2
-rw-r--r--src/math/big/rat.go2
-rw-r--r--src/math/big/ratconv.go2
-rw-r--r--src/math/big/ratconv_test.go9
-rw-r--r--src/math/rand/exp.go1
-rw-r--r--src/math/rand/normal.go1
-rw-r--r--src/math/rand/rand.go2
13 files changed, 15 insertions, 27 deletions
diff --git a/src/math/big/arith_test.go b/src/math/big/arith_test.go
index 7b3427f834..789b96bf35 100644
--- a/src/math/big/arith_test.go
+++ b/src/math/big/arith_test.go
@@ -510,7 +510,7 @@ func testFunVWW(t *testing.T, msg string, f funVWW, a argVWW) {
}
// TODO(gri) mulAddVWW and divWVW are symmetric operations but
-// their signature is not symmetric. Try to unify.
+// their signature is not symmetric. Try to unify.
type funWVW func(z []Word, xn Word, x []Word, y Word) (r Word)
type argWVW struct {
diff --git a/src/math/big/float.go b/src/math/big/float.go
index a8c91a6e54..70c7b794a4 100644
--- a/src/math/big/float.go
+++ b/src/math/big/float.go
@@ -236,7 +236,6 @@ func (x *Float) Acc() Accuracy {
// -1 if x < 0
// 0 if x is ±0
// +1 if x > 0
-//
func (x *Float) Sign() int {
if debugFloat {
x.validate()
@@ -1672,7 +1671,6 @@ func (z *Float) Quo(x, y *Float) *Float {
// -1 if x < y
// 0 if x == y (incl. -0 == 0, -Inf == -Inf, and +Inf == +Inf)
// +1 if x > y
-//
func (x *Float) Cmp(y *Float) int {
if debugFloat {
x.validate()
@@ -1707,7 +1705,6 @@ func (x *Float) Cmp(y *Float) int {
// 0 if x == 0 (signed or unsigned)
// +1 if 0 < x < +Inf
// +2 if x == +Inf
-//
func (x *Float) ord() int {
var m int
switch x.form {
diff --git a/src/math/big/floatconv.go b/src/math/big/floatconv.go
index 57b7df3936..93f7195219 100644
--- a/src/math/big/floatconv.go
+++ b/src/math/big/floatconv.go
@@ -153,7 +153,6 @@ func (z *Float) scan(r io.ByteScanner, base int) (f *Float, b int, err error) {
// for p, q := uint64(0), uint64(1); p < q; p, q = q, q*5 {
// fmt.Println(q)
// }
-//
var pow5tab = [...]uint64{
1,
5,
@@ -257,7 +256,6 @@ func (z *Float) pow5(n uint64) *Float {
//
// The returned *Float f is nil and the value of z is valid but not
// defined if an error is reported.
-//
func (z *Float) Parse(s string, base int) (f *Float, b int, err error) {
// scan doesn't handle ±Inf
if len(s) == 3 && (s == "Inf" || s == "inf") {
diff --git a/src/math/big/int.go b/src/math/big/int.go
index 7647346486..700d00d031 100644
--- a/src/math/big/int.go
+++ b/src/math/big/int.go
@@ -34,7 +34,6 @@ var intOne = &Int{false, natOne}
// -1 if x < 0
// 0 if x == 0
// +1 if x > 0
-//
func (x *Int) Sign() int {
if len(x.abs) == 0 {
return 0
@@ -234,7 +233,6 @@ func (z *Int) Rem(x, y *Int) *Int {
//
// (See Daan Leijen, ``Division and Modulus for Computer Scientists''.)
// See DivMod for Euclidean division and modulus (unlike Go).
-//
func (z *Int) QuoRem(x, y, r *Int) (*Int, *Int) {
z.abs, r.abs = z.abs.div(r.abs, x.abs, y.abs)
z.neg, r.neg = len(z.abs) > 0 && x.neg != y.neg, len(r.abs) > 0 && x.neg // 0 has no sign
@@ -292,7 +290,6 @@ func (z *Int) Mod(x, y *Int) *Int {
// Systems (TOPLAS), 14(2):127-144, New York, NY, USA, 4/1992.
// ACM press.)
// See QuoRem for T-division and modulus (like Go).
-//
func (z *Int) DivMod(x, y, m *Int) (*Int, *Int) {
y0 := y // save y
if z == y || alias(z.abs, y.abs) {
@@ -316,7 +313,6 @@ func (z *Int) DivMod(x, y, m *Int) (*Int, *Int) {
// -1 if x < y
// 0 if x == y
// +1 if x > y
-//
func (x *Int) Cmp(y *Int) (r int) {
// x cmp y == x cmp y
// x cmp (-y) == x
@@ -343,7 +339,6 @@ func (x *Int) Cmp(y *Int) (r int) {
// -1 if |x| < |y|
// 0 if |x| == |y|
// +1 if |x| > |y|
-//
func (x *Int) CmpAbs(y *Int) int {
return x.abs.cmp(y.abs)
}
@@ -420,7 +415,6 @@ func (x *Int) IsUint64() bool {
// Incorrect placement of underscores is reported as an error if there
// are no other errors. If base != 0, underscores are not recognized
// and act like any other character that is not a valid digit.
-//
func (z *Int) SetString(s string, base int) (*Int, bool) {
return z.setFromScanner(strings.NewReader(s), base)
}
diff --git a/src/math/big/intconv.go b/src/math/big/intconv.go
index 0567284105..2fe10ff0a2 100644
--- a/src/math/big/intconv.go
+++ b/src/math/big/intconv.go
@@ -63,7 +63,6 @@ var _ fmt.Formatter = intOne // *Int must implement fmt.Formatter
// specification of minimum digits precision, output field
// width, space or zero padding, and '-' for left or right
// justification.
-//
func (x *Int) Format(s fmt.State, ch rune) {
// determine base
var base int
@@ -178,7 +177,6 @@ func (x *Int) Format(s fmt.State, ch rune) {
// ``0b'' or ``0B'' selects base 2; a ``0'', ``0o'', or ``0O'' prefix selects
// base 8, and a ``0x'' or ``0X'' prefix selects base 16. Otherwise the selected
// base is 10.
-//
func (z *Int) scan(r io.ByteScanner, base int) (*Int, int, error) {
// determine sign
neg, err := scanSign(r)
diff --git a/src/math/big/nat.go b/src/math/big/nat.go
index 512b2c229f..ee0c63eb28 100644
--- a/src/math/big/nat.go
+++ b/src/math/big/nat.go
@@ -31,7 +31,6 @@ import (
// During arithmetic operations, denormalized values may occur but are
// always normalized before returning the final result. The normalized
// representation of 0 is the empty or nil slice (length = 0).
-//
type nat []Word
var (
@@ -363,10 +362,11 @@ func karatsuba(z, x, y nat) {
}
// 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).
+// 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 {
return cap(x) > 0 && cap(y) > 0 && &x[0:cap(x)][cap(x)-1] == &y[0:cap(y)][cap(y)-1]
}
diff --git a/src/math/big/natconv.go b/src/math/big/natconv.go
index 42d1cccf6f..99488ac833 100644
--- a/src/math/big/natconv.go
+++ b/src/math/big/natconv.go
@@ -105,7 +105,6 @@ var (
// parsed. A digit count <= 0 indicates the presence of a period (if fracOk
// is set, only), and -count is the number of fractional digits found.
// In this case, the actual value of the scanned number is res * b**count.
-//
func (z nat) scan(r io.ByteScanner, base int, fracOk bool) (res nat, b, count int, err error) {
// reject invalid bases
baseOk := base == 0 ||
@@ -366,7 +365,6 @@ func (x nat) itoa(neg bool, base int) []byte {
// range 2..64 shows that values of 8 and 16 work well, with a 4x speedup at medium lengths and
// ~30x for 20000 digits. Use nat_test.go's BenchmarkLeafSize tests to optimize leafSize for
// specific hardware.
-//
func (q nat) convertWords(s []byte, b Word, ndigits int, bb Word, table []divisor) {
// split larger blocks recursively
if table != nil {
diff --git a/src/math/big/rat.go b/src/math/big/rat.go
index 731a979ff7..e77da67d1b 100644
--- a/src/math/big/rat.go
+++ b/src/math/big/rat.go
@@ -392,7 +392,6 @@ func (z *Rat) Inv(x *Rat) *Rat {
// -1 if x < 0
// 0 if x == 0
// +1 if x > 0
-//
func (x *Rat) Sign() int {
return x.a.Sign()
}
@@ -482,7 +481,6 @@ func (z *Int) scaleDenom(x *Int, f nat) {
// -1 if x < y
// 0 if x == y
// +1 if x > y
-//
func (x *Rat) Cmp(y *Rat) int {
var a, b Int
a.scaleDenom(&x.a, y.b.abs)
diff --git a/src/math/big/ratconv.go b/src/math/big/ratconv.go
index 90053a9c81..dadd4d7b8e 100644
--- a/src/math/big/ratconv.go
+++ b/src/math/big/ratconv.go
@@ -113,7 +113,7 @@ func (z *Rat) SetString(s string) (*Rat, bool) {
// special-case 0 (see also issue #16176)
if len(z.a.abs) == 0 {
- return z, true
+ return z.norm(), true
}
// len(z.a.abs) > 0
diff --git a/src/math/big/ratconv_test.go b/src/math/big/ratconv_test.go
index e55e655718..45a35608f4 100644
--- a/src/math/big/ratconv_test.go
+++ b/src/math/big/ratconv_test.go
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"math"
+ "reflect"
"strconv"
"strings"
"testing"
@@ -205,6 +206,14 @@ func TestRatSetString(t *testing.T) {
}
}
+func TestRatSetStringZero(t *testing.T) {
+ got, _ := new(Rat).SetString("0")
+ want := new(Rat).SetInt64(0)
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("got %#+v, want %#+v", got, want)
+ }
+}
+
func TestRatScan(t *testing.T) {
var buf bytes.Buffer
for i, test := range setStringTests {
diff --git a/src/math/rand/exp.go b/src/math/rand/exp.go
index 5a8d946c0c..9a07ba1be0 100644
--- a/src/math/rand/exp.go
+++ b/src/math/rand/exp.go
@@ -27,7 +27,6 @@ const (
// callers can adjust the output using:
//
// sample = ExpFloat64() / desiredRateParameter
-//
func (r *Rand) ExpFloat64() float64 {
for {
j := r.Uint32()
diff --git a/src/math/rand/normal.go b/src/math/rand/normal.go
index 2c5a7aa99b..48ecdd5adb 100644
--- a/src/math/rand/normal.go
+++ b/src/math/rand/normal.go
@@ -34,7 +34,6 @@ func absInt32(i int32) uint32 {
// adjust the output using:
//
// sample = NormFloat64() * desiredStdDev + desiredMean
-//
func (r *Rand) NormFloat64() float64 {
for {
j := int32(r.Uint32()) // Possibly negative
diff --git a/src/math/rand/rand.go b/src/math/rand/rand.go
index 13f20ca5ef..dfbd1fa4e7 100644
--- a/src/math/rand/rand.go
+++ b/src/math/rand/rand.go
@@ -366,7 +366,6 @@ func Read(p []byte) (n int, err error) { return globalRand.Read(p) }
// adjust the output using:
//
// sample = NormFloat64() * desiredStdDev + desiredMean
-//
func NormFloat64() float64 { return globalRand.NormFloat64() }
// ExpFloat64 returns an exponentially distributed float64 in the range
@@ -376,7 +375,6 @@ func NormFloat64() float64 { return globalRand.NormFloat64() }
// callers can adjust the output using:
//
// sample = ExpFloat64() / desiredRateParameter
-//
func ExpFloat64() float64 { return globalRand.ExpFloat64() }
type lockedSource struct {