1
0
mirror of https://github.com/golang/go synced 2024-10-04 16:21:22 -06:00
Commit Graph

136 Commits

Author SHA1 Message Date
Robert Griesemer
28e0e18863 math: slightly more readable comments
Replaced /*-style comments with line comments;
there are two many *'s already in those lines.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5699051
2012-02-23 10:17:24 -08:00
Russ Cox
0e70f2722b all: shorten some of the longer tests
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5675092
2012-02-18 16:24:23 -05:00
Rob Pike
7d1c5328ed math/rand: Intn etc. should panic if their argument is <= 0.
I am making a unilateral decision here. I could also settle for returning 0,
as long it's documented, but I argue that it's equivalent to an index
out of bounds.

Fixes #2892.

R=golang-dev, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5676079
2012-02-18 08:53:03 +11:00
Andrew Gerrand
11e113db57 godoc: make example code more readable with new comment convention
go/doc: move Examples to go/ast
cmd/go: use go/doc to read examples
src/pkg: update examples to use new convention

This is to make whole file examples more readable. When presented as a
complete function, preceding an Example with its output is confusing.
The new convention is to put the expected output in the final comment
of the example, preceded by the string "output:" (case insensitive).

An idiomatic example looks like this:

// This example demonstrates Foo by doing bar and quux.
func ExampleFoo() {
        // example body that does bar and quux

        // Output:
        // example output
}

R=rsc, gri
CC=golang-dev
https://golang.org/cl/5673053
2012-02-16 11:50:28 +11:00
Shenghou Ma
9a4487458a all: update 'gotest' to 'go test'
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5645099
2012-02-13 13:58:17 -05:00
Rob Pike
13443ccc2a math: fix gamma doc, link to OEIS
Fixes #2940.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5645078
2012-02-10 15:56:51 +11:00
Robert Griesemer
d0607221fa math/big: more accurate package comment
Fix some receiver names for consistency.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5624043
2012-02-03 10:17:19 -08:00
Robert Griesemer
b80c7e5dfd math/big: API, documentation cleanup
Fixes #2863.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5620058
2012-02-02 19:21:55 -08:00
Robert Griesemer
25787acb3c math/big: document Word type
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5615050
2012-02-02 14:43:55 -08:00
Robert Griesemer
71c19b610f mat/big: add raw access to Int bits
This is a minimal API extension, it makes it possible
to implement missing Int functionality externally w/o
compromising efficiency. It is the hope that this will
reduce the number of feature requests going directly
into the big package.

Also: Fixed some naming inconsistencies: The receiver
is only called z when it is also the result.

R=golang-dev, agl
CC=golang-dev
https://golang.org/cl/5607055
2012-02-01 11:43:40 -08:00
Luuk van Dijk
8dd3de4d4b pkg/math: undo manual inlining of IsInf and IsNaN
R=rsc
CC=golang-dev
https://golang.org/cl/5484076
2012-02-01 16:08:31 +01:00
Russ Cox
2050a9e478 build: remove Make.pkg, Make.tool
Consequently, remove many package Makefiles,
and shorten the few that remain.

gomake becomes 'go tool make'.

Turn off test phases of run.bash that do not work,
flagged with $BROKEN.  Future CLs will restore these,
but this seemed like a big enough CL already.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5601057
2012-01-30 23:43:46 -05:00
Robert Griesemer
8a90a8861f math/big: test both bitLen and bitLen_g
Also: simpler, more direct test.

R=golang-dev, dave.andersen
CC=golang-dev
https://golang.org/cl/5573070
2012-01-26 10:08:21 -08:00
David G. Andersen
1e09031f7f math/big: return type of bitLen is an int; use MOVL on amd64.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5577050
2012-01-25 16:09:12 -08:00
David G. Andersen
316f81bb1d math/big: assembly versions of bitLen for x86-64, 386, and ARM.
Roughly 2x speedup for the internal bitLen function in arith.go.  Added TestWordBitLen test.

Performance differences against the new version of
bitLen generic:

x86-64 Macbook pro (current tip):

benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0             6            4  -37.40%
big.BenchmarkBitLen1             6            2  -51.79%
big.BenchmarkBitLen2             6            2  -65.04%
big.BenchmarkBitLen3             6            2  -66.10%
big.BenchmarkBitLen4             6            2  -60.96%
big.BenchmarkBitLen5             6            2  -55.80%
big.BenchmarkBitLen8             6            2  -56.19%
big.BenchmarkBitLen9             6            2  -64.73%
big.BenchmarkBitLen16            7            2  -68.84%
big.BenchmarkBitLen17            6            2  -67.11%
big.BenchmarkBitLen31            7            2  -61.57%

386 Intel Atom (current tip):
benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0            23           20  -13.04%
big.BenchmarkBitLen1            23           20  -14.77%
big.BenchmarkBitLen2            24           20  -19.28%
big.BenchmarkBitLen3            25           20  -21.57%
big.BenchmarkBitLen4            24           20  -16.94%
big.BenchmarkBitLen5            25           20  -20.78%
big.BenchmarkBitLen8            24           20  -19.28%
big.BenchmarkBitLen9            25           20  -20.47%
big.BenchmarkBitLen16           26           20  -23.37%
big.BenchmarkBitLen17           26           20  -25.09%
big.BenchmarkBitLen31           32           20  -35.51%

ARM v5 SheevaPlug, previous weekly patched with bitLen:
benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0            50           29  -41.73%
big.BenchmarkBitLen1            51           29  -42.75%
big.BenchmarkBitLen2            59           29  -50.08%
big.BenchmarkBitLen3            60           29  -50.75%
big.BenchmarkBitLen4            59           29  -50.08%
big.BenchmarkBitLen5            60           29  -50.75%
big.BenchmarkBitLen8            59           29  -50.08%
big.BenchmarkBitLen9            60           29  -50.75%
big.BenchmarkBitLen16           69           29  -57.35%
big.BenchmarkBitLen17           70           29  -57.89%
big.BenchmarkBitLen31           95           29  -69.07%

R=golang-dev, minux.ma, gri
CC=golang-dev
https://golang.org/cl/5574054
2012-01-25 15:04:16 -08:00
Andrew Gerrand
ddd67f2ecd math/big: add examples for Rat and Int's SetString and Scan methods
R=golang-dev, bradfitz, rsc, r, gri, r
CC=golang-dev
https://golang.org/cl/5543047
2012-01-25 10:29:44 +11:00
David G. Andersen
1dc37bbf46 math/big: slight improvement to algorithm used for internal bitLen function
The bitLen function currently shifts out blocks of 8 bits at a time.
This change replaces this sorta-linear algorithm with a log(N)
one (shift out 16 bits, then 8, then 4, then 2, then 1).
I left the start of it linear at 16 bits at a time so that
the function continues to work with 32 or 64 bit values
without any funkiness.
The algorithm is similar to several of the nlz ("number of
leading zeros") algorithms from "Hacker's Delight" or the
"bit twiddling hacks" pages.

Doesn't make a big difference to the existing benchmarks, but
I'm using the code in a different context that calls bitLen
much more often, so it seemed worthwhile making the existing
codebase faster so that it's a better building block.

Microbenchmark results on a 64-bit Macbook Pro using 6g from weekly.2012-01-20:

benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0             4            6  +50.12%
big.BenchmarkBitLen1             4            6  +33.91%
big.BenchmarkBitLen2             6            6   +3.05%
big.BenchmarkBitLen3             7            6  -19.05%
big.BenchmarkBitLen4             9            6  -30.19%
big.BenchmarkBitLen5            11            6  -42.23%
big.BenchmarkBitLen8            16            6  -61.78%
big.BenchmarkBitLen9             5            6  +18.29%
big.BenchmarkBitLen16           18            7  -60.99%
big.BenchmarkBitLen17            7            6   -4.64%
big.BenchmarkBitLen31           19            7  -62.49%

On an ARM machine (with the previous weekly):

benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0            37           50  +36.56%
big.BenchmarkBitLen1            59           51  -13.69%
big.BenchmarkBitLen2            74           59  -20.40%
big.BenchmarkBitLen3            92           60  -34.89%
big.BenchmarkBitLen4           110           59  -46.09%
big.BenchmarkBitLen5           127           60  -52.68%
big.BenchmarkBitLen8           181           59  -67.24%
big.BenchmarkBitLen9            78           60  -23.05%
big.BenchmarkBitLen16          199           69  -65.13%
big.BenchmarkBitLen17           91           70  -23.17%
big.BenchmarkBitLen31          210           95  -54.43%

R=golang-dev, dave, edsrzf, gri
CC=golang-dev
https://golang.org/cl/5570044
2012-01-23 13:46:28 -08:00
Dmitriy Vyukov
f2f0059307 math/rand: decrease test duration in short mode
TestNonStandardNormalValues runs 1.5s,
the change reduces it to 0.2s in short mode.
The problem is with slow machines, emulators and dynamic tools.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5540065
2012-01-19 16:17:44 +04:00
Scott Lawrence
5163e7aa27 math/rand: document default initial seed for global generator
Fixes #2044.

R=golang-dev
CC=golang-dev
https://golang.org/cl/5541056
2012-01-16 18:13:34 -05:00
Shenghou Ma
4cfa9e3c61 doc: fix comments referring to removed API funcs
The strconv package has removed Atob, AtoF{64,32} and Ftoa.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5540057
2012-01-14 10:59:45 -08:00
Robert Griesemer
b4be65bc7f math/big: simplify fast string conversion
- use slice ops for convertWords instead of lo/hi boundaries
- always compute leading zeroes (simplifies logic significantly),
  but remove them once, at the end (since leafSize is small, the
  worst-case scenario is not adding significant overhead)
- various comment cleanups (specifically, replaced direct -> iterative,
  and indirect -> recursive)
- slightly faster overall for -bench=String

(This CL incorporates the changes re: my comments to CL 5418047
https://golang.org/cl/5418047/ )

benchmark                          old ns/op    new ns/op    delta
big.BenchmarkString10Base2               519          527   +1.54%
big.BenchmarkString100Base2             2279         2158   -5.31%
big.BenchmarkString1000Base2           18475        17323   -6.24%
big.BenchmarkString10000Base2         178248       166219   -6.75%
big.BenchmarkString100000Base2       1548494      1431587   -7.55%
big.BenchmarkString10Base8               415          422   +1.69%
big.BenchmarkString100Base8             1025          978   -4.59%
big.BenchmarkString1000Base8            6822         6428   -5.78%
big.BenchmarkString10000Base8          64598        61065   -5.47%
big.BenchmarkString100000Base8        593788       549150   -7.52%
big.BenchmarkString10Base10              654          645   -1.38%
big.BenchmarkString100Base10            1863         1835   -1.50%
big.BenchmarkString1000Base10          12099        11981   -0.98%
big.BenchmarkString10000Base10         57601        56888   -1.24%
big.BenchmarkString100000Base10     20123120     19827890   -1.47%
big.BenchmarkString10Base16              358          362   +1.12%
big.BenchmarkString100Base16             815          776   -4.79%
big.BenchmarkString1000Base16           4710         4421   -6.14%
big.BenchmarkString10000Base16         43938        40968   -6.76%
big.BenchmarkString100000Base16       406307       373930   -7.97%

R=michael.jones, mtj
CC=golang-dev
https://golang.org/cl/5432090
2012-01-09 11:20:09 -08:00
Charles L. Dorian
149d3f06d8 math: fix typo in all_test.go
Logb errors were reported as Ilogb errors.

R=rsc, golang-dev, gri
CC=golang-dev
https://golang.org/cl/5517045
2012-01-05 11:04:14 -08:00
Robert Griesemer
fc78c5aa00 math/big: Rand shouldn't hang if argument is also receiver.
Fixes #2607.

R=rsc
CC=golang-dev
https://golang.org/cl/5489109
2011-12-22 14:15:41 -08:00
Rob Pike
6b772462e4 panics: use the new facilities of testing.B instead
Lots of panics go away.
Also fix a name error in html/template.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5498045
2011-12-20 10:36:25 -08:00
Robert Griesemer
541b67d051 go/printer, gofmt: fine tuning of line spacing
- no empty lines inside empty structs and interfaces
- top-level declarations are separated by a blank line if
  a) they are of different kind (e.g. const vs type); or
  b) there are documentation comments associated with a
     declaration (this is new)
- applied gofmt -w misc src

The actual changes are in go/printer/nodes.go:397-400 (empty structs/interfaces),
and go/printer/printer.go:307-309 (extra line break). The remaining
changes are cleanups w/o changing the existing functionality.

Fixes issue  2570.

R=rsc
CC=golang-dev
https://golang.org/cl/5493057
2011-12-16 15:43:06 -08:00
Russ Cox
2572803899 math: delete non-Sqrt-based Hypot
I was confused by the existence of two portable Hypot
routines in the tree when I cleaned things up, and I made
ARM use the wrong (imprecise) one.  Use the right one,
and delete the wrong one.

Fixes arm build.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5485065
2011-12-13 17:08:56 -05:00
Russ Cox
dd8dc6f059 math: regularize build
This will be nicer to the automatic tools.
It requires a few more assembly stubs
but fewer Go files.

There are a few instances where it looks like
there are new blobs of code, but they are just
being copied out of deleted files.

There is no new code here.

Suppose you have a portable implementation for Sin
and a 386-specific assembly one.  The old way to
do this was to write three files

sin_decl.go
   func Sin(x float64) float64  // declaration only
sin_386.s
   assembly implementation

sin_port.go
   func Sin(x float64) float64 { ... }  // pure-Go impl

and then link in either sin_decl.go+sin_386.s or
just sin_port.go.  The Makefile actually did the magic
of linking in only the _port.go files for those without
assembly and only the _decl.go files for those with
assembly, or at least some of that magic.

The biggest problem with this, beyond being hard
to explain to the build system, is that once you do
explain it to the build system, godoc knows which
of sin_port.go or sin_decl.go are involved on a given
architecture, and it (correctly) ignores the other.
That means you have to put identical doc comments
in both files.

The new approach, which is more like what we did
in the later packages math/big and sync/atomic,
is to have

sin.go
   func Sin(x float64) float64  // decl only
   func sin(x float64) float64 {...}  // pure-Go impl

sin_386.s
   // assembly for Sin (ignores sin)
sin_amd64.s
   // assembly for Sin: jmp sin
sin_arm.s
   // assembly for Sin: jmp sin

Once we abandon Makefiles we can put all the assembly
stubs in one source file, so the number of files will
actually go down.

Chris asked whether the branches cost anything.
Given that they are branching to pure-Go implementations
that are not typically known for their speed, the single
direct branch is not going to be noticeable.  That is,
it's on the slow path.

An alternative would have been to preserve the old
"only write assembly files when there's an implementation"
and still have just one copy of the declaration of Sin
(and thus one doc comment) by doing:

sin.go
   func Sin(x float64) float64 { return sin(x) }

sin_decl.go
   func sin(x float64) float64 // declaration only
sin_386.s
   // assembly for sin

sin_port.go
   func sin(x float64) float64 { portable code }

In this version everyone would link in sin.go and
then either sin_decl.go+sin_386.s or sin_port.go.

This has an extra function call on all paths, including
the "fast path" to get to assembly, and it triples the
number of Go files involved compared to what I did
in this CL.  On the other hand you don't have to
write assembly stubs.  After starting down this path
I decided that the assembly stubs were the easier
approach.

As for generating the assembly stubs on the fly, much
of the goal here is to eliminate magic from the build
process, so that zero-configuration tools like goinstall
or the new go tool can handle this package.

R=golang-dev, r, cw, iant, r
CC=golang-dev
https://golang.org/cl/5488057
2011-12-13 15:20:12 -05:00
Charles L. Dorian
f5c211172b math: fix special cases in Nextafter
Nextafter(0, -1) != -0.

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5467060
2011-12-12 15:51:11 -05:00
Russ Cox
a250f37cbc update tree for new default type rule
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5448091
2011-12-08 22:08:03 -05:00
Charles L. Dorian
2065b0a094 math: special cases for Pow10; delete BUG
R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5477046
2011-12-08 22:06:33 -05:00
Charles L. Dorian
94b0342f17 math: document more special cases
Acosh, Asinh, Atanh, Ceil, Floor, Trunc, Mod and Remainder affected. These changes add some non-finite arguments and results (and -0.0 results).

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5469046
2011-12-08 17:07:13 -05:00
Charles L. Dorian
e4de2e7fd0 math: document special-cases behavior for Dim, Max and Min
Max returns +Inf if x or y is +Inf; else it returns NaN if either x or y is NaN. Max(-0, -0) returns -0.
Min returns -Inf if x or y is -Inf; else it returns NaN if either x or y is NaN. Min(+0, -0) returns -0.
Dim(+Inf, +Inf) = NaN, Dim(-Inf, -Inf) = NaN and Dim(NaN, anything) = NaN.
Also, change "conditions" to "cases" for Sin (missed it in previous CL).

R=rsc, dave
CC=golang-dev
https://golang.org/cl/5437137
2011-12-07 14:52:17 -05:00
Charles L. Dorian
abc7df9686 math: add special-cases comments to Sinh and Tanh.
Also change "Special conditions" to "Special cases" as in other functions.

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5440078
2011-12-05 14:01:24 -05:00
Charles L. Dorian
06e635e46d math: faster Sincos
Sincos via sincos.go is 35.4 ns/op, via sincos_amd64.s is 37.4 ns/op on 2.53 GHz Intel Core 2 Duo (Mac OS X).

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5447045
2011-11-30 15:11:44 -05:00
Roger Peppe
ca6de008ba math/big: fix destination leak into result value
This code would panic:
z := big.NewInt(1)
z.SetBit(big.NewInt(0), 2, 1)
if z.Cmp(big.NewInt(1<<2)) != 0 {
        panic("fail")
}

R=rsc, gri
CC=golang-dev
https://golang.org/cl/5437081
2011-11-30 09:29:58 -08:00
Russ Cox
03823b881c use new time API
R=bradfitz, gri, r, dsymonds
CC=golang-dev
https://golang.org/cl/5390042
2011-11-30 12:01:46 -05:00
Charles L. Dorian
c8d2544b26 math: update special-conditions comments to use ± symbol
R=rsc, golang-dev, r
CC=golang-dev
https://golang.org/cl/5445046
2011-11-28 13:04:52 -08:00
Charles L. Dorian
f1fecf8d2a math: fix typo in Log1p comments
Also note the special case of -0.0.

R=rsc, golang-dev, gri
CC=golang-dev
https://golang.org/cl/5435084
2011-11-27 18:01:08 -08:00
Michael T. Jones
4c113ffe16 math/big: use recursive subdivision for significant speedup
This change adds the second aspect to the conversion code, the
use of large divisiors (powers of big base) to greatly speed up
the divsion of large numbers. Speedups of 30x are common in the
large cases. Also includes new tests and tuning code for the
key internal parameters.

R=gri
CC=golang-dev
https://golang.org/cl/5438058
2011-11-27 11:10:59 -08:00
Charles L. Dorian
f3aa54e30d math: faster Cbrt
For amd64, from 127 to 105 ns/op; for 386, from 208 to 169 ns/op.

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5412056
2011-11-21 09:56:07 -05:00
Robert Griesemer
f5cf0a486e math/big: replace nat{} -> nat(nil)
No need for creating a new nat each time.
Per Roger Peppe's suggestion; assuming
nat(nil) produces better code than nat{}.

R=rsc
CC=golang-dev
https://golang.org/cl/5375092
2011-11-14 13:35:22 -08:00
David G. Andersen
120f3b7b9d math/big: Correcting typo in SetBit() documentation
z is set to x+bit change, not z+bit change

R=golang-dev
CC=golang-dev
https://golang.org/cl/5374056
2011-11-10 14:41:24 -05:00
Charles L. Dorian
300b443ade math: faster Lgamma
Converting from polynomial constants to counted array speeds up Lgamma from 51.3 to 37.7 ns/op. Variables renamed in Gamma to avoid overlap in Lgamma.

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5359045
2011-11-09 15:44:49 -05:00
Rob Pike
45e3bcb343 renaming_3: gofix -r go1pkgrename src/pkg/[m-z]*
R=rsc
CC=golang-dev
https://golang.org/cl/5345045
2011-11-08 15:41:54 -08:00
Rob Pike
6ab6c49fce renaming_1: hand-edited files for go 1 renaming
This contains the files that required handiwork, mostly
Makefiles with updated TARGs, plus the two packages
with modified package names.
html/template/doc.go needs a separate edit pass.
test/fixedbugs/bug358.go is not legal go so gofix fails on it.

R=rsc
CC=golang-dev
https://golang.org/cl/5340050
2011-11-08 15:38:47 -08:00
Charles L. Dorian
c171633780 math: faster Gamma
Having the compiler count the number of array elements speeds up Gamma from 63.7 to 56.6 ns/op.

R=rsc, golang-dev, r
CC=golang-dev
https://golang.org/cl/5362043
2011-11-05 12:25:36 -07:00
Charles L. Dorian
377ac335af math: improved high-angle test for Cos, Sin and Tan
Maximum error for 386 is "close" (1e-14). For amd64, it's "veryclose" (4e-16).

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5340042
2011-11-04 15:35:59 -04:00
Vincent Vanackere
eb1717e035 all: rename os.EOF to io.EOF in various non-code contexts
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5334050
2011-11-03 14:01:30 -07:00
Rob Pike
5cb4a15320 html,log,math: renamings
This is Go 1 package renaming CL #2.
This one merely moves the source; the import strings will be
changed after the next weekly release.

exp/template/html -> html/template
big -> math/big
cmath -> math/cmplx
rand -> math/rand
syslog -> log/syslog

The only edits are in Makefiles and deps.bash.

Note that this CL moves exp/template/html out of exp. I decided
to do that so all the renamings can be done together, even though
the API (and that of template, for that matter) is still fluid.

R=r, rsc
CC=golang-dev
https://golang.org/cl/5332053
2011-11-03 12:42:57 -07:00
Charles L. Dorian
cefee3c919 math: improved accuracy for Tan
R=rsc
CC=golang-dev
https://golang.org/cl/5298087
2011-11-02 14:01:21 -04:00