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

416 Commits

Author SHA1 Message Date
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
Robert Griesemer
92eb34b59a math/big: remove superfluous comparison
This is not a functional change.

Also:
- minor cleanups, better comments
- uniform spelling of noun "zeros" (per OED)

Fixes #11277.

Change-Id: I1726f358ce15907bd2410f646b02cf8b11b919cd
Reviewed-on: https://go-review.googlesource.com/11267
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-08-21 17:46:46 +00:00
Andrey Petrov
7cabaded51 math/rand: warn against using package for security-sensitive work
Urge users of math/rand to consider using crypto/rand when doing
security-sensitive work.

Related to issue #11871. While we haven't reached consensus on how
to make the package inherently safer, everyone agrees that the docs
for math/rand can be improved.

Change-Id: I576a312e51b2a3445691da6b277c7b4717173197
Reviewed-on: https://go-review.googlesource.com/12900
Reviewed-by: Rob Pike <r@golang.org>
2015-07-30 12:42:18 +00:00
Robert Griesemer
f35bc3ee87 math/big: document rounding for Rat.FloatToString
Fixes #11523.

Change-Id: I172f6facd555a1c6db76f25d5097343c20dea59a
Reviewed-on: https://go-review.googlesource.com/12507
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-22 19:47:19 +00:00
Russ Cox
bed6326a3c math: fix Log2 test failures on ppc64 (and s390)
- Make Log2 exact for powers of two.
- Fix error tolerance function to make tolerance
  a function of the correct (expected) value.

Fixes #9066.

Change-Id: I0320a93ce4130deed1c7b7685627d51acb7bc56d
Reviewed-on: https://go-review.googlesource.com/12230
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-15 05:35:22 +00:00
Brad Fitzpatrick
783297ad6a all: link to https for golang subdomains too
The previous commit (git 2ae77376) just did golang.org.  This one
includes golang.org subdomains like blog, play, and build.

Change-Id: I4469f7b307ae2a12ea89323422044e604c5133ae
Reviewed-on: https://go-review.googlesource.com/12071
Reviewed-by: Rob Pike <r@golang.org>
2015-07-12 04:42:40 +00:00
Brad Fitzpatrick
2ae77376f7 all: link to https instead of http
The one in misc/makerelease/makerelease.go is particularly bad and
probably warrants rotating our keys.

I didn't update old weekly notes, and reverted some changes involving
test code for now, since we're late in the Go 1.5 freeze. Otherwise,
the rest are all auto-generated changes, and all manually reviewed.

Change-Id: Ia2753576ab5d64826a167d259f48a2f50508792d
Reviewed-on: https://go-review.googlesource.com/12048
Reviewed-by: Rob Pike <r@golang.org>
2015-07-11 14:36:33 +00:00
Charlie Dorian
8b221092b9 math: Expm1 returns -1 with large negative argument.
Fixes #11442

Change-Id: I2053fe752c6a122924d28565f1338f73e00ed417
Reviewed-on: https://go-review.googlesource.com/11791
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-10 22:22:24 +00:00
Josh Bleecher Snyder
71832ff489 math/rand: improve NewZipf documentation
Change-Id: I78f0f9ac33db153c4a0d7f9866da20ebcd3d3639
Reviewed-on: https://go-review.googlesource.com/11872
Reviewed-by: Rob Pike <r@golang.org>
2015-07-03 21:39:04 +00:00
Andrew Gerrand
895df143a2 math: explain OEIS link
Fixes #10236

Change-Id: Ife85513efda48af81c267b753da2ac7317cdfe75
Reviewed-on: https://go-review.googlesource.com/11479
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-26 01:25:58 +00:00
Robert Griesemer
1eb8c4aa44 math/big: fix GCD in presence of aliasing
Fixes #11284.

Change-Id: I4ecc4e4cd3c1b3467b43e4ba9666ea6db5fb61a5
Reviewed-on: https://go-review.googlesource.com/11268
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-19 19:53:45 +00:00
Andrew Gerrand
0c247bf41b math/big: refine Fibonacci example
Change-Id: Id9e8c3f89e021b9f389ab3c8403e6a8450fa9f5f
Reviewed-on: https://go-review.googlesource.com/11231
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-18 22:16:16 +00:00
ALTree
ee1ef8fe67 math/big: Add small complete example of big.Float usage
Updates #11241

Change-Id: I573be85d0cfcf410f6125ecd2be8a3d292c40bbb
Reviewed-on: https://go-review.googlesource.com/11245
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-18 21:08:41 +00:00
Robert Griesemer
bbf79575a5 math/big: incorporate feedback by josharian (Example_fibonacci)
Change-Id: I376ff39594b532a5490f13e3985b7a6ff4b6761d
Reviewed-on: https://go-review.googlesource.com/11191
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-17 20:29:35 +00:00
ALTree
f0fee976aa math/big: Added small complete example of big.Int usage
Updates #11241

Change-Id: I9639c4f66cf805a57b087c9f648d3918df105d86
Reviewed-on: https://go-review.googlesource.com/11034
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-17 19:42:06 +00:00
Austin Clements
2774b37306 all: use RET instead of RETURN on ppc64
All of the architectures except ppc64 have only "RET" for the return
mnemonic. ppc64 used to have only "RETURN", but commit cf06ea6
introduced RET as a synonym for RETURN to make ppc64 consistent with
the other architectures. However, that commit was never followed up to
make the code itself consistent by eliminating uses of RETURN.

This commit replaces all uses of RETURN in the ppc64 assembly with
RET.

