1
0
mirror of https://github.com/golang/go synced 2024-10-02 06:18:32 -06:00
Commit Graph

194 Commits

Author SHA1 Message Date
Robert Griesemer
3858efcc58 math/big: use correct precision in Float.Float32/64 for denormals
When a big.Float is converted to a denormal float32/64, the rounding
precision depends on the size of the denormal. Rounding may round up
and thus change the size (exponent) of the denormal. Recompute the
correct precision again for correct placement of the mantissa.

Fixes #14553.

Change-Id: Iedab5810a2d2a405cc5da28c6de7be34cb035b86
Reviewed-on: https://go-review.googlesource.com/20198
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-03-04 17:39:50 +00:00
Rob Pike
0f9cc465fa math: delete unused function sqrtC
It appears to be a trivial dreg. Unreferenced. Gone.

Change-Id: I4a5ceed48e84254bc8a07fdb04487a18a0edf965
Reviewed-on: https://go-review.googlesource.com/20122
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
2016-03-03 02:29:09 +00:00
Brad Fitzpatrick
5fea2ccc77 all: single space after period.
The tree's pretty inconsistent about single space vs double space
after a period in documentation. Make it consistently a single space,
per earlier decisions. This means contributors won't be confused by
misleading precedence.

This CL doesn't use go/doc to parse. It only addresses // comments.
It was generated with:

$ perl -i -npe 's,^(\s*// .+[a-z]\.)  +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.)  +([A-Z])')
$ go test go/doc -update

Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7
Reviewed-on: https://go-review.googlesource.com/20022
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Dave Day <djd@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02 00:13:47 +00:00
Brad Fitzpatrick
519474451a all: make copyright headers consistent with one space after period
This is a subset of https://golang.org/cl/20022 with only the copyright
header lines, so the next CL will be smaller and more reviewable.

Go policy has been single space after periods in comments for some time.

The copyright header template at:

    https://golang.org/doc/contribute.html#copyright

also uses a single space.

Make them all consistent.

Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0
Reviewed-on: https://go-review.googlesource.com/20111
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-01 23:34:33 +00:00
Martin Möhrmann
fdd0179bb1 all: fix typos and spelling
Change-Id: Icd06d99c42b8299fd931c7da821e1f418684d913
Reviewed-on: https://go-review.googlesource.com/19829
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-02-24 18:42:29 +00:00
Nathan VanBenschoten
b04f3b06ec all: replace strings.Index with strings.Contains where possible
Change-Id: Ia613f1c37bfce800ece0533a5326fca91d99a66a
Reviewed-on: https://go-review.googlesource.com/18120
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
2016-02-19 01:06:05 +00:00
Russ Cox
1e066cad1b math/big: fix Exp(x, x, x) for certain large x
Fixes #13907.

Change-Id: Ieaa5183f399b12a9177372212adf481c8f0b4a0d
Reviewed-on: https://go-review.googlesource.com/18491
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Vlad Krasnov <vlad@cloudflare.com>
Reviewed-by: Adam Langley <agl@golang.org>
2016-01-13 01:43:35 +00:00
Robert Griesemer
5e059d1c31 math/big: fix typo in comment
Fixes #13875.

Change-Id: Icbb85c858d0bc545499a2b31622e9e7abdd7e5f9
Reviewed-on: https://go-review.googlesource.com/18441
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-08 20:18:10 +00:00
Russ Cox
04d732b4c2 build: shorten a few packages with long tests
Takes 3% off my all.bash run time.

For #10571.

Change-Id: I8f00f523d6919e87182d35722a669b0b96b8218b
Reviewed-on: https://go-review.googlesource.com/18087
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-12-29 15:46:44 +00:00
Russ Cox
6bcec09ceb math/big: additional Montgomery cleanup
Also fix bug reported in CL 17510.

Found during fix of #13515 in CL 17672, but separate from the fix.

Change-Id: I4b1024569a98f5cfd2ebb442ec3d64356164d284
Reviewed-on: https://go-review.googlesource.com/17673
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-12-16 20:25:29 +00:00
Russ Cox
4306352182 math/big: fix carry propagation in Int.Exp Montgomery code
Fixes #13515.

Change-Id: I7dd5fbc816e5ea135f7d81f6735e7601f636fe4f
Reviewed-on: https://go-review.googlesource.com/17672
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-12-11 17:24:29 +00:00
David Chase
38255cbd1b math/rand: improve uniformity of rand.Float64,Float32
Replaced code that substituted 0 for rounded-up 1 with
code to try again.  This has minimal effect on the existing
stream of random numbers, but restores uniformity.

Fixes #12290.

