diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-07-16 06:54:42 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-07-16 06:54:42 +0000 |
commit | f4ca453c9530ff24478cae090c9979b97fdd7411 (patch) | |
tree | 0e8fda573576bb4181dba29d0e88380a8c38fafd /libgo/go/math | |
parent | 84a4a7d4b2fecf754bc0b7fce55b05912a054ef4 (diff) | |
download | gcc-f4ca453c9530ff24478cae090c9979b97fdd7411.tar.gz |
libgo: Update to Go 1.1.1.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@200974 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/math')
-rw-r--r-- | libgo/go/math/big/int.go | 16 | ||||
-rw-r--r-- | libgo/go/math/big/nat.go | 2 | ||||
-rw-r--r-- | libgo/go/math/big/rat.go | 14 | ||||
-rw-r--r-- | libgo/go/math/big/rat_test.go | 45 | ||||
-rw-r--r-- | libgo/go/math/hypot.go | 6 | ||||
-rw-r--r-- | libgo/go/math/rand/exp.go | 1 | ||||
-rw-r--r-- | libgo/go/math/rand/normal.go | 1 | ||||
-rw-r--r-- | libgo/go/math/rand/zipf.go | 6 | ||||
-rw-r--r-- | libgo/go/math/sqrt.go | 8 | ||||
-rw-r--r-- | libgo/go/math/tanh.go | 2 |
10 files changed, 44 insertions, 57 deletions
diff --git a/libgo/go/math/big/int.go b/libgo/go/math/big/int.go index bf2fd200926..d1b5602d668 100644 --- a/libgo/go/math/big/int.go +++ b/libgo/go/math/big/int.go @@ -53,7 +53,7 @@ func (z *Int) SetInt64(x int64) *Int { // SetUint64 sets z to x and returns z. func (z *Int) SetUint64(x uint64) *Int { - z.abs = z.abs.setUint64(uint64(x)) + z.abs = z.abs.setUint64(x) z.neg = false return z } @@ -513,13 +513,7 @@ func (z *Int) Scan(s fmt.ScanState, ch rune) error { // Int64 returns the int64 representation of x. // If x cannot be represented in an int64, the result is undefined. func (x *Int) Int64() int64 { - if len(x.abs) == 0 { - return 0 - } - v := int64(x.abs[0]) - if _W == 32 && len(x.abs) > 1 { - v |= int64(x.abs[1]) << 32 - } + v := int64(x.Uint64()) if x.neg { v = -v } @@ -527,7 +521,7 @@ func (x *Int) Int64() int64 { } // Uint64 returns the uint64 representation of x. -// If x cannot be represented in an uint64, the result is undefined. +// If x cannot be represented in a uint64, the result is undefined. func (x *Int) Uint64() uint64 { if len(x.abs) == 0 { return 0 @@ -795,8 +789,8 @@ func (x *Int) Bit(i int) uint { } // SetBit sets z to x, with x's i'th bit set to b (0 or 1). -// That is, if bit is 1 SetBit sets z = x | (1 << i); -// if bit is 0 it sets z = x &^ (1 << i). If bit is not 0 or 1, +// That is, if b is 1 SetBit sets z = x | (1 << i); +// if b is 0 SetBit sets z = x &^ (1 << i). If b is not 0 or 1, // SetBit will panic. func (z *Int) SetBit(x *Int, i int, b uint) *Int { if i < 0 { diff --git a/libgo/go/math/big/nat.go b/libgo/go/math/big/nat.go index 9d09f97b77b..6874900d0bd 100644 --- a/libgo/go/math/big/nat.go +++ b/libgo/go/math/big/nat.go @@ -1021,8 +1021,6 @@ func trailingZeroBits(x Word) uint { default: panic("unknown word size") } - - return 0 } // trailingZeroBits returns the number of consecutive least significant zero diff --git a/libgo/go/math/big/rat.go b/libgo/go/math/big/rat.go index 3e6473d9224..75d044fe21d 100644 --- a/libgo/go/math/big/rat.go +++ b/libgo/go/math/big/rat.go @@ -163,16 +163,16 @@ func quotToFloat(a, b nat) (f float64, exact bool) { return } -// Float64 returns the nearest float64 value to z. -// If z is exactly representable as a float64, Float64 returns exact=true. -// If z is negative, so too is f, even if f==0. -func (z *Rat) Float64() (f float64, exact bool) { - b := z.b.abs +// Float64 returns the nearest float64 value for x and a bool indicating +// whether f represents x exactly. The sign of f always matches the sign +// of x, even if f == 0. +func (x *Rat) Float64() (f float64, exact bool) { + b := x.b.abs if len(b) == 0 { b = b.set(natOne) // materialize denominator } - f, exact = quotToFloat(z.a.abs, b) - if z.a.neg { + f, exact = quotToFloat(x.a.abs, b) + if x.a.neg { f = -f } return diff --git a/libgo/go/math/big/rat_test.go b/libgo/go/math/big/rat_test.go index 4b4134b410f..1c2c642379c 100644 --- a/libgo/go/math/big/rat_test.go +++ b/libgo/go/math/big/rat_test.go @@ -500,12 +500,10 @@ func TestIssue3521(t *testing.T) { } } -// Test inputs to Rat.SetString. The optional prefix "slow:" skips -// checks found to be slow for certain large rationals. +// Test inputs to Rat.SetString. The prefix "long:" causes the test +// to be skipped in --test.short mode. (The threshold is about 500us.) var float64inputs = []string{ - // // Constants plundered from strconv/testfp.txt. - // // Table 1: Stress Inputs for Conversion to 53-bit Binary, < 1/2 ULP "5e+125", @@ -583,9 +581,7 @@ var float64inputs = []string{ "75224575729e-45", "459926601011e+15", - // // Constants plundered from strconv/atof_test.go. - // "0", "1", @@ -630,8 +626,8 @@ var float64inputs = []string{ "-1e310", "1e400", "-1e400", - "1e400000", - "-1e400000", + "long:1e400000", + "long:-1e400000", // denormalized "1e-305", @@ -649,10 +645,10 @@ var float64inputs = []string{ "2e-324", // way too small "1e-350", - "slow:1e-400000", + "long:1e-400000", // way too small, negative "-1e-350", - "slow:-1e-400000", + "long:-1e-400000", // try to overflow exponent // [Disabled: too slow and memory-hungry with rationals.] @@ -672,7 +668,7 @@ var float64inputs = []string{ // A different kind of very large number. "22.222222222222222", - "2." + strings.Repeat("2", 4000) + "e+1", + "long:2." + strings.Repeat("2", 4000) + "e+1", // Exactly halfway between 1 and math.Nextafter(1, 2). // Round to even (down). @@ -682,7 +678,7 @@ var float64inputs = []string{ // Slightly higher; round up. "1.00000000000000011102230246251565404236316680908203126", // Slightly higher, but you have to read all the way to the end. - "slow:1.00000000000000011102230246251565404236316680908203125" + strings.Repeat("0", 10000) + "1", + "long:1.00000000000000011102230246251565404236316680908203125" + strings.Repeat("0", 10000) + "1", // Smallest denormal, 2^(-1022-52) "4.940656458412465441765687928682213723651e-324", @@ -705,9 +701,11 @@ var float64inputs = []string{ func TestFloat64SpecialCases(t *testing.T) { for _, input := range float64inputs { - slow := strings.HasPrefix(input, "slow:") - if slow { - input = input[len("slow:"):] + if strings.HasPrefix(input, "long:") { + if testing.Short() { + continue + } + input = input[len("long:"):] } r, ok := new(Rat).SetString(input) @@ -732,11 +730,11 @@ func TestFloat64SpecialCases(t *testing.T) { case f == 0 && r.Num().BitLen() == 0: // Ok: Rat(0) is equivalent to both +/- float64(0). default: - t.Errorf("strconv.ParseFloat(%q) = %g (%b), want %g (%b); delta=%g", input, e, e, f, f, f-e) + t.Errorf("strconv.ParseFloat(%q) = %g (%b), want %g (%b); delta = %g", input, e, e, f, f, f-e) } } - if !isFinite(f) || slow { + if !isFinite(f) { continue } @@ -751,7 +749,7 @@ func TestFloat64SpecialCases(t *testing.T) { // 4. Check exactness using slow algorithm. if wasExact := new(Rat).SetFloat64(f).Cmp(r) == 0; wasExact != exact { - t.Errorf("Rat.SetString(%q).Float64().exact = %b, want %b", input, exact, wasExact) + t.Errorf("Rat.SetString(%q).Float64().exact = %t, want %t", input, exact, wasExact) } } } @@ -769,8 +767,11 @@ func TestFloat64Distribution(t *testing.T) { 9, 11, } - const winc, einc = 5, 100 // quick test (<1s) - //const winc, einc = 1, 1 // soak test (~75s) + var winc, einc = uint64(1), int(1) // soak test (~75s on x86-64) + if testing.Short() { + winc, einc = 10, 500 // quick test (~12ms on x86-64) + } + for _, sign := range "+-" { for _, a := range add { for wid := uint64(0); wid < 60; wid += winc { @@ -790,7 +791,7 @@ func TestFloat64Distribution(t *testing.T) { if !checkIsBestApprox(t, f, r) { // Append context information. - t.Errorf("(input was mantissa %#x, exp %d; f=%g (%b); f~%g; r=%v)", + t.Errorf("(input was mantissa %#x, exp %d; f = %g (%b); f ~ %g; r = %v)", b, exp, f, f, math.Ldexp(float64(b), exp), r) } @@ -825,7 +826,7 @@ func checkNonLossyRoundtrip(t *testing.T, f float64) { } f2, exact := r.Float64() if f != f2 || !exact { - t.Errorf("Rat.SetFloat64(%g).Float64() = %g (%b), %v, want %g (%b), %v; delta=%b", + t.Errorf("Rat.SetFloat64(%g).Float64() = %g (%b), %v, want %g (%b), %v; delta = %b", f, f2, f2, exact, f, f, true, f2-f) } } diff --git a/libgo/go/math/hypot.go b/libgo/go/math/hypot.go index a6fa84c7655..59b9c74e1d0 100644 --- a/libgo/go/math/hypot.go +++ b/libgo/go/math/hypot.go @@ -12,8 +12,10 @@ package math // unnecessary overflow and underflow. // // Special cases are: -// Hypot(p, q) = +Inf if p or q is infinite -// Hypot(p, q) = NaN if p or q is NaN +// Hypot(±Inf, q) = +Inf +// Hypot(p, ±Inf) = +Inf +// Hypot(NaN, q) = NaN +// Hypot(p, NaN) = NaN func Hypot(p, q float64) float64 { return hypot(p, q) } diff --git a/libgo/go/math/rand/exp.go b/libgo/go/math/rand/exp.go index 85da495219d..4bc110f9138 100644 --- a/libgo/go/math/rand/exp.go +++ b/libgo/go/math/rand/exp.go @@ -43,7 +43,6 @@ func (r *Rand) ExpFloat64() float64 { return x } } - panic("unreachable") } var ke = [256]uint32{ diff --git a/libgo/go/math/rand/normal.go b/libgo/go/math/rand/normal.go index 9ab46db9f53..ba4ea54cace 100644 --- a/libgo/go/math/rand/normal.go +++ b/libgo/go/math/rand/normal.go @@ -63,7 +63,6 @@ func (r *Rand) NormFloat64() float64 { return x } } - panic("unreachable") } var kn = [128]uint32{ diff --git a/libgo/go/math/rand/zipf.go b/libgo/go/math/rand/zipf.go index 38e8ec5162a..8db2c6f5bff 100644 --- a/libgo/go/math/rand/zipf.go +++ b/libgo/go/math/rand/zipf.go @@ -34,7 +34,6 @@ func (z *Zipf) hinv(x float64) float64 { // NewZipf returns a Zipf generating variates p(k) on [0, imax] // proportional to (v+k)**(-s) where s>1 and k>=0, and v>=1. -// func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf { z := new(Zipf) if s <= 1.0 || v < 1 { @@ -52,9 +51,12 @@ func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf { return z } -// Uint64 returns a value drawn from the Zipf distributed described +// Uint64 returns a value drawn from the Zipf distribution described // by the Zipf object. func (z *Zipf) Uint64() uint64 { + if z == nil { + panic("rand: nil Zipf") + } k := 0.0 for { diff --git a/libgo/go/math/sqrt.go b/libgo/go/math/sqrt.go index b5f297c84b6..78475973eb0 100644 --- a/libgo/go/math/sqrt.go +++ b/libgo/go/math/sqrt.go @@ -4,14 +4,6 @@ package math -// Sqrt returns the square root of x. -// -// Special cases are: -// Sqrt(+Inf) = +Inf -// Sqrt(±0) = ±0 -// Sqrt(x < 0) = NaN -// Sqrt(NaN) = NaN - //extern sqrt func libc_sqrt(float64) float64 diff --git a/libgo/go/math/tanh.go b/libgo/go/math/tanh.go index 7305be66c7f..cf0ffa1923f 100644 --- a/libgo/go/math/tanh.go +++ b/libgo/go/math/tanh.go @@ -65,7 +65,7 @@ var tanhQ = [...]float64{ 4.84406305325125486048E3, } -// Tanh computes the hyperbolic tangent of x. +// Tanh returns the hyperbolic tangent of x. // // Special cases are: // Tanh(±0) = ±0 |