This was done with
    sed -i 's/\<RETURN\>/RET/' **/*_ppc64x.s
plus one manual change to syscall/asm.s.

Change-Id: I3f6c8d2be157df8841d48de988ee43f3e3087995
Reviewed-on: https://go-review.googlesource.com/10672
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
2015-06-06 00:07:23 +00:00
Robert Griesemer
c1fed8482d math/big: turn off debug mode
Change-Id: Ie38742cddc5a256e2f0fc0f720c0ed2f1b2e1bca
Reviewed-on: https://go-review.googlesource.com/10664
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-03 22:08:17 +00:00
Dave Cheney
d15597e1b2 math/big: trim trailing zeros before hex printing
m was being resliced as the result of looking for the first
non zero word of the mantissa, however m was not used later
in printing.

Spotted by Gordon Klaus, https://groups.google.com/forum/#!topic/golang-nuts/MdDLbvOjb4o

Change-Id: Ifbebb51ea5e0d86cb8e0422eb184b8634639a733
Reviewed-on: https://go-review.googlesource.com/10604
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-03 22:06:04 +00:00
Robert Griesemer
71cc675572 math/big: implement fmt.Formatter-compatible (*Float).Format
Change-Id: I22fdba8ecaecf4e9201b845e65d982cac09f254a
Reviewed-on: https://go-review.googlesource.com/10499
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-02 06:37:53 +00:00
Robert Griesemer
a63b1806aa math/big: remove (*Float).Scan, ScanFloat; more robust (*Float).Parse
- (*Float).Scan conflicted with fmt.Scanner.Scan; it was also only used
  internally. Removed it, as well as the companion ScanFloat function.

- (*Float).Parse (and thus ParseFloat) can now also parse infinities.
  As a result, more code could be simplified.

- Fixed a bug in rounding (round may implicitly be called for infinite
  values). Found via existing test cases, after simplifying some code.

- Added more test cases.

Fixes issue #10938.

Change-Id: I1df97821654f034965ba8b82b272e52e6dc427f1
Reviewed-on: https://go-review.googlesource.com/10498
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-29 17:11:43 +00:00
Robert Griesemer
9b3d9230aa math/big: rename (*Float).Format to (*Float).Text
This paves the way for a fmt-compatible (*Float).Format method.
A better name then Text is still desirable (suggestions welcome).

This is partly fixing issue #10938.

Change-Id: I59c20a8cee11f5dba059fe0f38b414fe75f2ab13
Reviewed-on: https://go-review.googlesource.com/10493
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-29 17:10:54 +00:00
Robert Griesemer
0c02b33acd math/big: fix latent decimal conversion bug
A decimal represented 0.0 with a 0-length mantissa and undefined
exponent, but the formatting code assumes a valid zero exponent
if the float value is 0.0. The code worked because we allocate a
new decimal value each time and because there's no rounding that
lead to 0.0.

Change-Id: Ifd771d7709de83b87fdbf141786286b4c3e13d4f
Reviewed-on: https://go-review.googlesource.com/10448
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-28 16:02:32 +00:00
Robert Griesemer
635cd91eb4 math/big: more cleanups (msbxx, nlzxx functions)
Change-Id: Ibace718452b6dc029c5af5240117f5fc794c38cf
Reviewed-on: https://go-review.googlesource.com/10388
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-27 22:10:15 +00:00
Robert Griesemer
0858d8847d math/big: removed TODO, cleanups
- factor out handling of sign
- rename bstring, pstring to fmtB, fmtP consistent with fmtE, fmtF
- move all float-to-string conversion functions into ftoa.go
- no functional changes

Change-Id: I5970ecb874dc9c387630b59147d90bda16a5d8e6
Reviewed-on: https://go-review.googlesource.com/10387
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-27 22:09:47 +00:00
Robert Griesemer
2df1ccdbc6 math/big: Always print exponent sign when using 'p' exponent for Floats.
Float.Format supports the 'b' and 'p' format, both of which print
a binary ('p') exponent. The 'b' format always printed a sign ('+'
or '-') for the exponent; the 'p' format only printed a negative
sign for the exponent. This change makes the two consistent. It
also makes the 'p' format easier to read if the exponent is >= 0.

Also:
- Comments added elsewhere.

Change-Id: Ifd2e01bdafb3043345972ca22a90248d055bd29b
Reviewed-on: https://go-review.googlesource.com/10359
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-22 23:12:51 +00:00
Robert Griesemer
5ffbca4823 math/big: fix Float.Float64 conversion for denormal corner cases
- This change uses the same code as for Float32 and fixes the case
  of a number that gets rounded up to the smallest denormal.

- Enabled correspoding test case.

Change-Id: I8aac874a566cd727863a82717854f603fbdc26c6
Reviewed-on: https://go-review.googlesource.com/10352
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-22 21:10:43 +00:00
Robert Griesemer
8de8925c77 math/big: add more Float.Float64 conversion tests
- structure the Float64 conversion tests the same way as for Float32
- add additional test cases, including one that exposes a current issue
  (currently disabled, same issue as was fixed for Float32)

The Float64 fix will be in a subsequent change for easier reviewing.

Change-Id: I95dc9e8d1f6b6073a98c7bc2289e6d3248fc3420
Reviewed-on: https://go-review.googlesource.com/10351
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-22 21:06:01 +00:00
Robert Griesemer
79afb43a0a math/big: fix Float.Float32 conversion for denormal corner cases
The existing code was incorrect for numbers that after rounding would
become the smallest denormal float32 (instead the result was 0). This
caused all.bash to fail if Float32() were used in the compiler for
constant arithmetic (there's currently a work-around - see also issue
10321.

This change fixes the implementation of Float.Float32 and adds
corresponding test cases. Float32 and Float64 diverge at this point.
For ease of review, this change only fixes Float32. Float64 will be
made to match in a subsequent change.

Fixes #10321.

Change-Id: Iccafe37c1593a4946bc552e4ad2045f69be62d80
Reviewed-on: https://go-review.googlesource.com/10350
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-22 21:05:25 +00:00
Robert Griesemer
c344f751fc math/big: gofmt nat_test.go
Was apparently checked in by https://go-review.googlesource.com/#/c/9253/
without being gofmt-ed.

TBR: agl

Change-Id: I4d011dbaa15b7c5e73ca71f724f32951a0302dae
Reviewed-on: https://go-review.googlesource.com/10353
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-05-22 01:09:34 +00:00
Vlad Krasnov
9279684908 math/big: Simple Montgomery Multiplication to accelerate Mod-Exp
On Haswell I measure anywhere between 2X to 3.5X speedup for RSA.
I believe other architectures will also greatly improve.
In the future may be upgraded by dedicated assembly routine.

Built-in benchmarks i5-4278U turbo off:

benchmark                         old ns/op     new ns/op     delta
BenchmarkRSA2048Decrypt           6696649       3073769       -54.10%
Benchmark3PrimeRSA2048Decrypt     4472340       1669080       -62.68%

Change-Id: I17df84f85e34208f990665f9f90ea671695b2add
Reviewed-on: https://go-review.googlesource.com/9253
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
Reviewed-by: Vlad Krasnov <vlad@cloudflare.com>
Run-TryBot: Adam Langley <agl@golang.org>
2015-05-22 00:25:25 +00:00
Shenghou Ma
85a1577800 math/big, cmd/internal/gc/big: fix vet detected printf problem
Change-Id: I54425d8cbe0277d7a0c9d66c37f2128a0dfa6441
Reviewed-on: https://go-review.googlesource.com/10041
Run-TryBot: Minux Ma <minux@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-05-14 05:34:40 +00:00
Brad Fitzpatrick
f8fbcefa6c math/rand: shorten Float32 test for GOARM=5
Fixes #10749

Change-Id: I9d5f6f179fd117b0c358d7c8042daf5985b645c0
Reviewed-on: https://go-review.googlesource.com/10022
Reviewed-by: Dave Cheney <dave@cheney.net>
2015-05-13 22:31:44 +00:00
Bryan Ford
ac61588288 math/big: add modular square-root and Jacobi functions
This change adds Int.ModSqrt to compute modular square-roots via the
standard Tonelli-Shanks algorithm, and the Jacobi function that this and
many other modular-arithmetic algorithms depend on.

This is needed by change 1883 (https://golang.org/cl/1883), to add
support for ANSI-standard compressed encoding of elliptic curve points.

Change-Id: Icc4805001bba0b3cb7200e0b0a7f87b14a9e9439
Reviewed-on: https://go-review.googlesource.com/1886
Reviewed-by: Adam Langley <agl@golang.org>
2015-04-30 04:02:58 +00:00
Josh Bleecher Snyder
56a7c5b95c math/big: add partial arm64 assembly support
benchmark                       old ns/op      new ns/op      delta
BenchmarkAddVV_1                18.7           14.8           -20.86%
BenchmarkAddVV_2                21.8           16.6           -23.85%
BenchmarkAddVV_3                26.1           17.1           -34.48%
BenchmarkAddVV_4                30.4           21.9           -27.96%
BenchmarkAddVV_5                35.5           19.8           -44.23%
BenchmarkAddVV_1e1              63.0           28.3           -55.08%
BenchmarkAddVV_1e2              593            178            -69.98%
BenchmarkAddVV_1e3              5691           1490           -73.82%
BenchmarkAddVV_1e4              56868          20761          -63.49%
BenchmarkAddVV_1e5              569062         207679         -63.51%
BenchmarkAddVW_1                15.8           12.6           -20.25%
BenchmarkAddVW_2                17.8           13.1           -26.40%
BenchmarkAddVW_3                21.2           13.9           -34.43%
BenchmarkAddVW_4                23.6           14.7           -37.71%
BenchmarkAddVW_5                26.0           15.8           -39.23%
BenchmarkAddVW_1e1              41.3           21.6           -47.70%
BenchmarkAddVW_1e2              383            145            -62.14%
BenchmarkAddVW_1e3              3703           1264           -65.87%
BenchmarkAddVW_1e4              36920          14359          -61.11%
BenchmarkAddVW_1e5              370345         143046         -61.37%
BenchmarkAddMulVVW_1            33.2           32.5           -2.11%
BenchmarkAddMulVVW_2            58.0           57.2           -1.38%
BenchmarkAddMulVVW_3            95.2           93.9           -1.37%
BenchmarkAddMulVVW_4            108            106            -1.85%
BenchmarkAddMulVVW_5            159            156            -1.89%
BenchmarkAddMulVVW_1e1          344            340            -1.16%
BenchmarkAddMulVVW_1e2          3644           3624           -0.55%
BenchmarkAddMulVVW_1e3          37344          37208          -0.36%
BenchmarkAddMulVVW_1e4          373295         372170         -0.30%
BenchmarkAddMulVVW_1e5          3438116        3425606        -0.36%
BenchmarkBitLen0                7.21           4.32           -40.08%
BenchmarkBitLen1                6.49           4.32           -33.44%
BenchmarkBitLen2                7.23           4.32           -40.25%
BenchmarkBitLen3                6.49           4.32           -33.44%
BenchmarkBitLen4                7.22           4.32           -40.17%
BenchmarkBitLen5                6.52           4.33           -33.59%
BenchmarkBitLen8                7.22           4.32           -40.17%
BenchmarkBitLen9                6.49           4.32           -33.44%
BenchmarkBitLen16               8.66           4.32           -50.12%
BenchmarkBitLen17               7.95           4.32           -45.66%
BenchmarkBitLen31               8.69           4.32           -50.29%
BenchmarkGCD10x10               5021           5033           +0.24%
BenchmarkGCD10x100              5571           5572           +0.02%
BenchmarkGCD10x1000             6707           6729           +0.33%
BenchmarkGCD10x10000            13526          13419          -0.79%
BenchmarkGCD10x100000           85668          83242          -2.83%
BenchmarkGCD100x100             24196          23936          -1.07%
BenchmarkGCD100x1000            28802          27309          -5.18%
BenchmarkGCD100x10000           64111          51704          -19.35%
BenchmarkGCD100x100000          385840         274385         -28.89%
BenchmarkGCD1000x1000           262892         236269         -10.13%
BenchmarkGCD1000x10000          371393         277883         -25.18%
BenchmarkGCD1000x100000         1311795        589055         -55.10%
BenchmarkGCD10000x10000         9596740        6123930        -36.19%
BenchmarkGCD10000x100000        16404000       7269610        -55.68%
BenchmarkGCD100000x100000       776660000      419270000      -46.02%
BenchmarkHilbert                13478980       13402270       -0.57%
BenchmarkBinomial               9802           9440           -3.69%
BenchmarkBitset                 142            142            +0.00%
BenchmarkBitsetNeg              328            279            -14.94%
BenchmarkBitsetOrig             853            861            +0.94%
BenchmarkBitsetNegOrig          1489           1444           -3.02%
BenchmarkMul                    420949000      410481000      -2.49%
BenchmarkExp3Power0x10          1148           1229           +7.06%
BenchmarkExp3Power0x40          1322           1376           +4.08%
BenchmarkExp3Power0x100         2437           2486           +2.01%
BenchmarkExp3Power0x400         9456           9346           -1.16%
BenchmarkExp3Power0x1000        113623         108701         -4.33%
BenchmarkExp3Power0x4000        1134933        1101481        -2.95%
BenchmarkExp3Power0x10000       10773570       10396160       -3.50%
BenchmarkExp3Power0x40000       101362100      97788300       -3.53%
BenchmarkExp3Power0x100000      921114000      885249000      -3.89%
BenchmarkExp3Power0x400000      8323094000     7969020000     -4.25%
BenchmarkFibo                   322021600      92554450       -71.26%
BenchmarkScanPi                 1264583        321065         -74.61%
BenchmarkStringPiParallel       1644661        554216         -66.30%
BenchmarkScan10Base2            1111           1080           -2.79%
BenchmarkScan100Base2           6645           6345           -4.51%
BenchmarkScan1000Base2          84084          62405          -25.78%
BenchmarkScan10000Base2         3105998        932551         -69.98%
BenchmarkScan100000Base2        257234800      40113333       -84.41%
BenchmarkScan10Base8            571            573            +0.35%
BenchmarkScan100Base8           2810           2543           -9.50%
BenchmarkScan1000Base8          47383          25834          -45.48%
BenchmarkScan10000Base8         2739518        567203         -79.30%
BenchmarkScan100000Base8        253952400      36495680       -85.63%
BenchmarkScan10Base10           553            556            +0.54%
BenchmarkScan100Base10          2640           2385           -9.66%
BenchmarkScan1000Base10         50865          24049          -52.72%
BenchmarkScan10000Base10        3279916        549313         -83.25%
BenchmarkScan100000Base10       309121000      36213140       -88.29%
BenchmarkScan10Base16           478            483            +1.05%
BenchmarkScan100Base16          2353           2144           -8.88%
BenchmarkScan1000Base16         48091          24246          -49.58%
BenchmarkScan10000Base16        2858886        586475         -79.49%
BenchmarkScan100000Base16       266320000      38190500       -85.66%
BenchmarkString10Base2          736            730            -0.82%
BenchmarkString100Base2         2695           2707           +0.45%
BenchmarkString1000Base2        20549          20388          -0.78%
BenchmarkString10000Base2       212638         210782         -0.87%
BenchmarkString100000Base2      1944963        1938033        -0.36%
BenchmarkString10Base8          524            517            -1.34%
BenchmarkString100Base8         1326           1320           -0.45%
BenchmarkString1000Base8        8213           8249           +0.44%
BenchmarkString10000Base8       72204          72092          -0.16%
BenchmarkString100000Base8      769068         765993         -0.40%
BenchmarkString10Base10         1018           982            -3.54%
BenchmarkString100Base10        3485           3206           -8.01%
BenchmarkString1000Base10       37102          18935          -48.97%
BenchmarkString10000Base10      188633         88637          -53.01%
BenchmarkString100000Base10     124490300      19700940       -84.17%
BenchmarkString10Base16         509            502            -1.38%
BenchmarkString100Base16        1084           1098           +1.29%
BenchmarkString1000Base16       5641           5650           +0.16%
BenchmarkString10000Base16      46900          46745          -0.33%
BenchmarkString100000Base16     508957         505840         -0.61%
BenchmarkLeafSize0              8934320        8149465        -8.78%
BenchmarkLeafSize1              237666         118381         -50.19%
BenchmarkLeafSize2              237807         117854         -50.44%
BenchmarkLeafSize3              1688640        353494         -79.07%
BenchmarkLeafSize4              235676         116196         -50.70%
BenchmarkLeafSize5              2121896        430325         -79.72%
BenchmarkLeafSize6              1682306        351775         -79.09%
BenchmarkLeafSize7              1051847        251436         -76.10%
BenchmarkLeafSize8              232697         115674         -50.29%
BenchmarkLeafSize9              2403616        488443         -79.68%
BenchmarkLeafSize10             2120975        429545         -79.75%
BenchmarkLeafSize11             2023789        426525         -78.92%
BenchmarkLeafSize12             1684830        351985         -79.11%
BenchmarkLeafSize13             1465529        337906         -76.94%
BenchmarkLeafSize14             1050498        253872         -75.83%
BenchmarkLeafSize15             683228         197384         -71.11%
BenchmarkLeafSize16             232496         116026         -50.10%
BenchmarkLeafSize32             245841         126671         -48.47%
BenchmarkLeafSize64             301728         190285         -36.93%

Change-Id: I63e63297896d96b89c9a275b893c2b405a7e105d
Reviewed-on: https://go-review.googlesource.com/9260
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-23 23:29:15 +00:00
Josh Bleecher Snyder
91f2db3c57 math/big: test that subVW and addVW work with arbitrary y
Fixes #10525.

Change-Id: I92dc87f5d6db396d8dde2220fc37b7093b772d81
Reviewed-on: https://go-review.googlesource.com/9210
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-04-21 23:13:33 +00:00
Robert Griesemer
d13f479de3 math/big: better doc strings for ErrNaN functionality
Change-Id: Ia0944e7b47193465d3ec37fc8dc46dea9b5dcc6b
Reviewed-on: https://go-review.googlesource.com/8710
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-09 20:18:32 +00:00
Robert Griesemer
b28802d2f1 math/big: make ErrNaN actually implement the error interface (oversight)
There was no way to get to the error message before.

Change-Id: I4aa9d3d9f468c33f9996295bafcbed097de0389f
Reviewed-on: https://go-review.googlesource.com/8660
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-04-08 19:47:39 +00:00
ALTree
e21154fe31 math/big: fix Exp when exponent is 1
Fixed bug that caused Exp(x, y, m) ( i.e. x**y (mod m) ) to return x
instead of x (mod m) when y == 1. See issue page on github for more
details.

Added test case

Fixes #9826

Change-Id: Ibabb58275a20c4231c9474199b7f1c10e54241ce
Reviewed-on: https://go-review.googlesource.com/8409
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-04-07 21:04:09 +00:00
Igor Dolzhikov
debe12cfcf net/http, math/big, cmd/internal/gc/big: replaced errors.New(fmt.Sprintf(...)) in favour fmt.Errorf()
Change-Id: I38fc0ab84a374cb9be0234e40665d7cea0e76fc1
Reviewed-on: https://go-review.googlesource.com/8402
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-06 15:40:34 +00:00
Robert Griesemer
09b3bf42c7 math/big: compute 10**exp efficiently when converting Floats
Change-Id: Ic2d9fdae43d18255c198ae62376212bdc89b75da
Reviewed-on: https://go-review.googlesource.com/8464
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-04-04 00:03:16 +00:00
Shenghou Ma
764c751ae5 math, cmd/internal/gc, cmd/7g: enable SQRT inlining, add assembly implementation
benchmark                 old ns/op     new ns/op     delta
BenchmarkSqrt             474           16.5          -96.52%
BenchmarkSqrtIndirect     476           38.1          -92.00%
BenchmarkSqrtGo           484           483           -0.21%

Change-Id: I5ad0132feda0d3275a884523b9e79d83db4fc726
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/8465
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-03 23:48:00 +00:00
Russ Cox
92dba0d278 cmd/internal/gc: use hardware instruction for math.Sqrt (amd64/arm)
I first prototyped this change in Sept 2011, and I discarded it
because it made no difference in the obvious benchmark loop.
It still makes no difference in the obvious benchmark loop,
but in a less obvious one, doing some extra computation
around the calls to Sqrt, not making the call does have a
significant effect.

benchmark                 old ns/op     new ns/op     delta
BenchmarkSqrt             4.56          4.57          +0.22%
BenchmarkSqrtIndirect     4.56          4.56          +0.00%
BenchmarkSqrtGo           69.4          69.4          +0.00%
BenchmarkSqrtPrime        4417          3647          -17.43%

This is a warmup for using hardware expansions for some
calls to 1-line assembly routines in the runtime (for example getg).

Change-Id: Ie66be23f8c09d0f7dc4ddd7ca8a93cfce28f55a4
Reviewed-on: https://go-review.googlesource.com/8356
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-03 16:13:36 +00:00
Robert Griesemer
bb298754ab math/big: implement missing special cases for binary operations
Change-Id: I9fc12b1a9b1554523e08839c1ff46c8668217ba1
Reviewed-on: https://go-review.googlesource.com/8381
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-04-02 17:05:09 +00:00
Robert Griesemer
919a6fbeab math/big: faster Int.Binomial(n, k) for k > n/2
benchmark             old ns/op     new ns/op     delta
BenchmarkBinomial     478664        4410          -99.08%

Fixes #10084.

Change-Id: Ib75034428e32c79c9a660ae9f9bd396afc6a7f11
Reviewed-on: https://go-review.googlesource.com/8351
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-04-01 19:35:35 +00:00
Robert Griesemer
fa85a7206d math/big: remove NaN support - just not worth it
NaNs make the API more complicated for no real good reasons.
There are few operations that produce NaNs with IEEE arithmetic,
there's no need to copy the behavior. It's easy to test for these
scenarios and avoid them (on the other hand, it's not easy to test
for overflow or underflow, so we want to keep +/-Inf).

Also:
- renamed IsNeg -> Signbit (clearer, especially for x == -0)
- removed IsZero           (Sign() == 0 is sufficient and efficient)
- removed IsFinite         (now same as !IsInf)

Change-Id: I3f3b4445c325d9bbb1bf46ce2e298a6aeb498e07
Reviewed-on: https://go-review.googlesource.com/8280
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-31 23:05:31 +00:00
Robert Griesemer
8d267b9b59 math/big: fixed Float.Float64, implemented Float.Float32
- fix bounds checks for exponent range of denormalized numbers
- use correct rounding precision for denormalized numbers
- added extra tests

Change-Id: I6be56399afd0d9a603300a2e44b5539e08d6f592
Reviewed-on: https://go-review.googlesource.com/8096
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-31 19:36:55 +00:00
Jeremy Schlatter
ff1f3a11e4 math/big: fix copy-paste mistake in int_test.go
Change-Id: If986ed2cf94efba92763d00a3182047c05d6f805
Reviewed-on: https://go-review.googlesource.com/8133
Reviewed-by: Minux Ma <minux@golang.org>
2015-03-27 21:02:31 +00:00
Robert Griesemer
2c4cf2f6f2 math/big: fix known bug in Float.Float64
- handle exponent over- and underflow
- handle denormalized numbers
- added test cases

Change-Id: I1bbb9904b0c104f54696944e1f57559881f6eeeb
Reviewed-on: https://go-review.googlesource.com/7982
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-24 20:34:14 +00:00
Robert Griesemer
98182c86b1 math/big: enable pure Go (no assembly) build with build tag
To use a pure Go implementation of the low-level arithmetic
functions (when no platform-specific assembly implementations
are available), set the build tag math_big_pure_go.

This will make it easy to vendor the math/big package where no
assembly is available (for instance for use with gc which relies
on 1.4 functionality for now).

Change-Id: I91e17c0fdc568a20ec1512d7c64621241dc60c17
Reviewed-on: https://go-review.googlesource.com/7856
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-20 21:58:19 +00:00
Josh Bleecher Snyder
2adc4e8927 all: use "reports whether" in place of "returns true if(f)"
Comment changes only.

Change-Id: I56848814564c4aa0988b451df18bebdfc88d6d94
Reviewed-on: https://go-review.googlesource.com/7721
Reviewed-by: Rob Pike <r@golang.org>
2015-03-18 15:14:06 +00:00
Robert Griesemer
db96e6821a math/big: clearer semantics for Float.Scan
Change-Id: I72e8389ec080be8a0119f98df898de6f5510fa4d
Reviewed-on: https://go-review.googlesource.com/7693
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-17 20:18:53 +00:00
Robert Griesemer
00c73f5c6e math/big: cleaner handling of exponent under/overflow
Fixed several corner-case bugs and added corresponding tests.

Change-Id: I23096b9caeeff0956f65ab59fa91e168d0e47bb8
Reviewed-on: https://go-review.googlesource.com/7001
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-17 16:09:34 +00:00
Aram Hăvărneanu
f0aef42ea1 math, math/big: add support for GOARCH=arm64
Change-Id: Ief12e1435a40dd2eaddc3f97f63be44c4dd2e050
Reviewed-on: https://go-review.googlesource.com/7144
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-03-16 18:46:10 +00:00
Robert Griesemer
23fd374bf2 math/big: wrap Float.Cmp result in struct to prevent wrong use
Float.Cmp used to return a value < 0, 0, or > 0 depending on how
arguments x, y compared against each other. With the possibility
of NaNs, the result was changed into an Accuracy (to include Undef).
Consequently, Float.Cmp results could still be compared for (in-)
equality with 0, but comparing if < 0 or > 0 would provide the
wrong answer w/o any obvious notice by the compiler.

This change wraps Float.Cmp results into a struct and accessors
are used to access the desired result. This prevents incorrect
use.

Change-Id: I34e6a6c1859251ec99b5cf953e82542025ace56f
Reviewed-on: https://go-review.googlesource.com/7526
Reviewed-by: Rob Pike <r@golang.org>
2015-03-14 00:48:53 +00:00
Robert Griesemer
a4bfe64f00 math/big: fix minor documentation issue
Change-Id: Ib42f75c03573cec16801b79a6eb9b1b542028f4f
Reviewed-on: https://go-review.googlesource.com/7524
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-13 21:30:11 +00:00
Robert Griesemer
f6580319e4 math/big: fix silly bug in Int64 accessor
Change-Id: If335d45ea1ab6c8aeeb47515f97680e2c1d651f3
Reviewed-on: https://go-review.googlesource.com/7522
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-13 20:14:57 +00:00
Robert Griesemer
8a6eca43df math/big: handle NaNs in Float.Cmp
Also:
- Implemented NewFloat convenience factory function (analogous to
  NewInt and NewRat).
- Implemented convenience accessors for Accuracy values returned
  from Float.Cmp.
- Added test and example.

Change-Id: I985bb4f86e6def222d4b2505417250d29a39c60e
Reviewed-on: https://go-review.googlesource.com/6970
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-12 18:56:25 +00:00
Robert Griesemer
363617c7d3 math/big: added (internal) Float.form field for easier case distinctions
This is a fairly significant _internal_ representation change. Instead
of encoding 0, finite, infinite, and NaN values with special mantissa
and exponent values, a new (1 byte) 'form' field is used (without making
the Float struct bigger). The form field permits simpler and faster
case distinctions. As a side benefit, for zero and non-finite floats,
fewer fields need to be set. Also, the exponent range is not the full
int32 range (in the old format, infExp and nanExp were used to represent
Inf and NaN values and tests for those values sometimes didn't test
for the empty mantissa, so the range was reduced by 2 values).

The correspondence between the old and new fields is as follows.
Old representation:

x                 neg      mant         exp
---------------------------------------------------------------
+/-0              sign     empty        0
0 < |x| < +Inf    sign     mantissa     exponent
+/-Inf            sign     empty        infExp
NaN               false    empty        nanExp

New representation (- stands for ignored fields):

x                 neg      mant         exp         form
---------------------------------------------------------------
+/-0              sign     -            -           zero
0 < |x| < +Inf    sign     mantissa     exponent    finite
+/-Inf            sign     -            -           inf
NaN               -        -            -           nan

Client should not be affected by this change.

Change-Id: I7e355894d602ceb23f9ec01da755fe6e0386b101
Reviewed-on: https://go-review.googlesource.com/6870
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-12 18:41:45 +00:00
Robert Griesemer
0ff7c3ea45 math/big: make validate a method of Float (cleanup)
Change-Id: If38f45acffd352ed95f32f3a36edd91a1fb33d0c
Reviewed-on: https://go-review.googlesource.com/6850
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-12 18:34:42 +00:00
Robert Griesemer
63269404a8 math/big: introduce Bits abstraction instead of using "untyped" []int bit lists
Change-Id: I6caa6bdcf6643ce3015244397a752bd133f3d00c
Reviewed-on: https://go-review.googlesource.com/6840
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-12 18:31:21 +00:00
Robert Griesemer
f3d3328988 math/big: move "bits" operations used for Float tests into separate file
This is a pure code move without any semantic change.

Change-Id: I2c18efc858955d07949b1241e793232f2cf1deb9
Reviewed-on: https://go-review.googlesource.com/6821
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-06 01:36:59 +00:00
Robert Griesemer
85626a9266 math/big: added more comprehensive mul/quo test
Change-Id: Ib813eb5960c3310b1c919f25f687560f4f9d63b0
Reviewed-on: https://go-review.googlesource.com/6820
Reviewed-by: Russ Cox <rsc@golang.org>
2015-03-05 01:36:45 +00:00
Robert Griesemer
7be32d038a math/big: reenable TestFloatAdd32 (used to fail on 32bit platforms)
Change-Id: I932c2f1b1d27c437722cd27d2001b085a655c572
Reviewed-on: https://go-review.googlesource.com/6722
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04 18:24:53 +00:00
Robert Griesemer
2a1728d009 math/big: use stringer for enum String() methods
Change-Id: Ide0615542d67b7d81bf6c56aab550e142a8789f7
Reviewed-on: https://go-review.googlesource.com/6682
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04 18:24:34 +00:00
Robert Griesemer
0a8a625848 math/big: added Float.Add example, remove warning from Floats
Change-Id: If04840c34b0ac5168ce1699eae880f04ae21c84c
Reviewed-on: https://go-review.googlesource.com/6680
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04 18:24:15 +00:00
Robert Griesemer
ef0b03137d math/big: remove Float.Lsh/Rsh; added shift example
Shifts are trivially implemented by combining
Float.MantExp and Float.SetMantExp.

Change-Id: Ia2fb49297d8ea7aa7d64c8b1318dc3dc7c8af2f7
Reviewed-on: https://go-review.googlesource.com/6671
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04 18:23:43 +00:00
Robert Griesemer
d934d10a0b math/big: introduce Undef Accuracy, use for NaN operands/results
This change represents Accuracy as a bit pattern rather than
an ordered value; with a new value Undef which is both Below
and Above.

Change-Id: Ibb96294c1417fb3cf2c3cf2374c993b0a4e106b3
Reviewed-on: https://go-review.googlesource.com/6650
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04 18:23:22 +00:00
Robert Griesemer
ea1fafbccd math/big: modified MantExp semantics to enable fast exponent access
Change-Id: I9a6ebb747d5b9756c214bdeb19f60820602d7a24
Reviewed-on: https://go-review.googlesource.com/6340
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04 18:22:31 +00:00
Robert Griesemer
e053883352 math/big: implement NaN
This change introduces NaNs (for situations like Inf-Inf, etc.).
The implementation is incomplete (the four basic operations produce
a NaN if any of the operands is an Inf or a NaN); and some operations
produce incorrect accuracy for NaN arguments. These are known bugs
which are documented.

Change-Id: Ia88841209e47930681cef19f113e178f92ceeb33
Reviewed-on: https://go-review.googlesource.com/6540
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04 18:22:01 +00:00
Robert Griesemer
c3dc78f301 math/big: replace Float.NewInf with Float.SetInf for more consistent API
Change-Id: I2a60ea4a196eef1af5d2aae6cc239c64bddb6fb2
Reviewed-on: https://go-review.googlesource.com/6301
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-02 20:35:49 +00:00
Robert Griesemer
79c12958c7 math/big: export Float.MinPrec
MinPrec returns the minimum precision required to represent a Float
without loss of precision. Added test.

Change-Id: I466c8e492dcdd59fae854fc4e71ef9b1add7d817
Reviewed-on: https://go-review.googlesource.com/6010
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-26 17:01:16 +00:00
Robert Griesemer
9c4aade584 math/big: fix build for 32bit platforms
Change-Id: I9c217e5140294a17e4feb65da5b121ee8d8cadc2
Reviewed-on: https://go-review.googlesource.com/6050
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-26 00:15:04 +00:00
Robert Griesemer
ca0be6f849 math/big: clean up Float.SetPrec, use shorter internal representation
Change-Id: I9b78085adc12cbd240d0b8b48db6810ddb2aeadd
Reviewed-on: https://go-review.googlesource.com/5991
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25 23:10:44 +00:00
Robert Griesemer
c20a018d6f math/big: apply a round of go vet
Change-Id: Ie8310acc783659497e50dfe629f06d655b51d647
Reviewed-on: https://go-review.googlesource.com/5990
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25 23:10:14 +00:00
Robert Griesemer
bba8b89aa5 math/big: improve some doc strings
Change-Id: Ie37673d4af2fa7476d67ffb686641611ab6a8e6b
Reviewed-on: https://go-review.googlesource.com/5930
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25 23:09:51 +00:00
Robert Griesemer
88cbe09202 math/big: permit passing of an *Int to Float.Int to avoid allocation
Change-Id: I50e83248357928e56c94b88a8764de828f4f5c76
Reviewed-on: https://go-review.googlesource.com/5890
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25 18:10:42 +00:00
Robert Griesemer
3e9e9b4822 math/big: implemented Float.Rat
Change-Id: If516e12d4b5dfb6f9288437d270569f7e4e2a1cd
Reviewed-on: https://go-review.googlesource.com/5871
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25 16:53:28 +00:00
Robert Griesemer
18fd940620 math/big: permit passing of (possibly nil) *Float to MantExp to avoid allocation
Change-Id: Ia92eea833283f8b16fa09d4ca1c9cb3bc0eb18a2
Reviewed-on: https://go-review.googlesource.com/5870
Reviewed-by: Rob Pike <r@golang.org>
2015-02-25 00:46:27 +00:00
Robert Griesemer
c4b8f9127a math/big: fix test for 32bit platforms (fix build)
Change-Id: I73509cd0e0866cfe2b2ae46a26fb4d043dd050c4
Reviewed-on: https://go-review.googlesource.com/5840
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-24 21:58:00 +00:00
Robert Griesemer
c651fdc0cf math/big: change Float.SetMantExp to always multiply mant by 2**exp
Change-Id: If840e647376a2141f8c17729f7ef251bfff13f5f
Reviewed-on: https://go-review.googlesource.com/5810
Reviewed-by: Rob Pike <r@golang.org>
2015-02-24 21:30:04 +00:00
Robert Griesemer
d9859ad404 math/big: fix several issues with string->Float conversion
Change-Id: I7bf7154e2d8d779fdf7f1d2bb561a06ad174f3b0
Reviewed-on: https://go-review.googlesource.com/4883
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-24 17:35:25 +00:00
Charlie Dorian
ec92af650c math: Dim, Max, Min - allow more bit patterns for NaN
Fixes #9919

Change-Id: Ib443c762f727d4986ca7f8a404362f92b0e91aff
Reviewed-on: https://go-review.googlesource.com/5553
Reviewed-by: Minux Ma <minux@golang.org>
2015-02-23 23:07:01 +00:00
Robert Griesemer
ce137592c0 math/big: fix formatting for 'b' format
Fixes #9939.

Change-Id: I9d60722b648fbc00650115da539a7466c6c86552
Reviewed-on: https://go-review.googlesource.com/5640
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-23 21:23:50 +00:00
Charles Dorian
b48d2a5f25 math: faster Cbrt
Old 45.3 ns/op, new 19.9 ns/op.

Change-Id: If2a201981dcc259846631ecbc694c401e0a80287
Reviewed-on: https://go-review.googlesource.com/5260
Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-23 21:04:46 +00:00
Robert Griesemer
6a10f720f2 math/big: don't return io.EOF on successful call of ParseFloat
Fixes $9938.

Change-Id: Ie8680a875225748abd660fb26b4c25546e7b92d3
Reviewed-on: https://go-review.googlesource.com/5620
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-23 19:20:15 +00:00
Robert Griesemer
2b0213d569 math/big: incorporated feedback from prior TBR reviews
Change-Id: Ida847365223ef09b4a3846e240b4bb6919cb0fe9
Reviewed-on: https://go-review.googlesource.com/5610
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-23 18:09:36 +00:00
Ivan Ukhov
277eddb8f2 math: change Nextafter64 to Nextafter in the description of Nextafter
Change-Id: I3419d6247fbff36aa1ed5451bb3cfb7502c3d07e
Reviewed-on: https://go-review.googlesource.com/5030
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-02-17 14:29:18 +00:00
Robert Griesemer
61c9c3ddc4 math/big: implement fast path in Float.SetRat if argument is integer
Change-Id: Ib82500e198b86e9fade278c7eea7a4b0c6b0b2e1
Reviewed-on: https://go-review.googlesource.com/4921
Reviewed-by: Rob Pike <r@golang.org>
2015-02-15 20:11:00 +00:00
Robert Griesemer
2dd7a6d41f math/big: always round after the sign is set
Some rounding modes are affected by the sign of the value to
be rounded. Make sure the sign is set before round is called.
Added tests (that failed before the fix).

Change-Id: Idd09b8fcbab89894fede0b9bc922cda5ddc87930
Reviewed-on: https://go-review.googlesource.com/4876
Reviewed-by: Rob Pike <r@golang.org>
2015-02-15 05:14:05 +00:00
Robert Griesemer
b7bfb54eaa math/big: fix aliasing bug in Float.Quo
TBR r, adonovan

Change-Id: I1a38e2d724bf1147c7307a7e5ae855c42c60428c
Reviewed-on: https://go-review.googlesource.com/4875
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14 04:22:56 +00:00
Robert Griesemer
a809dc7adb math/big: don't scan past a binary exponent if not accepted syntactically
TBR adonovan

Change-Id: I842cbc855dbd560f65e76c9a557dff1a22c5d610
Reviewed-on: https://go-review.googlesource.com/4882
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14 01:01:19 +00:00
Robert Griesemer
ccdbfe3174 math/big: only permit bases 2, 10, 16 when scanning number w/ "decimal" point
TBR adonovan

Change-Id: I4fd694101c2cf1c0c39bf73d16cab18502742dd9
Reviewed-on: https://go-review.googlesource.com/4881
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14 01:00:30 +00:00
Robert Griesemer
2e3c738649 math/big: remove Float.Round (not needed anymore), fix a bug in SetInt64
TBR adonovan

Change-Id: I30020f39be9183b37275e10a4fd1e1a3b4c48c89
Reviewed-on: https://go-review.googlesource.com/4880
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14 00:43:07 +00:00
Robert Griesemer
df218d3393 math/big: implement/rename accessors for precision and rounding mode
Also: remove NewFloat - not needed anymore. Work-around for places
where has been used so far:

NewFloat(x, prec, mode) === new(Float).SetMode(mode).SetPrec(prec).SetFloat64(x)

However, if mode == ToNearestEven, SetMode is not needed. SetPrec
is needed if the default precision (53 after SetFloat64) is not
adequate.

TBR adonovan

Change-Id: Ifda12c479ba157f2dea306c32b47c7afbf31e759
Reviewed-on: https://go-review.googlesource.com/4842
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14 00:42:40 +00:00
Robert Griesemer
31e852402f math/big: fix aliasing error in Add, Sub
Also:
- make representation more flexible (no need to store trailing 0 digits to match precision)
- simplify rounding as a consequence
- minor related fixes

TBR adonovan

Change-Id: Ie91075990688b506d28371ec3b633b8267397ebb
Reviewed-on: https://go-review.googlesource.com/4841
Reviewed-by: Rob Pike <r@golang.org>
2015-02-14 00:42:05 +00:00
Robert Griesemer
7a77d8d1e9 math/big: use internal validation more consistently
TBR adonovan

Change-Id: If77afa6474af6cad6512f6866725e3ae5acf2e3f
Reviewed-on: https://go-review.googlesource.com/4840
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14 00:41:20 +00:00
Robert Griesemer
9e9ddb004f math/big: implemented Float.Int64, simplified Float.Uint64
Change-Id: Ic270ffa7ec6f6dd4b0a951c64ad965447cce1417
Reviewed-on: https://go-review.googlesource.com/4571
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-12 20:59:02 +00:00
Robert Griesemer
764a9cf20d math/big: completed Float.Uint64
Change-Id: Ib3738492a2ec8fc99323e687168b17b7239db6ad
Reviewed-on: https://go-review.googlesource.com/4511
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-11 17:03:08 +00:00
Robert Griesemer
15fe15a198 math/big: add test cases for Float.Abs and Float.Neg
Change-Id: Ic5f3864bc6d94d60b754e3ccf72b1d40c5c09117
Reviewed-on: https://go-review.googlesource.com/4510
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-11 17:02:54 +00:00
Robert Griesemer
64e7038291 math/big: implemented Float.Int (truncation of Floats to Ints)
Change-Id: Id98f7333fe6ae1b64e0469c6d01f02360c1f8f55
Reviewed-on: https://go-review.googlesource.com/4481
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-11 17:02:35 +00:00
Robert Griesemer
950aa9f1bc math/big: When result prec == 0, use at least prec == 64 for SetInt, SetRat.
This avoids surprises.

Change-Id: Iaae67da2d12e29c4e797ad6313e0895f7ce80cb1
Reviewed-on: https://go-review.googlesource.com/4480
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-11 17:02:09 +00:00
Robert Griesemer
f77696a7f0 math/big: implemented Frexp, Ldexp, IsInt, Copy, bug fixes, more tests
- Frexp, Ldexp are equivalents to the corresponding math functions.
- Set now has the same prec behavior as the other functions
- Copy is a true assignment (replaces old version of Set)
- Cmp now handles infinities
- more tests

Change-Id: I0d33980c08be3095b25d7b3d16bcad1aa7abbd0f
Reviewed-on: https://go-review.googlesource.com/4292
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-10 19:08:53 +00:00
Robert Griesemer
04ce9dbf35 math/big: correct umax
Change-Id: I208c8ac44d1a8882d8fdeb18347dc20941e20374
Reviewed-on: https://go-review.googlesource.com/4250
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-09 19:32:12 +00:00
Robert Griesemer
acfe3a59bd math/big: API cleanup
- better and more consistent documentation
- more functions implemented
- more tests

Change-Id: If4c591e7af4ec5434fbb411a48dd0f8add993720
Reviewed-on: https://go-review.googlesource.com/4140
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-09 17:53:18 +00:00
Robert Griesemer
15594df6b4 math/big: handling of +/-Inf and zero precision, enable zero values
- clarified representation of +/-Inf
- only 0 and Inf values can have 0 precision
- a zero precision value used as result value takes the max precision
  of the arguments (to be fine-tuned for setters)
- the zero precision approach makes Float zero values possible
  (they represent +0)
- more tests

Missing: Filling in the blanks. More tests.

Change-Id: Ibb4f97e12e1f356c3085ce80f3464e97b82ac130
Reviewed-on: https://go-review.googlesource.com/4000
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-06 17:21:01 +00:00
Péter Surányi
9b6ccb1323 all: don't refer to code.google.com/p/go{,-wiki}/
Only documentation / comment changes. Update references to
point to golang.org permalinks or go.googlesource.com/go.
References in historical release notes under doc are left as is.

Change-Id: Icfc14e4998723e2c2d48f9877a91c5abef6794ea
Reviewed-on: https://go-review.googlesource.com/4060
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-06 14:41:47 +00:00
Robert Griesemer
f083a0e364 math/big: add "smoke test" for big.Float division
Change-Id: Ica419a1215ca33dc1cff1e9e4137f204591e3cee
Reviewed-on: https://go-review.googlesource.com/3942
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-05 22:22:28 +00:00
Robert Griesemer
91c0f006fc math/big: more Float conversion tests
Change-Id: Ia30886569141ca2e0321bea6ee1d5c9e0f79d6f9
Reviewed-on: https://go-review.googlesource.com/3941
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-05 22:21:01 +00:00
Robert Griesemer
57c1485fd9 math/big: simplified formatting logic
Change-Id: I4329c44b829fcd77e4f1a1d45904f0f8a280a595
Reviewed-on: https://go-review.googlesource.com/3940
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-05 22:19:42 +00:00
Robert Griesemer
721d5893d7 math/big: first version of Float %e, %f, %g, %G formatting working
Change-Id: I10efa3bc8bc7f41100feabe17837f805a42d7eb6
Reviewed-on: https://go-review.googlesource.com/3842
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-04 21:11:51 +00:00
Robert Griesemer
b8fcae02b0 math/big: fix %b format so it matches strconf %b format for non-zero values
(For zero values the strconv %b format prints the bias-adjusted exponent;
there's no bias in Float.)

Change-Id: I6f4dda9c3a50d02eac375cfe2c927c1540aae865
Reviewed-on: https://go-review.googlesource.com/3841
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-04 21:07:37 +00:00
Robert Griesemer
bbd6771621 math/big: implemented decimal rounding for Float-to-string conversion
Change-Id: Id508ca2f6c087861e8c6bc536bc39e54dce09825
Reviewed-on: https://go-review.googlesource.com/3840
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-04 21:06:37 +00:00
Robert Griesemer
01ba4c000c math/big: implement precise Float to decimal conversion (core functionality)
Change-Id: Ic0153397922ded28a5cb362e86ecdfec42e92163
Reviewed-on: https://go-review.googlesource.com/3752
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-03 19:04:26 +00:00
Robert Griesemer
6966e07ae7 math/big: fix typos
Change-Id: Icb1490f97584d61823339ae809b88d423b185e64
Reviewed-on: https://go-review.googlesource.com/3751
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-03 18:48:38 +00:00
Robert Griesemer
4c91c0d07b math/big: build Float.Format on top of Float.Append
Change-Id: I444eec24467f827caa5c88a1c5ae5bce92508b98
Reviewed-on: https://go-review.googlesource.com/3750
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-03 18:43:51 +00:00
Robert Griesemer
f17cd88089 math/big: split float conversion routines and tests into separate files
No other functional changes.

Change-Id: I7e0bb7452c6a265535297ec7ce6a629f1aff695c
Reviewed-on: https://go-review.googlesource.com/3674
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-30 23:03:06 +00:00
Robert Griesemer
20a96a1f68 math/big: split rat conversion routines and tests into separate files
No other functional changes.

Change-Id: I8be1fc488caa4f3d4c00afcb8c00475bfcd10709
Reviewed-on: https://go-review.googlesource.com/3673
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-30 23:02:51 +00:00
Robert Griesemer
a0c5d28403 math/big: split int conversion routines and tests into separate files
No other functional changes.

Change-Id: If0d9e6208d53478e70d991b6926ea196b2cccf2e
Reviewed-on: https://go-review.googlesource.com/3672
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-30 23:02:35 +00:00
Robert Griesemer
d135966ef6 math/big: split nat conversion routines and tests into separate files
No functional changes.

Change-Id: Ibbb705b167603d30467f3ebb83a3bb39845306a5
Reviewed-on: https://go-review.googlesource.com/3671
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-30 23:01:56 +00:00
Robert Griesemer
9f22de7aaf math/big: parsing of fractions and floats in mantissa bases other than 10
Change-Id: I1eaebf956a69e0958201cc5e0a9beefa062c71e1
Reviewed-on: https://go-review.googlesource.com/3454
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-30 21:51:18 +00:00
Robert Griesemer
0a24b8c776 math/big: sketched out complete set of Float/string conversion functions
Also:
- use io.ByteScanner rather than io.RuneScanner internally
- minor simplifications in Float.Add/Sub

Change-Id: Iae0e99384128dba9eccf68592c4fd389e2bd3b4f
Reviewed-on: https://go-review.googlesource.com/3380
Reviewed-by: Rob Pike <r@golang.org>
2015-01-28 23:22:16 +00:00
Robert Griesemer
f4a2617765 math/big: various fixes, enable tests for 32bit platforms
- fixed Float.Add, Float.Sub
- fixed Float.PString to be platform independent
- fixed Float.Uint64
- fixed various test outputs

TBR: adonovan

Change-Id: I9d273b344d4786f1fed18862198b23285c358a39
Reviewed-on: https://go-review.googlesource.com/3321
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-27 21:14:42 +00:00
Robert Griesemer
3acb9fd98e math/big: disable some tests on 32bit platforms (fix build)
TBR: adonovan

Change-Id: I59757b5b46a2c533fc5f888423c99d550d3c7648
Reviewed-on: https://go-review.googlesource.com/3264
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-24 05:42:47 +00:00
Robert Griesemer
bd275b2381 math/big: multi-precision Floats (starting point)
Implemented:
- +, -, *, /, and some unary ops
- all rounding modes
- basic conversions
- string to float conversion
- tests

Missing:
- float to string conversion, formatting
- handling of +/-0 and +/-inf (under- and overflow)
- various TODOs and cleanups

With precision set to 24 or 53, the results match
float32 or float64 operations exactly (excluding
NaNs and denormalized numbers which will not be
supported).

Change-Id: I3121e90fc4b1528e40bb6ff526008da18b3c6520
Reviewed-on: https://go-review.googlesource.com/1218
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-24 05:17:27 +00:00
Robert Griesemer
2dfa4f4eb0 math/big: use new nat.scan for Rat.SetString
Change-Id: Ida20bf95e8f0fdadb459c2daa6d22edae9c3ad16
Reviewed-on: https://go-review.googlesource.com/3091
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-21 01:48:04 +00:00
Robert Griesemer
4e0618c992 math/big: permit internal nat.scan to accept decimal point
This will simplify parsing of rational and (eventually) floating point numbers.

Also streamlined inner loop. As a result, scan runs faster for all but short
(<= 10 digit) numbers. For short numbers it is < 10% slower (cause is known
and could be addressed in a future CL).

Minor unrelated cleanups. Added additional tests.

benchmark                     old ns/op     new ns/op     delta
BenchmarkScanPi               134465        125122        -6.95%
BenchmarkScan10Base2          493           540           +9.53%
BenchmarkScan100Base2         3608          3244          -10.09%
BenchmarkScan1000Base2        35376         32377         -8.48%
BenchmarkScan10000Base2       481504        450028        -6.54%
BenchmarkScan100000Base2      17936774      17648080      -1.61%
BenchmarkScan10Base8          258           280           +8.53%
BenchmarkScan100Base8         1389          1323          -4.75%
BenchmarkScan1000Base8        14221         13036         -8.33%
BenchmarkScan10000Base8       271298        258993        -4.54%
BenchmarkScan100000Base8      15715465      15672580      -0.27%
BenchmarkScan10Base10         249           268           +7.63%
BenchmarkScan100Base10        1324          1220          -7.85%
BenchmarkScan1000Base10       13398         12234         -8.69%
BenchmarkScan10000Base10      259157        249342        -3.79%
BenchmarkScan100000Base10     15670613      15582409      -0.56%
BenchmarkScan10Base16         231           251           +8.66%
BenchmarkScan100Base16        1093          1065          -2.56%
BenchmarkScan1000Base16       12687         12196         -3.87%
BenchmarkScan10000Base16      282349        271443        -3.86%
BenchmarkScan100000Base16     16742669      16552917      -1.13%

Change-Id: I4b9b078792788aef872b307399f00ffd34903127
Reviewed-on: https://go-review.googlesource.com/2960
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-20 22:57:39 +00:00
Robert Griesemer
de47e9ca54 math/big: better test coverage, misc. cleanups
Change-Id: I4ce5cee63093d917095bf90f4e11123f7ec0f93c
Reviewed-on: https://go-review.googlesource.com/2964
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-20 19:23:47 +00:00
Keith Randall
c6ddca2aec math/big: bug in AndNot(x,y) for x>0,y<0.
The comment says to use (y-1), but then we did add(y.abs, natOne).  We meant sub.

Fixes #9609

Change-Id: I4fe4783326ca082c05588310a0af7895a48fc779
Reviewed-on: https://go-review.googlesource.com/2961
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-16 17:36:29 +00:00
Robert Griesemer
654a185f20 math/big: faster assembly kernels for AddVx/SubVx for 386.
(analog to Change-Id: Ia473e9ab9c63a955c252426684176bca566645ae)

Fixes #9243.

benchmark              old ns/op     new ns/op     delta
BenchmarkAddVV_1       5.76          5.60          -2.78%
BenchmarkAddVV_2       7.17          6.98          -2.65%
BenchmarkAddVV_3       8.69          8.57          -1.38%
BenchmarkAddVV_4       10.5          10.5          +0.00%
BenchmarkAddVV_5       13.3          11.6          -12.78%
BenchmarkAddVV_1e1     20.4          19.3          -5.39%
BenchmarkAddVV_1e2     166           140           -15.66%
BenchmarkAddVV_1e3     1588          1278          -19.52%
BenchmarkAddVV_1e4     16138         12657         -21.57%
BenchmarkAddVV_1e5     167608        127836        -23.73%
BenchmarkAddVW_1       4.87          4.76          -2.26%
BenchmarkAddVW_2       6.10          6.07          -0.49%
BenchmarkAddVW_3       7.75          7.65          -1.29%
BenchmarkAddVW_4       9.30          9.39          +0.97%
BenchmarkAddVW_5       10.8          10.9          +0.93%
BenchmarkAddVW_1e1     18.8          18.8          +0.00%
BenchmarkAddVW_1e2     143           134           -6.29%
BenchmarkAddVW_1e3     1390          1266          -8.92%
BenchmarkAddVW_1e4     13877         12545         -9.60%
BenchmarkAddVW_1e5     155330        125432        -19.25%

benchmark              old MB/s     new MB/s     speedup
BenchmarkAddVV_1       5556.09      5715.12      1.03x
BenchmarkAddVV_2       8926.55      9170.64      1.03x
BenchmarkAddVV_3       11042.15     11201.77     1.01x
BenchmarkAddVV_4       12168.21     12245.50     1.01x
BenchmarkAddVV_5       12041.39     13805.73     1.15x
BenchmarkAddVV_1e1     15659.65     16548.18     1.06x
BenchmarkAddVV_1e2     19268.57     22728.64     1.18x
BenchmarkAddVV_1e3     20141.45     25033.36     1.24x
BenchmarkAddVV_1e4     19827.86     25281.92     1.28x
BenchmarkAddVV_1e5     19092.06     25031.92     1.31x
BenchmarkAddVW_1       822.12       840.92       1.02x
BenchmarkAddVW_2       1310.89      1317.89      1.01x
BenchmarkAddVW_3       1549.31      1568.26      1.01x
BenchmarkAddVW_4       1720.45      1703.77      0.99x
BenchmarkAddVW_5       1857.12      1828.66      0.98x
BenchmarkAddVW_1e1     2126.39      2132.38      1.00x
BenchmarkAddVW_1e2     2784.49      2969.21      1.07x
BenchmarkAddVW_1e3     2876.89      3157.35      1.10x
BenchmarkAddVW_1e4     2882.32      3188.51      1.11x
BenchmarkAddVW_1e5     2575.16      3188.96      1.24x

(measured on OS X 10.9.5, 2.3 GHz Intel Core i7, 8GB 1333 MHz DDR3)

Change-Id: I46698729d5e0bc3e277aa0146a9d7a086c0c26f1
Reviewed-on: https://go-review.googlesource.com/2560
Reviewed-by: Keith Randall <khr@golang.org>
2015-01-08 20:58:59 +00:00
Robert Griesemer
067acd51b0 math/big: faster "pure Go" addition/subtraction for long vectors
(platforms w/o corresponding assembly kernels)

For short vector adds there's some erradic slow-down, but overall
these routines have become significantly faster. This only matters
for platforms w/o native (assembly) versions of these kernels, so
we are not concerned about the minor slow-down for short vectors.

This code was already reviewed under Mercurial (golang.org/cl/172810043)
but wasn't submitted before the switch to git.

Benchmarks run on 2.3GHz Intel Core i7, running OS X 10.9.5,
with the respective AddVV and AddVW assembly routines disabled.

benchmark              old ns/op     new ns/op     delta
BenchmarkAddVV_1       6.59          7.09          +7.59%
BenchmarkAddVV_2       10.3          10.1          -1.94%
BenchmarkAddVV_3       10.9          12.6          +15.60%
BenchmarkAddVV_4       13.9          15.6          +12.23%
BenchmarkAddVV_5       16.8          17.3          +2.98%
BenchmarkAddVV_1e1     29.5          29.9          +1.36%
BenchmarkAddVV_1e2     246           232           -5.69%
BenchmarkAddVV_1e3     2374          2185          -7.96%
BenchmarkAddVV_1e4     58942         22292         -62.18%
BenchmarkAddVV_1e5     668622        225279        -66.31%
BenchmarkAddVW_1       6.81          5.58          -18.06%
BenchmarkAddVW_2       7.69          6.86          -10.79%
BenchmarkAddVW_3       9.56          8.32          -12.97%
BenchmarkAddVW_4       12.1          9.53          -21.24%
BenchmarkAddVW_5       13.2          10.9          -17.42%
BenchmarkAddVW_1e1     23.4          18.0          -23.08%
BenchmarkAddVW_1e2     175           141           -19.43%
BenchmarkAddVW_1e3     1568          1266          -19.26%
BenchmarkAddVW_1e4     15425         12596         -18.34%
BenchmarkAddVW_1e5     156737        133539        -14.80%
BenchmarkFibo          381678466     132958666     -65.16%

benchmark              old MB/s     new MB/s     speedup
BenchmarkAddVV_1       9715.25      9028.30      0.93x
BenchmarkAddVV_2       12461.72     12622.60     1.01x
BenchmarkAddVV_3       17549.64     15243.82     0.87x
BenchmarkAddVV_4       18392.54     16398.29     0.89x
BenchmarkAddVV_5       18995.23     18496.57     0.97x
BenchmarkAddVV_1e1     21708.98     21438.28     0.99x
BenchmarkAddVV_1e2     25956.53     27506.88     1.06x
BenchmarkAddVV_1e3     26947.93     29286.66     1.09x
BenchmarkAddVV_1e4     10857.96     28709.46     2.64x
BenchmarkAddVV_1e5     9571.91      28409.21     2.97x
BenchmarkAddVW_1       1175.28      1433.98      1.22x
BenchmarkAddVW_2       2080.01      2332.54      1.12x
BenchmarkAddVW_3       2509.28      2883.97      1.15x
BenchmarkAddVW_4       2646.09      3356.83      1.27x
BenchmarkAddVW_5       3020.69      3671.07      1.22x
BenchmarkAddVW_1e1     3425.76      4441.40      1.30x
BenchmarkAddVW_1e2     4553.17      5642.96      1.24x
BenchmarkAddVW_1e3     5100.14      6318.72      1.24x
BenchmarkAddVW_1e4     5186.15      6350.96      1.22x
BenchmarkAddVW_1e5     5104.07      5990.74      1.17x

Change-Id: I7a62023b1105248a0e85e5b9819d3fd4266123d4
Reviewed-on: https://go-review.googlesource.com/2480
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-08 17:00:59 +00:00
Robert Griesemer
80b3ff9f82 math/big: faster assembly kernels for AddVx/SubVx for amd64.
Replaced use of rotate instructions (RCRQ, RCLQ) with ADDQ/SBBQ
for restoring/saving the carry flag per suggestion from Torbjörn
Granlund (author of GMP bignum libs for C).
The rotate instructions tend to be slower on todays machines.

benchmark              old ns/op     new ns/op     delta
BenchmarkAddVV_1       5.69          5.51          -3.16%
BenchmarkAddVV_2       7.15          6.87          -3.92%
BenchmarkAddVV_3       8.69          8.06          -7.25%
BenchmarkAddVV_4       8.10          8.13          +0.37%
BenchmarkAddVV_5       8.37          8.47          +1.19%
BenchmarkAddVV_1e1     13.1          12.0          -8.40%
BenchmarkAddVV_1e2     78.1          69.4          -11.14%
BenchmarkAddVV_1e3     815           656           -19.51%
BenchmarkAddVV_1e4     8137          7345          -9.73%
BenchmarkAddVV_1e5     100127        93909         -6.21%
BenchmarkAddVW_1       4.86          4.71          -3.09%
BenchmarkAddVW_2       5.67          5.50          -3.00%
BenchmarkAddVW_3       6.51          6.34          -2.61%
BenchmarkAddVW_4       6.69          6.66          -0.45%
BenchmarkAddVW_5       7.20          7.21          +0.14%
BenchmarkAddVW_1e1     10.0          9.34          -6.60%
BenchmarkAddVW_1e2     45.4          52.3          +15.20%
BenchmarkAddVW_1e3     417           491           +17.75%
BenchmarkAddVW_1e4     4760          4852          +1.93%
BenchmarkAddVW_1e5     69107         67717         -2.01%

benchmark              old MB/s      new MB/s      speedup
BenchmarkAddVV_1       11241.82      11610.28      1.03x
BenchmarkAddVV_2       17902.68      18631.82      1.04x
BenchmarkAddVV_3       22082.43      23835.64      1.08x
BenchmarkAddVV_4       31588.18      31492.06      1.00x
BenchmarkAddVV_5       38229.90      37783.17      0.99x
BenchmarkAddVV_1e1     48891.67      53340.91      1.09x
BenchmarkAddVV_1e2     81940.61      92191.86      1.13x
BenchmarkAddVV_1e3     78443.09      97480.44      1.24x
BenchmarkAddVV_1e4     78644.18      87129.50      1.11x
BenchmarkAddVV_1e5     63918.48      68150.84      1.07x
BenchmarkAddVW_1       13165.09      13581.00      1.03x
BenchmarkAddVW_2       22588.04      23275.41      1.03x
BenchmarkAddVW_3       29483.82      30303.96      1.03x
BenchmarkAddVW_4       38286.54      38453.21      1.00x
BenchmarkAddVW_5       44414.57      44370.59      1.00x
BenchmarkAddVW_1e1     63816.84      68494.08      1.07x
BenchmarkAddVW_1e2     140885.41     122427.16     0.87x
BenchmarkAddVW_1e3     153258.31     130325.28     0.85x
BenchmarkAddVW_1e4     134447.63     131904.02     0.98x
BenchmarkAddVW_1e5     92609.41      94509.88      1.02x

Change-Id: Ia473e9ab9c63a955c252426684176bca566645ae
Reviewed-on: https://go-review.googlesource.com/2503
Reviewed-by: Keith Randall <khr@golang.org>
2015-01-08 16:57:11 +00:00
Shenghou Ma
43178697db math/big: panic if n <= 0 for ProbablyPrime
Fixes #9509

Change-Id: I3b86745d38e09093fe2f4b918d774bd6608727d7
Reviewed-on: https://go-review.googlesource.com/2313
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-05 23:11:35 +00:00
Fazlul Shahriar
e6f76aac32 math: be consistent in how we document special cases
Change-Id: Ic6bc4af7bcc89b2881b2b9e7290aeb6fd54804e2
Reviewed-on: https://go-review.googlesource.com/2239
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-01-05 21:01:46 +00:00
Guobiao Mei
59cb2d9ca6 math/rand: fix example_test to show with the correct method
Originally it used r.Int63() to show "Uint32", and now we use the correct r.Uint32() method.

Fixes #9429

Change-Id: I8a1228f1ca1af93b0e3104676fc99000257c456f
Reviewed-on: https://go-review.googlesource.com/2069
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-23 17:24:24 +00:00
Alberto Donizetti
5de497bc6f math: Added parity check to ProbablyPrime
Fixes #9269

Change-Id: I25751632e95978537b656aedfa5c35ab2273089b
Reviewed-on: https://go-review.googlesource.com/1380
Reviewed-by: Robert Griesemer <gri@golang.org>
2014-12-12 00:25:16 +00:00
Russ Cox
09d92b6bbf all: power64 is now ppc64
Fixes #8654.

LGTM=austin
R=austin
CC=golang-codereviews
https://golang.org/cl/180600043
2014-12-05 19:13:20 -05:00
Austin Clements
062e354c84 [dev.power64] runtime: power64 fixes and ports of changes
Fix include paths that got moved in the great pkg/ rename.  Add
missing runtime/arch_* files for power64.  Port changes that
happened on default since branching to
runtime/{asm,atomic,sys_linux}_power64x.s (precise stacks,
calling convention change, various new and deleted functions.
Port struct renaming and fix some bugs in
runtime/defs_linux_power64.h.

LGTM=rsc
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/161450043
2014-10-27 17:27:03 -04:00
Austin Clements
f0bd539c59 [dev.power64] all: merge default into dev.power64
This brings dev.power64 up-to-date with the current tip of
default.  go_bootstrap is still panicking with a bad defer
when initializing the runtime (even on amd64).

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/152570049
2014-10-22 15:51:54 -04:00
Austin Clements
2bd616b1a7 build: merge the great pkg/ rename into dev.power64
This also removes pkg/runtime/traceback_lr.c, which was ported
to Go in an earlier commit and then moved to
runtime/traceback.go.

Reviewer: rsc@golang.org
          rsc: LGTM
2014-10-22 13:25:37 -04:00
Keith Randall
96d1e4ab59 math/big: Allow non-prime modulus for ModInverse
The inverse is defined whenever the element and the
modulus are relatively prime.  The code already handles
this situation, but the spec does not.

Test that it does indeed work.

Fixes #8875

LGTM=agl
R=agl
CC=golang-codereviews
https://golang.org/cl/155010043
2014-10-14 14:09:56 -07:00
Casey Marshall
7371153321 math/big: Fixes issue 8920
(*Rat).SetString checks for denominator.

LGTM=gri
R=golang-codereviews, gri
CC=golang-codereviews
https://golang.org/cl/159760043
2014-10-13 12:41:14 -07:00
Robert Griesemer
87f51f1031 math/big: fix doc comments
Fixes #8904.

TBR=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/148650043
2014-10-07 10:56:58 -07:00
Robert Griesemer
28ddfb090c math/big: math.Exp should return result >= 0 for |m| > 0
The documentation states that Exp(x, y, m)
computes x**y mod |m| for m != nil && m > 0.
In math.big, Mod is the Euclidean modulus,
which is always >= 0.

Fixes #8822.

LGTM=agl, r, rsc
R=agl, r, rsc
CC=golang-codereviews
https://golang.org/cl/145650043
2014-10-02 13:02:25 -07:00
Russ Cox
4a8cb4a49c math: avoid assumption of denormalized math mode in Sincos
The extra-clever code in Sincos is trying to do

        if v&2 == 0 {
                mask = 0xffffffffffffffff
        } else {
                mask = 0
        }

It does this by turning v&2 into a float64 X0 and then using

        MOVSD $0.0, X3
        CMPSD X0, X3, 0

That CMPSD is defined to behave like:

        if X0 == X3 {
                X3 = 0xffffffffffffffff
        } else {
                X3 = 0
        }

which gives the desired mask in X3. The goal in using the
CMPSD was to avoid a conditional branch.

This code fails when called from a PortAudio callback.
In particular, the failure behavior is exactly as if the
CMPSD always chose the 'true' execution.

Notice that the comparison X0 == X3 is comparing as
floating point values the 64-bit pattern v&2 and the actual
floating point value zero. The only possible values for v&2
are 0x0000000000000000 (floating point zero)
and 0x0000000000000002 (floating point 1e-323, a denormal).
If they are both comparing equal to zero, I conclude that
in a PortAudio callback (whatever that means), the processor
is running in "denormals are zero" mode.

I confirmed this by placing the processor into that mode
and running the test case in the bug; it produces the
incorrect output reported in the bug.

In general, if a Go program changes the floating point math
modes to something other than what Go expects, the math
library is not going to work exactly as intended, so we might
be justified in not fixing this at all.

However, it seems reasonable that the client code might
have expected "denormals are zero" mode to only affect
actual processing of denormals. This code has produced
what is in effect a gratuitous denormal by being extra clever.
There is nothing about the computation being requested
that fundamentally requires a denormal.

It is also easy to do this computation in integer math instead:

        mask = ((v&2)>>1)-1

Do that.

For the record, the other math tests that fail if you put the
processor in "denormals are zero" mode are the tests for
Frexp, Ilogb, Ldexp, Logb, Log2, and FloatMinMax, but all
fail processing denormal inputs. Sincos was the only function
for which that mode causes incorrect behavior on non-denormal inputs.

The existing tests check that the new assembly is correct.
There is no test for behavior in "denormals are zero" mode,
because I don't want to add assembly to change that.

Fixes #8623.

LGTM=josharian
R=golang-codereviews, josharian
CC=golang-codereviews, iant, r
https://golang.org/cl/151750043
2014-09-26 17:13:24 -04:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00