Change-Id: Ib68f0b0a4a173339bcd0274cc16509f7b0977de8
Reviewed-on: https://go-review.googlesource.com/17670
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-12-11 15:17:42 +00:00
Russ Cox
0816432918 math/big: fix misuse of Unicode
ˆ (U+02C6) is a circumflex accent, not an exponentiation operator.
In the rest of the source code for this package, exponentation is
written as **, so do the same here.

Change-Id: I107b85be242ab79d152eb8a6fcf3ca2b197d7658
Reviewed-on: https://go-review.googlesource.com/17671
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-12-11 03:37:57 +00:00
Brad Fitzpatrick
7e1791b97f math/big: fix typo
Found by github user asukakenji.

Change-Id: I4c76316b69e8a243fb6bf280283f3722e728d853
Reviewed-on: https://go-review.googlesource.com/17641
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-12-09 16:59:52 +00:00
Jingguo Yao
fb01ad21c2 math/rand: add a comment for the i=0 iteration
Fixes #13215

Change-Id: I126117d42e7c1e69cbc7fad0760e225b03ed15bd
Reviewed-on: https://go-review.googlesource.com/16852
Reviewed-by: Keith Randall <khr@golang.org>
2015-11-15 08:21:29 +00:00
Yao Zhang
4a25f6ca05 math, math/big: added support for mips64{,le}
Change-Id: I5129a5b9dbbc57d97da723c2fc247bd28f951817
Reviewed-on: https://go-review.googlesource.com/14451
Reviewed-by: Minux Ma <minux@golang.org>
2015-11-12 04:49:57 +00:00
Matthew Dempsky
7832c82bf5 math: fix bad shift in Expm1
Noticed by cmd/vet.

Expected values array produced by Python instead of Keisan because:

1) Keisan's website calculator is painfully difficult to copy/paste
values into and out of, and

2) after tediously computing e^(vf[i] * 10) - 1 via Keisan I
discovered that Keisan computing vf[i]*10 in a higher precision was
giving substantially different output values.

Also, testing uses "close" instead of "veryclose" because 386's
assembly implementation produces values for some of the test cases
that fail "veryclose".  Curiously, Expm1(vf[i]*10) is identical to
Exp(vf[i]*10)-1 on 386, whereas with the portable implementation
they're only "veryclose".

Investigating these questions is left to someone else.  I just wanted
to fix the cmd/vet warning.

Fixes #13101.

Change-Id: Ica8f6c267d01aa4cc31f53593e95812746942fbc
Reviewed-on: https://go-review.googlesource.com/16505
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Klaus Post <klauspost@gmail.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-10-30 22:55:19 +00:00
Brad Fitzpatrick
a59a27564b math: fix typo and braino in my earlier commit
The bug number was a typo, and I forgot to switch the implementation
back to if statements after the change from Float64bits in the first
patchset back to branching.

if statements can currently be inlined, but switch cannot (#13071)

Change-Id: I81d0cf64bda69186c3d747a07047f6a694f8fa70
Reviewed-on: https://go-review.googlesource.com/16446
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-10-29 21:12:08 +00:00
Brad Fitzpatrick
6f8a66536b math: replace assembly implementations of Abs with pure Go version
The compiler can do a fine job, and can also inline it.

From Jeremy Jackins's observation and rsc's recommendation in thread:

"Pure Go math.Abs outperforms assembly version"
https://groups.google.com/forum/#!topic/golang-dev/nP5mWvwAXZo

Updates #13095

Change-Id: I3066f8eaa327bb403173b29791cc8661d7c0532c
Reviewed-on: https://go-review.googlesource.com/16444
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-10-29 19:44:59 +00:00
Caleb Spare
22d4c8bf13 math: fix normalization bug in pure-Go sqrt
Fixes #13013

Change-Id: I6cf500eacdce76e303fc1cd92dd1c80eef0986bc
Reviewed-on: https://go-review.googlesource.com/16158
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-10-23 18:29:10 +00:00
David Crawshaw
e4feb18fc2 math/big: fix SetMantExp comment
Change-Id: If30cf9c94b58e18564db46c15c6f5cc14ec1a6fa
Reviewed-on: https://go-review.googlesource.com/16271
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-10-23 16:38:27 +00:00
Charlie Dorian
6fed2a68f7 math: Modf(-0) returns -0,-0
Fixes #12867

Change-Id: I8ba81c622bce2a77a6142f941603198582eaf8a4
Reviewed-on: https://go-review.googlesource.com/15570
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-10-09 17:09:16 +00:00
Charlie Dorian
1ef9b5a5b9 math/cmplx: make error tolerance test function of expected value
Copy math package CL 12230 to cmplx package.

Change-Id: I3345b782b84b5b98e2b6a60d8774c7e7cede2891
Reviewed-on: https://go-review.googlesource.com/15500
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-10-07 18:41:11 +00:00
Damian Gryski
2fd016422e math/big: check return value from quick.Check() for GCD tests
Change-Id: I46c12aaaf453365c157604dfb1486605cfefd7af
Reviewed-on: https://go-review.googlesource.com/15263
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-10-03 16:06:44 +00:00
Ilya Tocar
37cfb2e07e math: optimize ceil/floor functions on amd64
Use SSE 4.1 rounding instruction to perform rounding
Results (haswell):

name      old time/op  new time/op  delta
Floor-48  2.71ns ± 0%  1.87ns ± 1%  -31.17%  (p=0.000 n=16+19)
Ceil-48   3.09ns ± 3%  2.16ns ± 0%  -30.16%  (p=0.000 n=19+12)

Change-Id: If63715879eed6530b1eb4fc96132d827f8f43909
Reviewed-on: https://go-review.googlesource.com/14561
Reviewed-by: Klaus Post <klauspost@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2015-10-03 15:55:08 +00:00
Adam Langley
5d5889c4d9 math/big: correct documentation for ProbablyPrime.
As akalin points out in the bug, the comment previously claimed that the
probability that the input is prime given that the function returned
true is 1 - ¼ⁿ. But that's wrong: the correct statement is that the
probability of the function returning false given a composite input is
1 - ¼ⁿ.

This is not nearly as helpful, but at least it's truthful. A number of
other (correct) expressions are suggested on the bug, but I think that
the simplier one is preferable.

This change also notes that the function is not suitable for
adversarial inputs since it's deterministic.

Fixes #12274.

Change-Id: I6a0871d103b126ee5a5a922a8c6993055cb7b1ed
Reviewed-on: https://go-review.googlesource.com/14052
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-09-30 00:39:00 +00:00
Robert Griesemer
3b9e8bb7f2 math/big: more documentation
Good enough for now.

Fixes #11241.

Change-Id: Ieb50809f104d20bcbe14daecac503f72486bec92
Reviewed-on: https://go-review.googlesource.com/15111
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-29 00:23:51 +00:00
Robert Griesemer
18563f8ab4 math/big: clean up *Int encoding tests
- more uniform naming
- test sign more deliberately
- remove superfluous test (JSON encoder always uses the JSON marshaler if present)

Change-Id: I37b1e367c01fc8bae1e06adbdb72dd366c08d5ce
Reviewed-on: https://go-review.googlesource.com/15110
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-29 00:23:31 +00:00
Robert Griesemer
38c5fd5cf8 math/big: implement Float.Text(Un)Marshaler
Fixes #12256.

Change-Id: Ie4a3337996da5c060b27530b076048ffead85f3b
Reviewed-on: https://go-review.googlesource.com/15040
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-29 00:21:45 +00:00
Robert Griesemer
3d4cd144cc math/big: improved documentation
- moved existing package documentation from nat.go to doc.go
- expanded on it

For #11241.

Change-Id: Ie75a2b0178a8904a4154307a1f5080d7efc5489a
Reviewed-on: https://go-review.googlesource.com/15042
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-28 16:27:52 +00:00
Robert Griesemer
59129c6a93 math/big: remove some string conversions in Int encoding
Change-Id: I1180aa3d30fb8563c8e6ecefeb3296af0a88f5a6
Reviewed-on: https://go-review.googlesource.com/14998
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-25 22:25:52 +00:00
Robert Griesemer
7fa5a11ea1 math/big: move Int/Rat gob/json/xml functionality in separate files
Like int/rat/float conversions, move this functionality into separate
implementation and test files.

No implementation changes besides the move.

Change-Id: If19c45f5a72a57b95cbce2329724693ae5a4807d
Reviewed-on: https://go-review.googlesource.com/14997
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-25 22:25:36 +00:00
Robert Griesemer
e937eeeccd math/big: removed more unnecessary string conversions
- renamed (nat) itoa to utoa (since that's what it is)
- added (nat) itoa that takes a sign parameter; this helps removing a few string copies
- used buffers instead of string+ in Rat conversions

Change-Id: I6b37a6b39557ae311cafdfe5c4a26e9246bde1a9
Reviewed-on: https://go-review.googlesource.com/14995
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-25 22:25:12 +00:00
Robert Griesemer
8d701f092d math/big: implement Int.Text, Int.Append
This makes the Int conversion routines match the respective strconv
and big.Float conversion routines.

Change-Id: I5cfcda1632ee52fe87c5bb75892bdda76cc3af15
Reviewed-on: https://go-review.googlesource.com/14994
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-25 22:24:49 +00:00
Robert Griesemer
b07a9efa78 math/big: faster string conversion routines
Eliminated unnecessary string conversions throughout and removed
(internal) capability for arbitrary character sets in conversion
routines (functionality was not exported and not used internally).

benchmark                         old ns/op     new ns/op     delta
BenchmarkDecimalConversion-8      198283        187085        -5.65%
BenchmarkStringPiParallel-8       46116         47822         +3.70%
BenchmarkString10Base2-8          216           166           -23.15%
BenchmarkString100Base2-8         886           762           -14.00%
BenchmarkString1000Base2-8        7296          6625          -9.20%
BenchmarkString10000Base2-8       72371         65563         -9.41%
BenchmarkString100000Base2-8      725849        672766        -7.31%
BenchmarkString10Base8-8          160           114           -28.75%
BenchmarkString100Base8-8         398           309           -22.36%
BenchmarkString1000Base8-8        2650          2244          -15.32%
BenchmarkString10000Base8-8       24974         21745         -12.93%
BenchmarkString100000Base8-8      245457        217489        -11.39%
BenchmarkString10Base10-8         337           288           -14.54%
BenchmarkString100Base10-8        1298          1046          -19.41%
BenchmarkString1000Base10-8       6200          5752          -7.23%
BenchmarkString10000Base10-8      24942         22589         -9.43%
BenchmarkString100000Base10-8     8012921       7947152       -0.82%
BenchmarkString10Base16-8         156           107           -31.41%
BenchmarkString100Base16-8        344           255           -25.87%
BenchmarkString1000Base16-8       2067          1705          -17.51%
BenchmarkString10000Base16-8      19026         16112         -15.32%
BenchmarkString100000Base16-8     184038        163457        -11.18%

Change-Id: I68bd807529bd9b985f4b6ac2a87764bcc1a7d2f7
Reviewed-on: https://go-review.googlesource.com/14926
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-24 23:07:47 +00:00
Robert Griesemer
3f7c3e01db math/big: fix test for denormalized inputs and enable more test cases
Also: removed unnecessary BUG comment (was fixed).

Change-Id: I8f11fbcb4e30a19ec5a25df742b3e25e2ee7f846
Reviewed-on: https://go-review.googlesource.com/14923
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-24 22:23:55 +00:00
Robert Griesemer
59a6ba5634 math/big: factored out an internal accessor method (cleanup), added benchmark
Current result of DecimalConversion benchmark (for future reference):

BenchmarkDecimalConversion-8	   10000	    204770 ns/op

Measured on Mac Mini (late 2012) running OS X 10.10.5,
2.3 GHz Intel Core i7, 8 GB 1333 MHz DDR3.

Also: Removed comment suggesting to implement decimal by representing
digits as numbers 0..9 rather than ASCII chars '0'..'9' to avoid
repeated +/-'0' operations. Tried and it appears (per above benchmark)
that the +/-'0' operations are neglibile but the addition conversion
passes around it are not and that it makes things significantly slower.

Change-Id: I6ee033b1172043248093cc5d02abff5fc54c2e7a
Reviewed-on: https://go-review.googlesource.com/14857
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-23 20:25:59 +00:00
Robert Griesemer
4fc9565ffc math/big: implement negative precision for Float.Append/Text
Enabled all but a handful of disabled Float formatting test cases.

Fixes #10991.

Change-Id: Id18e160e857be2743429a377000e996978015a1a
Reviewed-on: https://go-review.googlesource.com/14850
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-23 16:45:38 +00:00
Robert Griesemer
b5d94b7d41 math/big: add test cases for min/max exponent values
Change-Id: I2e74e39628285e2fecaab712be6cff230619a6c2
Reviewed-on: https://go-review.googlesource.com/14778
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-22 07:59:02 +00:00
Robert Griesemer
16b3675bc8 math/big: optimize Float.Parse by reducing powers of 10 to powers of 2 and 5
Instead of computing the final adjustment factor as a power of 10,
it's more efficient to split 10**e into 2**e * 5**e . Powers of 2
are trivially added to the Float exponent, and powers of 5 are
smaller and thus faster to compute.

Also, use a table of uint64 values rather than float64 values for
initial power value. uint64 values appear to be faster to convert
to Floats (useful for small exponents).

Added two small benchmarks to confirm that there's no regresssion.

benchmark                         old ns/op     new ns/op     delta
BenchmarkParseFloatSmallExp-8     17543         16220         -7.54%
BenchmarkParseFloatLargeExp-8     60865         59996         -1.43%

Change-Id: I3efd7556b023316f86f334137a67fe0c6d52f8ef
Reviewed-on: https://go-review.googlesource.com/14782
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-09-22 05:48:02 +00:00
Spencer Nelson
f9e404c1c5 math/rand: make Rand fulfill the Reader interface
Add a Read function to Rand which reads random bytes into a buffer.

Fixes #8330

Change-Id: I85b90277b8be9287c6697def8dbefe0029b6ee06
Reviewed-on: https://go-review.googlesource.com/14522
Reviewed-by: Rob Pike <r@golang.org>
2015-09-16 17:54:01 +00:00
Alberto Donizetti
3d5bed2726 math/big: Add small complete example of big.Rat usage
Updates #11241

Change-Id: If71f651f3b8aca432c91314358b93f195217d9ec
Reviewed-on: https://go-review.googlesource.com/14317
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-09-15 17:46:22 +00:00
Rob Pike
67ddae87b9 all: use one 'l' when cancelling everywhere except Solaris
Fixes #11626.

Change-Id: I1b70c0844473c3b57a53d7cca747ea5cdc68d232
Reviewed-on: https://go-review.googlesource.com/14526
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-09-11 18:31:51 +00:00
Robert Griesemer
a370fbaac6 math/big: use more direct formatting in ExampleRoundingMode, cosmetic changes
Change-Id: I3d37391af2089881a5bd4d8f3e5d434b279c272e
Reviewed-on: https://go-review.googlesource.com/14490
Reviewed-by: Chris Manghane <cmang@golang.org>
2015-09-10 22:10:41 +00:00
Konstantin Shaposhnikov
e216735dfa math/big: add example for RoundingMode
Updates #11241

Change-Id: I0614c5a9a7a4c399ad5d664f36c70c3210911905
Reviewed-on: https://go-review.googlesource.com/14356
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-09-10 19:58:29 +00:00
Konstantin Shaposhnikov
49fb8cc10c all: minor documentation tweaks for constants
Block comments appear after a block in the HTML documentation generated by
godoc. Words like "following" should be avoided.

Change-Id: Iedfad67f4b8b9c84f128b98b9b06fa76919af388
Reviewed-on: https://go-review.googlesource.com/14357
Reviewed-by: Rob Pike <r@golang.org>
2015-09-09 05:07:52 +00:00
David Leon Gil
ea0491b70a math/big: use optimized formula in ModSqrt for 3 mod 4 primes
For primes which are 3 mod 4, using Tonelli-Shanks is slower
and more complicated than using the identity

     a**((p+1)/4) mod p == sqrt(a)

For 2^450-2^225-1 and 2^10860-2^5430-1, which are 3 mod 4:

BenchmarkModSqrt225_TonelliTri      1000     1135375 ns/op
BenchmarkModSqrt225_3Mod4          10000      156009 ns/op
BenchmarkModSqrt5430_Tonelli           1  3448851386 ns/op
BenchmarkModSqrt5430_3Mod4             2   914616710 ns/op

~2.6x to 7x faster.

Fixes #11437 (which is a prime choice of issues to fix)

Change-Id: I813fb29454160483ec29825469e0370d517850c2
Reviewed-on: https://go-review.googlesource.com/11522
Reviewed-by: Adam Langley <agl@golang.org>
2015-08-29 19:11:03 +00:00
Tarmigan Casebolt
e893724e75 math: avoid unused assignment in jn.go
Change-Id: Ie4f21bcd5849e994c63ec5bbda2dee6f3ec4da12
Reviewed-on: https://go-review.googlesource.com/13891
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-08-24 14:34:36 +00:00
Robert Griesemer
e288271773 math/big: fix TestBytes test
Fixes #12231.

Change-Id: I1f07c444623cd864667e21b2fee534eacdc193bb
Reviewed-on: https://go-review.googlesource.com/13814
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-08-21 20:02:40 +00:00
Alberto Donizetti
13b5dc885b math/big: correctly handle large exponent in SetString
Even though the umul/uquo functions expect two valid, finite big.Floats
arguments, SetString was calling them with possibly Inf values, which
resulted in bogus return values.

Replace umul and udiv calls with Mul and Quo calls to fix this. Also,
fix two wrong tests.

See relevant issue on issue tracker for a detailed explanation.

Fixes #11341

Change-Id: Ie35222763a57a2d712a5f5f7baec75cab8189a53
Reviewed-on: https://go-review.googlesource.com/13778
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-08-21 18:11:22 +00:00