diff options
Diffstat (limited to 'src/pkg/math')
37 files changed, 865 insertions, 114 deletions
diff --git a/src/pkg/math/abs_amd64p32.s b/src/pkg/math/abs_amd64p32.s new file mode 100644 index 000000000..08c8c6b33 --- /dev/null +++ b/src/pkg/math/abs_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "abs_amd64.s" diff --git a/src/pkg/math/asin_amd64p32.s b/src/pkg/math/asin_amd64p32.s new file mode 100644 index 000000000..2751c475f --- /dev/null +++ b/src/pkg/math/asin_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "asin_amd64.s" diff --git a/src/pkg/math/atan2_amd64p32.s b/src/pkg/math/atan2_amd64p32.s new file mode 100644 index 000000000..3fdc03ca8 --- /dev/null +++ b/src/pkg/math/atan2_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "atan2_amd64.s" diff --git a/src/pkg/math/atan_amd64p32.s b/src/pkg/math/atan_amd64p32.s new file mode 100644 index 000000000..1c1f6ceda --- /dev/null +++ b/src/pkg/math/atan_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "atan_amd64.s" diff --git a/src/pkg/math/big/arith.go b/src/pkg/math/big/arith.go index f316806d7..3d5a8682d 100644 --- a/src/pkg/math/big/arith.go +++ b/src/pkg/math/big/arith.go @@ -131,12 +131,11 @@ func divWW_g(u1, u0, v Word) (q, r Word) { q1 := un32 / vn1 rhat := un32 - q1*vn1 -again1: - if q1 >= _B2 || q1*vn0 > _B2*rhat+un1 { + for q1 >= _B2 || q1*vn0 > _B2*rhat+un1 { q1-- rhat += vn1 - if rhat < _B2 { - goto again1 + if rhat >= _B2 { + break } } @@ -144,12 +143,11 @@ again1: q0 := un21 / vn1 rhat = un21 - q0*vn1 -again2: - if q0 >= _B2 || q0*vn0 > _B2*rhat+un0 { + for q0 >= _B2 || q0*vn0 > _B2*rhat+un0 { q0-- rhat += vn1 - if rhat < _B2 { - goto again2 + if rhat >= _B2 { + break } } diff --git a/src/pkg/math/big/arith_amd64p32.s b/src/pkg/math/big/arith_amd64p32.s new file mode 100644 index 000000000..227870a00 --- /dev/null +++ b/src/pkg/math/big/arith_amd64p32.s @@ -0,0 +1,41 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "../../../cmd/ld/textflag.h" + +TEXT ·mulWW(SB),NOSPLIT,$0 + JMP ·mulWW_g(SB) + +TEXT ·divWW(SB),NOSPLIT,$0 + JMP ·divWW_g(SB) + +TEXT ·addVV(SB),NOSPLIT,$0 + JMP ·addVV_g(SB) + +TEXT ·subVV(SB),NOSPLIT,$0 + JMP ·subVV_g(SB) + +TEXT ·addVW(SB),NOSPLIT,$0 + JMP ·addVW_g(SB) + +TEXT ·subVW(SB),NOSPLIT,$0 + JMP ·subVW_g(SB) + +TEXT ·shlVU(SB),NOSPLIT,$0 + JMP ·shlVU_g(SB) + +TEXT ·shrVU(SB),NOSPLIT,$0 + JMP ·shrVU_g(SB) + +TEXT ·mulAddVWW(SB),NOSPLIT,$0 + JMP ·mulAddVWW_g(SB) + +TEXT ·addMulVVW(SB),NOSPLIT,$0 + JMP ·addMulVVW_g(SB) + +TEXT ·divWVW(SB),NOSPLIT,$0 + JMP ·divWVW_g(SB) + +TEXT ·bitLen(SB),NOSPLIT,$0 + JMP ·bitLen_g(SB) diff --git a/src/pkg/math/big/arith_arm.s b/src/pkg/math/big/arith_arm.s index ecf55b344..8d36761c4 100644 --- a/src/pkg/math/big/arith_arm.s +++ b/src/pkg/math/big/arith_arm.s @@ -7,31 +7,26 @@ // This file provides fast assembly versions for the elementary // arithmetic operations on vectors implemented in arith.go. -#define CFLAG 29 // bit position of carry flag - // func addVV(z, x, y []Word) (c Word) TEXT ·addVV(SB),NOSPLIT,$0 - MOVW $0, R0 + ADD.S $0, R0 // clear carry flag MOVW z+0(FP), R1 + MOVW z_len+4(FP), R4 MOVW x+12(FP), R2 MOVW y+24(FP), R3 - MOVW z_len+4(FP), R4 - MOVW R4<<2, R4 - ADD R1, R4 + ADD R4<<2, R1, R4 B E1 L1: MOVW.P 4(R2), R5 MOVW.P 4(R3), R6 - MOVW R0, CPSR ADC.S R6, R5 MOVW.P R5, 4(R1) - MOVW CPSR, R0 E1: - CMP R1, R4 + TEQ R1, R4 BNE L1 - MOVW R0>>CFLAG, R0 - AND $1, R0 + MOVW $0, R0 + MOVW.CS $1, R0 MOVW R0, c+36(FP) RET @@ -39,28 +34,24 @@ E1: // func subVV(z, x, y []Word) (c Word) // (same as addVV except for SBC instead of ADC and label names) TEXT ·subVV(SB),NOSPLIT,$0 - MOVW $(1<<CFLAG), R0 + SUB.S $0, R0 // clear borrow flag MOVW z+0(FP), R1 + MOVW z_len+4(FP), R4 MOVW x+12(FP), R2 MOVW y+24(FP), R3 - MOVW z_len+4(FP), R4 - MOVW R4<<2, R4 - ADD R1, R4 + ADD R4<<2, R1, R4 B E2 L2: MOVW.P 4(R2), R5 MOVW.P 4(R3), R6 - MOVW R0, CPSR SBC.S R6, R5 MOVW.P R5, 4(R1) - MOVW CPSR, R0 E2: - CMP R1, R4 + TEQ R1, R4 BNE L2 - MOVW R0>>CFLAG, R0 - AND $1, R0 - EOR $1, R0 + MOVW $0, R0 + MOVW.CC $1, R0 MOVW R0, c+36(FP) RET @@ -68,12 +59,11 @@ E2: // func addVW(z, x []Word, y Word) (c Word) TEXT ·addVW(SB),NOSPLIT,$0 MOVW z+0(FP), R1 + MOVW z_len+4(FP), R4 MOVW x+12(FP), R2 MOVW y+24(FP), R3 - MOVW z_len+4(FP), R4 - MOVW R4<<2, R4 - ADD R1, R4 - CMP R1, R4 + ADD R4<<2, R1, R4 + TEQ R1, R4 BNE L3a MOVW R3, c+28(FP) RET @@ -81,20 +71,17 @@ L3a: MOVW.P 4(R2), R5 ADD.S R3, R5 MOVW.P R5, 4(R1) - MOVW CPSR, R0 B E3 L3: MOVW.P 4(R2), R5 - MOVW R0, CPSR ADC.S $0, R5 MOVW.P R5, 4(R1) - MOVW CPSR, R0 E3: - CMP R1, R4 + TEQ R1, R4 BNE L3 - MOVW R0>>CFLAG, R0 - AND $1, R0 + MOVW $0, R0 + MOVW.CS $1, R0 MOVW R0, c+28(FP) RET @@ -102,12 +89,11 @@ E3: // func subVW(z, x []Word, y Word) (c Word) TEXT ·subVW(SB),NOSPLIT,$0 MOVW z+0(FP), R1 + MOVW z_len+4(FP), R4 MOVW x+12(FP), R2 MOVW y+24(FP), R3 - MOVW z_len+4(FP), R4 - MOVW R4<<2, R4 - ADD R1, R4 - CMP R1, R4 + ADD R4<<2, R1, R4 + TEQ R1, R4 BNE L4a MOVW R3, c+28(FP) RET @@ -115,21 +101,17 @@ L4a: MOVW.P 4(R2), R5 SUB.S R3, R5 MOVW.P R5, 4(R1) - MOVW CPSR, R0 B E4 L4: MOVW.P 4(R2), R5 - MOVW R0, CPSR SBC.S $0, R5 MOVW.P R5, 4(R1) - MOVW CPSR, R0 E4: - CMP R1, R4 + TEQ R1, R4 BNE L4 - MOVW R0>>CFLAG, R0 - AND $1, R0 - EOR $1, R0 + MOVW $0, R0 + MOVW.CC $1, R0 MOVW R0, c+28(FP) RET @@ -137,16 +119,15 @@ E4: // func shlVU(z, x []Word, s uint) (c Word) TEXT ·shlVU(SB),NOSPLIT,$0 MOVW z_len+4(FP), R5 - CMP $0, R5 + TEQ $0, R5 BEQ X7 MOVW z+0(FP), R1 MOVW x+12(FP), R2 - MOVW R5<<2, R5 - ADD R5, R2 - ADD R1, R5 + ADD R5<<2, R2, R2 + ADD R5<<2, R1, R5 MOVW s+24(FP), R3 - CMP $0, R3 // shift 0 is special + TEQ $0, R3 // shift 0 is special BEQ Y7 ADD $4, R1 // stop one word early MOVW $32, R4 @@ -165,7 +146,7 @@ L7: MOVW.W R7, -4(R5) MOVW R6<<R3, R7 E7: - CMP R1, R5 + TEQ R1, R5 BNE L7 MOVW R7, -4(R5) @@ -174,7 +155,7 @@ E7: Y7: // copy loop, because shift 0 == shift 32 MOVW.W -4(R2), R6 MOVW.W R6, -4(R5) - CMP R1, R5 + TEQ R1, R5 BNE Y7 X7: @@ -186,15 +167,14 @@ X7: // func shrVU(z, x []Word, s uint) (c Word) TEXT ·shrVU(SB),NOSPLIT,$0 MOVW z_len+4(FP), R5 - CMP $0, R5 + TEQ $0, R5 BEQ X6 MOVW z+0(FP), R1 MOVW x+12(FP), R2 - MOVW R5<<2, R5 - ADD R1, R5 + ADD R5<<2, R1, R5 MOVW s+24(FP), R3 - CMP $0, R3 // shift 0 is special + TEQ $0, R3 // shift 0 is special BEQ Y6 SUB $4, R5 // stop one word early MOVW $32, R4 @@ -215,7 +195,7 @@ L6: MOVW.P R7, 4(R1) MOVW R6>>R3, R7 E6: - CMP R1, R5 + TEQ R1, R5 BNE L6 MOVW R7, 0(R1) @@ -224,7 +204,7 @@ E6: Y6: // copy loop, because shift 0 == shift 32 MOVW.P 4(R2), R6 MOVW.P R6, 4(R1) - CMP R1, R5 + TEQ R1, R5 BNE Y6 X6: @@ -237,12 +217,11 @@ X6: TEXT ·mulAddVWW(SB),NOSPLIT,$0 MOVW $0, R0 MOVW z+0(FP), R1 + MOVW z_len+4(FP), R5 MOVW x+12(FP), R2 MOVW y+24(FP), R3 MOVW r+28(FP), R4 - MOVW z_len+4(FP), R5 - MOVW R5<<2, R5 - ADD R1, R5 + ADD R5<<2, R1, R5 B E8 // word loop @@ -254,7 +233,7 @@ L8: MOVW.P R6, 4(R1) MOVW R7, R4 E8: - CMP R1, R5 + TEQ R1, R5 BNE L8 MOVW R4, c+32(FP) @@ -265,11 +244,10 @@ E8: TEXT ·addMulVVW(SB),NOSPLIT,$0 MOVW $0, R0 MOVW z+0(FP), R1 + MOVW z_len+4(FP), R5 MOVW x+12(FP), R2 MOVW y+24(FP), R3 - MOVW z_len+4(FP), R5 - MOVW R5<<2, R5 - ADD R1, R5 + ADD R5<<2, R1, R5 MOVW $0, R4 B E9 @@ -285,7 +263,7 @@ L9: MOVW.P R6, 4(R1) MOVW R7, R4 E9: - CMP R1, R5 + TEQ R1, R5 BNE L9 MOVW R4, c+28(FP) @@ -317,7 +295,6 @@ TEXT ·mulWW(SB),NOSPLIT,$0 TEXT ·bitLen(SB),NOSPLIT,$0 MOVW x+0(FP), R0 CLZ R0, R0 - MOVW $32, R1 - SUB.S R0, R1 - MOVW R1, n+4(FP) + RSB $32, R0 + MOVW R0, n+4(FP) RET diff --git a/src/pkg/math/big/int.go b/src/pkg/math/big/int.go index 7bbb152d7..269949d61 100644 --- a/src/pkg/math/big/int.go +++ b/src/pkg/math/big/int.go @@ -576,21 +576,22 @@ func (x *Int) BitLen() int { } // Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z. -// If y <= 0, the result is 1; if m == nil or m == 0, z = x**y. +// If y <= 0, the result is 1 mod |m|; if m == nil or m == 0, z = x**y. // See Knuth, volume 2, section 4.6.3. func (z *Int) Exp(x, y, m *Int) *Int { - if y.neg || len(y.abs) == 0 { - return z.SetInt64(1) + var yWords nat + if !y.neg { + yWords = y.abs } - // y > 0 + // y >= 0 var mWords nat if m != nil { mWords = m.abs // m.abs may be nil for m == 0 } - z.abs = z.abs.expNN(x.abs, y.abs, mWords) - z.neg = len(z.abs) > 0 && x.neg && y.abs[0]&1 == 1 // 0 has no sign + z.abs = z.abs.expNN(x.abs, yWords, mWords) + z.neg = len(z.abs) > 0 && x.neg && len(yWords) > 0 && yWords[0]&1 == 1 // 0 has no sign return z } @@ -982,17 +983,29 @@ func (z *Int) GobDecode(buf []byte) error { } // MarshalJSON implements the json.Marshaler interface. -func (x *Int) MarshalJSON() ([]byte, error) { +func (z *Int) MarshalJSON() ([]byte, error) { // TODO(gri): get rid of the []byte/string conversions - return []byte(x.String()), nil + return []byte(z.String()), nil } // UnmarshalJSON implements the json.Unmarshaler interface. -func (z *Int) UnmarshalJSON(x []byte) error { +func (z *Int) UnmarshalJSON(text []byte) error { // TODO(gri): get rid of the []byte/string conversions - _, ok := z.SetString(string(x), 0) - if !ok { - return fmt.Errorf("math/big: cannot unmarshal %s into a *big.Int", x) + if _, ok := z.SetString(string(text), 0); !ok { + return fmt.Errorf("math/big: cannot unmarshal %q into a *big.Int", text) + } + return nil +} + +// MarshalText implements the encoding.TextMarshaler interface +func (z *Int) MarshalText() (text []byte, err error) { + return []byte(z.String()), nil +} + +// UnmarshalText implements the encoding.TextUnmarshaler interface +func (z *Int) UnmarshalText(text []byte) error { + if _, ok := z.SetString(string(text), 0); !ok { + return fmt.Errorf("math/big: cannot unmarshal %q into a *big.Int", text) } return nil } diff --git a/src/pkg/math/big/int_test.go b/src/pkg/math/big/int_test.go index 87b975d5c..299dc72fb 100644 --- a/src/pkg/math/big/int_test.go +++ b/src/pkg/math/big/int_test.go @@ -9,6 +9,7 @@ import ( "encoding/gob" "encoding/hex" "encoding/json" + "encoding/xml" "fmt" "math/rand" "testing" @@ -767,6 +768,19 @@ var expTests = []struct { x, y, m string out string }{ + // y <= 0 + {"0", "0", "", "1"}, + {"1", "0", "", "1"}, + {"-10", "0", "", "1"}, + {"1234", "-1", "", "1"}, + + // m == 1 + {"0", "0", "1", "0"}, + {"1", "0", "1", "0"}, + {"-10", "0", "1", "0"}, + {"1234", "-1", "1", "0"}, + + // misc {"5", "-7", "", "1"}, {"-5", "-7", "", "1"}, {"5", "0", "", "1"}, @@ -1528,6 +1542,58 @@ func TestIntJSONEncoding(t *testing.T) { } } +var intVals = []string{ + "-141592653589793238462643383279502884197169399375105820974944592307816406286", + "-1415926535897932384626433832795028841971", + "-141592653589793", + "-1", + "0", + "1", + "141592653589793", + "1415926535897932384626433832795028841971", + "141592653589793238462643383279502884197169399375105820974944592307816406286", +} + +func TestIntJSONEncodingTextMarshaller(t *testing.T) { + for _, num := range intVals { + var tx Int + tx.SetString(num, 0) + b, err := json.Marshal(&tx) + if err != nil { + t.Errorf("marshaling of %s failed: %s", &tx, err) + continue + } + var rx Int + if err := json.Unmarshal(b, &rx); err != nil { + t.Errorf("unmarshaling of %s failed: %s", &tx, err) + continue + } + if rx.Cmp(&tx) != 0 { + t.Errorf("JSON encoding of %s failed: got %s want %s", &tx, &rx, &tx) + } + } +} + +func TestIntXMLEncodingTextMarshaller(t *testing.T) { + for _, num := range intVals { + var tx Int + tx.SetString(num, 0) + b, err := xml.Marshal(&tx) + if err != nil { + t.Errorf("marshaling of %s failed: %s", &tx, err) + continue + } + var rx Int + if err := xml.Unmarshal(b, &rx); err != nil { + t.Errorf("unmarshaling of %s failed: %s", &tx, err) + continue + } + if rx.Cmp(&tx) != 0 { + t.Errorf("XML encoding of %s failed: got %s want %s", &tx, &rx, &tx) + } + } +} + func TestIssue2607(t *testing.T) { // This code sequence used to hang. n := NewInt(10) diff --git a/src/pkg/math/big/nat.go b/src/pkg/math/big/nat.go index 6874900d0..16a87f5c5 100644 --- a/src/pkg/math/big/nat.go +++ b/src/pkg/math/big/nat.go @@ -1233,10 +1233,15 @@ func (z nat) expNN(x, y, m nat) nat { z = nil } + // x**y mod 1 == 0 + if len(m) == 1 && m[0] == 1 { + return z.setWord(0) + } + // m == 0 || m > 1 + + // x**0 == 1 if len(y) == 0 { - z = z.make(1) - z[0] = 1 - return z + return z.setWord(1) } // y > 0 diff --git a/src/pkg/math/big/nat_test.go b/src/pkg/math/big/nat_test.go index 1d4dfe80d..a2ae53385 100644 --- a/src/pkg/math/big/nat_test.go +++ b/src/pkg/math/big/nat_test.go @@ -437,20 +437,11 @@ func BenchmarkStringPiParallel(b *testing.B) { if x.decimalString() != pi { panic("benchmark incorrect: conversion failed") } - n := runtime.GOMAXPROCS(0) - m := b.N / n // n*m <= b.N due to flooring, but the error is neglibible (n is not very large) - c := make(chan int, n) - for i := 0; i < n; i++ { - go func() { - for j := 0; j < m; j++ { - x.decimalString() - } - c <- 0 - }() - } - for i := 0; i < n; i++ { - <-c - } + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + x.decimalString() + } + }) } func BenchmarkScan10Base2(b *testing.B) { ScanHelper(b, 2, 10, 10) } @@ -723,6 +714,12 @@ var expNNTests = []struct { x, y, m string out string }{ + {"0", "0", "0", "1"}, + {"0", "0", "1", "0"}, + {"1", "1", "1", "0"}, + {"2", "1", "1", "0"}, + {"2", "2", "1", "0"}, + {"10", "100000000000", "1", "0"}, {"0x8000000000000000", "2", "", "0x40000000000000000000000000000000"}, {"0x8000000000000000", "2", "6719", "4944"}, {"0x8000000000000000", "3", "6719", "5447"}, @@ -750,7 +747,7 @@ func TestExpNN(t *testing.T) { z := nat(nil).expNN(x, y, m) if z.cmp(out) != 0 { - t.Errorf("#%d got %v want %v", i, z, out) + t.Errorf("#%d got %s want %s", i, z.decimalString(), out.decimalString()) } } } diff --git a/src/pkg/math/big/rat.go b/src/pkg/math/big/rat.go index 7faee61a4..f0973b390 100644 --- a/src/pkg/math/big/rat.go +++ b/src/pkg/math/big/rat.go @@ -47,7 +47,7 @@ func (z *Rat) SetFloat64(f float64) *Rat { shift := 52 - exp - // Optimisation (?): partially pre-normalise. + // Optimization (?): partially pre-normalise. for mantissa&1 == 0 && shift > 0 { mantissa >>= 1 shift-- @@ -477,7 +477,7 @@ func (z *Rat) SetString(s string) (*Rat, bool) { return z, true } -// String returns a string representation of z in the form "a/b" (even if b == 1). +// String returns a string representation of x in the form "a/b" (even if b == 1). func (x *Rat) String() string { s := "/1" if len(x.b.abs) != 0 { @@ -486,7 +486,7 @@ func (x *Rat) String() string { return x.a.String() + s } -// RatString returns a string representation of z in the form "a/b" if b != 1, +// RatString returns a string representation of x in the form "a/b" if b != 1, // and in the form "a" if b == 1. func (x *Rat) RatString() string { if x.IsInt() { @@ -495,7 +495,7 @@ func (x *Rat) RatString() string { return x.String() } -// FloatString returns a string representation of z in decimal form with prec +// FloatString returns a string representation of x in decimal form with prec // digits of precision after the decimal point and the last digit rounded. func (x *Rat) FloatString(prec int) string { if x.IsInt() { @@ -585,3 +585,16 @@ func (z *Rat) GobDecode(buf []byte) error { z.b.abs = z.b.abs.setBytes(buf[i:]) return nil } + +// MarshalText implements the encoding.TextMarshaler interface +func (r *Rat) MarshalText() (text []byte, err error) { + return []byte(r.RatString()), nil +} + +// UnmarshalText implements the encoding.TextUnmarshaler interface +func (r *Rat) UnmarshalText(text []byte) error { + if _, ok := r.SetString(string(text)); !ok { + return fmt.Errorf("math/big: cannot unmarshal %q into a *big.Rat", text) + } + return nil +} diff --git a/src/pkg/math/big/rat_test.go b/src/pkg/math/big/rat_test.go index 0d432637b..414a67d41 100644 --- a/src/pkg/math/big/rat_test.go +++ b/src/pkg/math/big/rat_test.go @@ -7,6 +7,8 @@ package big import ( "bytes" "encoding/gob" + "encoding/json" + "encoding/xml" "fmt" "math" "strconv" @@ -433,6 +435,69 @@ func TestGobEncodingNilRatInSlice(t *testing.T) { } } +var ratNums = []string{ + "-141592653589793238462643383279502884197169399375105820974944592307816406286", + "-1415926535897932384626433832795028841971", + "-141592653589793", + "-1", + "0", + "1", + "141592653589793", + "1415926535897932384626433832795028841971", + "141592653589793238462643383279502884197169399375105820974944592307816406286", +} + +var ratDenoms = []string{ + "1", + "718281828459045", + "7182818284590452353602874713526624977572", + "718281828459045235360287471352662497757247093699959574966967627724076630353", +} + +func TestRatJSONEncoding(t *testing.T) { + for _, num := range ratNums { + for _, denom := range ratDenoms { + var tx Rat + tx.SetString(num + "/" + denom) + b, err := json.Marshal(&tx) + if err != nil { + t.Errorf("marshaling of %s failed: %s", &tx, err) + continue + } + var rx Rat + if err := json.Unmarshal(b, &rx); err != nil { + t.Errorf("unmarshaling of %s failed: %s", &tx, err) + continue + } + if rx.Cmp(&tx) != 0 { + t.Errorf("JSON encoding of %s failed: got %s want %s", &tx, &rx, &tx) + } + } + } +} + +func TestRatXMLEncoding(t *testing.T) { + for _, num := range ratNums { + for _, denom := range ratDenoms { + var tx Rat + tx.SetString(num + "/" + denom) + b, err := xml.Marshal(&tx) + if err != nil { + t.Errorf("marshaling of %s failed: %s", &tx, err) + continue + } + var rx Rat + if err := xml.Unmarshal(b, &rx); err != nil { + t.Errorf("unmarshaling of %s failed: %s", &tx, err) + continue + } + if rx.Cmp(&tx) != 0 { + t.Errorf("XML encoding of %s failed: got %s want %s", &tx, &rx, &tx) + } + } + } +} + func TestIssue2379(t *testing.T) { // 1) no aliasing q := NewRat(3, 2) diff --git a/src/pkg/math/cmplx/cmath_test.go b/src/pkg/math/cmplx/cmath_test.go index 610ca8ceb..f285646af 100644 --- a/src/pkg/math/cmplx/cmath_test.go +++ b/src/pkg/math/cmplx/cmath_test.go @@ -656,6 +656,19 @@ func TestPolar(t *testing.T) { } } func TestPow(t *testing.T) { + // Special cases for Pow(0, c). + var zero = complex(0, 0) + zeroPowers := [][2]complex128{ + {0, 1 + 0i}, + {1.5, 0 + 0i}, + {-1.5, complex(math.Inf(0), 0)}, + {-1.5 + 1.5i, Inf()}, + } + for _, zp := range zeroPowers { + if f := Pow(zero, zp[0]); f != zp[1] { + t.Errorf("Pow(%g, %g) = %g, want %g", zero, zp[0], f, zp[1]) + } + } var a = complex(3.0, 3.0) for i := 0; i < len(vc); i++ { if f := Pow(a, vc[i]); !cSoclose(pow[i], f, 4e-15) { diff --git a/src/pkg/math/cmplx/pow.go b/src/pkg/math/cmplx/pow.go index 4dbc58398..1630b879b 100644 --- a/src/pkg/math/cmplx/pow.go +++ b/src/pkg/math/cmplx/pow.go @@ -43,7 +43,25 @@ import "math" // IEEE -10,+10 30000 9.4e-15 1.5e-15 // Pow returns x**y, the base-x exponential of y. +// For generalized compatibility with math.Pow: +// Pow(0, ±0) returns 1+0i +// Pow(0, c) for real(c)<0 returns Inf+0i if imag(c) is zero, otherwise Inf+Inf i. func Pow(x, y complex128) complex128 { + if x == 0 { // Guaranteed also true for x == -0. + r, i := real(y), imag(y) + switch { + case r == 0: + return 1 + case r < 0: + if i == 0 { + return complex(math.Inf(1), 0) + } + return Inf() + case r > 0: + return 0 + } + panic("not reached") + } modulus := Abs(x) if modulus == 0 { return complex(0, 0) diff --git a/src/pkg/math/cmplx/sqrt.go b/src/pkg/math/cmplx/sqrt.go index 179b5396a..4ef6807ad 100644 --- a/src/pkg/math/cmplx/sqrt.go +++ b/src/pkg/math/cmplx/sqrt.go @@ -54,6 +54,7 @@ import "math" // IEEE -10,+10 1,000,000 2.9e-16 6.1e-17 // Sqrt returns the square root of x. +// The result r is chosen so that real(r) ≥ 0 and imag(r) has the same sign as imag(x). func Sqrt(x complex128) complex128 { if imag(x) == 0 { if real(x) == 0 { diff --git a/src/pkg/math/dim_amd64p32.s b/src/pkg/math/dim_amd64p32.s new file mode 100644 index 000000000..e5e34479d --- /dev/null +++ b/src/pkg/math/dim_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "dim_amd64.s" diff --git a/src/pkg/math/exp2_amd64p32.s b/src/pkg/math/exp2_amd64p32.s new file mode 100644 index 000000000..4d3830914 --- /dev/null +++ b/src/pkg/math/exp2_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "exp2_amd64.s" diff --git a/src/pkg/math/exp_amd64p32.s b/src/pkg/math/exp_amd64p32.s new file mode 100644 index 000000000..98ac2e91e --- /dev/null +++ b/src/pkg/math/exp_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "exp_amd64.s" diff --git a/src/pkg/math/expm1_amd64p32.s b/src/pkg/math/expm1_amd64p32.s new file mode 100644 index 000000000..709ebefcb --- /dev/null +++ b/src/pkg/math/expm1_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "expm1_amd64.s" diff --git a/src/pkg/math/floor_amd64p32.s b/src/pkg/math/floor_amd64p32.s new file mode 100644 index 000000000..5b87d7a40 --- /dev/null +++ b/src/pkg/math/floor_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "floor_amd64.s" diff --git a/src/pkg/math/frexp_amd64p32.s b/src/pkg/math/frexp_amd64p32.s new file mode 100644 index 000000000..fbb564539 --- /dev/null +++ b/src/pkg/math/frexp_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "frexp_amd64.s" diff --git a/src/pkg/math/hypot_amd64p32.s b/src/pkg/math/hypot_amd64p32.s new file mode 100644 index 000000000..b84542ae3 --- /dev/null +++ b/src/pkg/math/hypot_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "hypot_amd64.s" diff --git a/src/pkg/math/ldexp_amd64p32.s b/src/pkg/math/ldexp_amd64p32.s new file mode 100644 index 000000000..9aa9d9da3 --- /dev/null +++ b/src/pkg/math/ldexp_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "ldexp_amd64.s" diff --git a/src/pkg/math/log10_amd64p32.s b/src/pkg/math/log10_amd64p32.s new file mode 100644 index 000000000..bf43841e2 --- /dev/null +++ b/src/pkg/math/log10_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "log10_amd64.s" diff --git a/src/pkg/math/log1p_amd64p32.s b/src/pkg/math/log1p_amd64p32.s new file mode 100644 index 000000000..a14b5e38a --- /dev/null +++ b/src/pkg/math/log1p_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "log1p_amd64.s" diff --git a/src/pkg/math/log_amd64p32.s b/src/pkg/math/log_amd64p32.s new file mode 100644 index 000000000..5058d607e --- /dev/null +++ b/src/pkg/math/log_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "log_amd64.s" diff --git a/src/pkg/math/mod_amd64p32.s b/src/pkg/math/mod_amd64p32.s new file mode 100644 index 000000000..c1b231124 --- /dev/null +++ b/src/pkg/math/mod_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "mod_amd64.s" diff --git a/src/pkg/math/modf_amd64p32.s b/src/pkg/math/modf_amd64p32.s new file mode 100644 index 000000000..5508c2547 --- /dev/null +++ b/src/pkg/math/modf_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "modf_amd64.s" diff --git a/src/pkg/math/rand/rand.go b/src/pkg/math/rand/rand.go index 2157cdb46..3ffb5c4e5 100644 --- a/src/pkg/math/rand/rand.go +++ b/src/pkg/math/rand/rand.go @@ -60,6 +60,9 @@ func (r *Rand) Int63n(n int64) int64 { if n <= 0 { panic("invalid argument to Int63n") } + if n&(n-1) == 0 { // n is power of two, can mask + return r.Int63() & (n - 1) + } max := int64((1 << 63) - 1 - (1<<63)%uint64(n)) v := r.Int63() for v > max { @@ -74,6 +77,9 @@ func (r *Rand) Int31n(n int32) int32 { if n <= 0 { panic("invalid argument to Int31n") } + if n&(n-1) == 0 { // n is power of two, can mask + return r.Int31() & (n - 1) + } max := int32((1 << 31) - 1 - (1<<31)%uint32(n)) v := r.Int31() for v > max { @@ -95,20 +101,54 @@ func (r *Rand) Intn(n int) int { } // Float64 returns, as a float64, a pseudo-random number in [0.0,1.0). -func (r *Rand) Float64() float64 { return float64(r.Int63()) / (1 << 63) } +func (r *Rand) Float64() float64 { + // A clearer, simpler implementation would be: + // return float64(r.Int63n(1<<53)) / (1<<53) + // However, Go 1 shipped with + // return float64(r.Int63()) / (1 << 63) + // and we want to preserve that value stream. + // + // There is one bug in the value stream: r.Int63() may be so close + // to 1<<63 that the division rounds up to 1.0, and we've guaranteed + // that the result is always less than 1.0. To fix that, we treat the + // range as cyclic and map 1 back to 0. This is justified by observing + // that while some of the values rounded down to 0, nothing was + // rounding up to 0, so 0 was underrepresented in the results. + // Mapping 1 back to zero restores some balance. + // (The balance is not perfect because the implementation + // returns denormalized numbers for very small r.Int63(), + // and those steal from what would normally be 0 results.) + // The remapping only happens 1/2⁵³ of the time, so most clients + // will not observe it anyway. + f := float64(r.Int63()) / (1 << 63) + if f == 1 { + f = 0 + } + return f +} // Float32 returns, as a float32, a pseudo-random number in [0.0,1.0). -func (r *Rand) Float32() float32 { return float32(r.Float64()) } +func (r *Rand) Float32() float32 { + // Same rationale as in Float64: we want to preserve the Go 1 value + // stream except we want to fix it not to return 1.0 + // There is a double rounding going on here, but the argument for + // mapping 1 to 0 still applies: 0 was underrepresented before, + // so mapping 1 to 0 doesn't cause too many 0s. + // This only happens 1/2²⁴ of the time (plus the 1/2⁵³ of the time in Float64). + f := float32(r.Float64()) + if f == 1 { + f = 0 + } + return f +} // Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n). func (r *Rand) Perm(n int) []int { m := make([]int, n) for i := 0; i < n; i++ { - m[i] = i - } - for i := 0; i < n; i++ { j := r.Intn(i + 1) - m[i], m[j] = m[j], m[i] + m[i] = m[j] + m[j] = i } return m } diff --git a/src/pkg/math/rand/rand_test.go b/src/pkg/math/rand/rand_test.go index 4d3abdb60..ab0dc49b4 100644 --- a/src/pkg/math/rand/rand_test.go +++ b/src/pkg/math/rand/rand_test.go @@ -322,6 +322,17 @@ func TestExpTables(t *testing.T) { } } +// For issue 6721, the problem came after 7533753 calls, so check 10e6. +func TestFloat32(t *testing.T) { + r := New(NewSource(1)) + for ct := 0; ct < 10e6; ct++ { + f := r.Float32() + if f >= 1 { + t.Fatal("Float32() should be in range [0,1). ct:", ct, "f:", f) + } + } +} + // Benchmarks func BenchmarkInt63Threadsafe(b *testing.B) { @@ -357,3 +368,31 @@ func BenchmarkInt31n1000(b *testing.B) { r.Int31n(1000) } } + +func BenchmarkFloat32(b *testing.B) { + r := New(NewSource(1)) + for n := b.N; n > 0; n-- { + r.Float32() + } +} + +func BenchmarkFloat64(b *testing.B) { + r := New(NewSource(1)) + for n := b.N; n > 0; n-- { + r.Float64() + } +} + +func BenchmarkPerm3(b *testing.B) { + r := New(NewSource(1)) + for n := b.N; n > 0; n-- { + r.Perm(3) + } +} + +func BenchmarkPerm30(b *testing.B) { + r := New(NewSource(1)) + for n := b.N; n > 0; n-- { + r.Perm(30) + } +} diff --git a/src/pkg/math/rand/regress_test.go b/src/pkg/math/rand/regress_test.go new file mode 100644 index 000000000..2b012af89 --- /dev/null +++ b/src/pkg/math/rand/regress_test.go @@ -0,0 +1,355 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that random number sequences generated by a specific seed +// do not change from version to version. +// +// Do NOT make changes to the golden outputs. If bugs need to be fixed +// in the underlying code, find ways to fix them that do not affect the +// outputs. + +package rand_test + +import ( + "flag" + "fmt" + . "math/rand" + "reflect" + "testing" +) + +var printgolden = flag.Bool("printgolden", false, "print golden results for regression test") + +func TestRegress(t *testing.T) { + var int32s = []int32{1, 10, 32, 1 << 20, 1<<20 + 1, 1000000000, 1 << 30, 1<<31 - 2, 1<<31 - 1} + var int64s = []int64{1, 10, 32, 1 << 20, 1<<20 + 1, 1000000000, 1 << 30, 1<<31 - 2, 1<<31 - 1, 1000000000000000000, 1 << 60, 1<<63 - 2, 1<<63 - 1} + var permSizes = []int{0, 1, 5, 8, 9, 10, 16} + r := New(NewSource(0)) + + rv := reflect.ValueOf(r) + n := rv.NumMethod() + p := 0 + if *printgolden { + fmt.Printf("var regressGolden = []interface{}{\n") + } + for i := 0; i < n; i++ { + m := rv.Type().Method(i) + mv := rv.Method(i) + mt := mv.Type() + if mt.NumOut() == 0 { + continue + } + if mt.NumOut() != 1 { + t.Fatalf("unexpected result count for r.%s", m.Name) + } + r.Seed(0) + for repeat := 0; repeat < 20; repeat++ { + var args []reflect.Value + var argstr string + if mt.NumIn() == 1 { + var x interface{} + switch mt.In(0).Kind() { + default: + t.Fatalf("unexpected argument type for r.%s", m.Name) + + case reflect.Int: + if m.Name == "Perm" { + x = permSizes[repeat%len(permSizes)] + break + } + big := int64s[repeat%len(int64s)] + if int64(int(big)) != big { + r.Int63n(big) // what would happen on 64-bit machine, to keep stream in sync + if *printgolden { + fmt.Printf("\tskipped, // must run printgolden on 64-bit machine\n") + } + p++ + continue + } + x = int(big) + + case reflect.Int32: + x = int32s[repeat%len(int32s)] + + case reflect.Int64: + x = int64s[repeat%len(int64s)] + } + argstr = fmt.Sprint(x) + args = append(args, reflect.ValueOf(x)) + } + out := mv.Call(args)[0].Interface() + if m.Name == "Int" || m.Name == "Intn" { + out = int64(out.(int)) + } + if *printgolden { + var val string + big := int64(1 << 60) + if int64(int(big)) != big && (m.Name == "Int" || m.Name == "Intn") { + // 32-bit machine cannot print 64-bit results + val = "truncated" + } else if reflect.TypeOf(out).Kind() == reflect.Slice { + val = fmt.Sprintf("%#v", out) + } else { + val = fmt.Sprintf("%T(%v)", out, out) + } + fmt.Printf("\t%s, // %s(%s)\n", val, m.Name, argstr) + } else { + want := regressGolden[p] + if m.Name == "Int" { + want = int64(int(uint(want.(int64)) << 1 >> 1)) + } + if !reflect.DeepEqual(out, want) { + t.Errorf("r.%s(%s) = %v, want %v", m.Name, argstr, out, want) + } + } + p++ + } + } + if *printgolden { + fmt.Printf("}\n") + } +} + +var regressGolden = []interface{}{ + float64(4.668112973579268), // ExpFloat64() + float64(0.1601593871172866), // ExpFloat64() + float64(3.0465834105636), // ExpFloat64() + float64(0.06385839451671879), // ExpFloat64() + float64(1.8578917487258961), // ExpFloat64() + float64(0.784676123472182), // ExpFloat64() + float64(0.11225477361256932), // ExpFloat64() + float64(0.20173283329802255), // ExpFloat64() + float64(0.3468619496201105), // ExpFloat64() + float64(0.35601103454384536), // ExpFloat64() + float64(0.888376329507869), // ExpFloat64() + float64(1.4081362450365698), // ExpFloat64() + float64(1.0077753823151994), // ExpFloat64() + float64(0.23594100766227588), // ExpFloat64() + float64(2.777245612300007), // ExpFloat64() + float64(0.5202997830662377), // ExpFloat64() + float64(1.2842705247770294), // ExpFloat64() + float64(0.030307408362776206), // ExpFloat64() + float64(2.204156824853721), // ExpFloat64() + float64(2.09891923895058), // ExpFloat64() + float32(0.94519615), // Float32() + float32(0.24496509), // Float32() + float32(0.65595627), // Float32() + float32(0.05434384), // Float32() + float32(0.3675872), // Float32() + float32(0.28948045), // Float32() + float32(0.1924386), // Float32() + float32(0.65533215), // Float32() + float32(0.8971697), // Float32() + float32(0.16735445), // Float32() + float32(0.28858566), // Float32() + float32(0.9026048), // Float32() + float32(0.84978026), // Float32() + float32(0.2730468), // Float32() + float32(0.6090802), // Float32() + float32(0.253656), // Float32() + float32(0.7746542), // Float32() + float32(0.017480763), // Float32() + float32(0.78707397), // Float32() + float32(0.7993937), // Float32() + float64(0.9451961492941164), // Float64() + float64(0.24496508529377975), // Float64() + float64(0.6559562651954052), // Float64() + float64(0.05434383959970039), // Float64() + float64(0.36758720663245853), // Float64() + float64(0.2894804331565928), // Float64() + float64(0.19243860967493215), // Float64() + float64(0.6553321508148324), // Float64() + float64(0.897169713149801), // Float64() + float64(0.16735444255905835), // Float64() + float64(0.2885856518054551), // Float64() + float64(0.9026048462705047), // Float64() + float64(0.8497802817628735), // Float64() + float64(0.2730468047134829), // Float64() + float64(0.6090801919903561), // Float64() + float64(0.25365600644283687), // Float64() + float64(0.7746542391859803), // Float64() + float64(0.017480762156647272), // Float64() + float64(0.7870739563039942), // Float64() + float64(0.7993936979594545), // Float64() + int64(8717895732742165505), // Int() + int64(2259404117704393152), // Int() + int64(6050128673802995827), // Int() + int64(501233450539197794), // Int() + int64(3390393562759376202), // Int() + int64(2669985732393126063), // Int() + int64(1774932891286980153), // Int() + int64(6044372234677422456), // Int() + int64(8274930044578894929), // Int() + int64(1543572285742637646), // Int() + int64(2661732831099943416), // Int() + int64(8325060299420976708), // Int() + int64(7837839688282259259), // Int() + int64(2518412263346885298), // Int() + int64(5617773211005988520), // Int() + int64(2339563716805116249), // Int() + int64(7144924247938981575), // Int() + int64(161231572858529631), // Int() + int64(7259475919510918339), // Int() + int64(7373105480197164748), // Int() + int32(2029793274), // Int31() + int32(526058514), // Int31() + int32(1408655353), // Int31() + int32(116702506), // Int31() + int32(789387515), // Int31() + int32(621654496), // Int31() + int32(413258767), // Int31() + int32(1407315077), // Int31() + int32(1926657288), // Int31() + int32(359390928), // Int31() + int32(619732968), // Int31() + int32(1938329147), // Int31() + int32(1824889259), // Int31() + int32(586363548), // Int31() + int32(1307989752), // Int31() + int32(544722126), // Int31() + int32(1663557311), // Int31() + int32(37539650), // Int31() + int32(1690228450), // Int31() + int32(1716684894), // Int31() + int32(0), // Int31n(1) + int32(4), // Int31n(10) + int32(25), // Int31n(32) + int32(310570), // Int31n(1048576) + int32(857611), // Int31n(1048577) + int32(621654496), // Int31n(1000000000) + int32(413258767), // Int31n(1073741824) + int32(1407315077), // Int31n(2147483646) + int32(1926657288), // Int31n(2147483647) + int32(0), // Int31n(1) + int32(8), // Int31n(10) + int32(27), // Int31n(32) + int32(367019), // Int31n(1048576) + int32(209005), // Int31n(1048577) + int32(307989752), // Int31n(1000000000) + int32(544722126), // Int31n(1073741824) + int32(1663557311), // Int31n(2147483646) + int32(37539650), // Int31n(2147483647) + int32(0), // Int31n(1) + int32(4), // Int31n(10) + int64(8717895732742165505), // Int63() + int64(2259404117704393152), // Int63() + int64(6050128673802995827), // Int63() + int64(501233450539197794), // Int63() + int64(3390393562759376202), // Int63() + int64(2669985732393126063), // Int63() + int64(1774932891286980153), // Int63() + int64(6044372234677422456), // Int63() + int64(8274930044578894929), // Int63() + int64(1543572285742637646), // Int63() + int64(2661732831099943416), // Int63() + int64(8325060299420976708), // Int63() + int64(7837839688282259259), // Int63() + int64(2518412263346885298), // Int63() + int64(5617773211005988520), // Int63() + int64(2339563716805116249), // Int63() + int64(7144924247938981575), // Int63() + int64(161231572858529631), // Int63() + int64(7259475919510918339), // Int63() + int64(7373105480197164748), // Int63() + int64(0), // Int63n(1) + int64(2), // Int63n(10) + int64(19), // Int63n(32) + int64(959842), // Int63n(1048576) + int64(688912), // Int63n(1048577) + int64(393126063), // Int63n(1000000000) + int64(89212473), // Int63n(1073741824) + int64(834026388), // Int63n(2147483646) + int64(1577188963), // Int63n(2147483647) + int64(543572285742637646), // Int63n(1000000000000000000) + int64(355889821886249464), // Int63n(1152921504606846976) + int64(8325060299420976708), // Int63n(9223372036854775806) + int64(7837839688282259259), // Int63n(9223372036854775807) + int64(0), // Int63n(1) + int64(0), // Int63n(10) + int64(25), // Int63n(32) + int64(679623), // Int63n(1048576) + int64(882178), // Int63n(1048577) + int64(510918339), // Int63n(1000000000) + int64(782454476), // Int63n(1073741824) + int64(0), // Intn(1) + int64(4), // Intn(10) + int64(25), // Intn(32) + int64(310570), // Intn(1048576) + int64(857611), // Intn(1048577) + int64(621654496), // Intn(1000000000) + int64(413258767), // Intn(1073741824) + int64(1407315077), // Intn(2147483646) + int64(1926657288), // Intn(2147483647) + int64(543572285742637646), // Intn(1000000000000000000) + int64(355889821886249464), // Intn(1152921504606846976) + int64(8325060299420976708), // Intn(9223372036854775806) + int64(7837839688282259259), // Intn(9223372036854775807) + int64(0), // Intn(1) + int64(2), // Intn(10) + int64(14), // Intn(32) + int64(515775), // Intn(1048576) + int64(839455), // Intn(1048577) + int64(690228450), // Intn(1000000000) + int64(642943070), // Intn(1073741824) + float64(-0.28158587086436215), // NormFloat64() + float64(0.570933095808067), // NormFloat64() + float64(-1.6920196326157044), // NormFloat64() + float64(0.1996229111693099), // NormFloat64() + float64(1.9195199291234621), // NormFloat64() + float64(0.8954838794918353), // NormFloat64() + float64(0.41457072128813166), // NormFloat64() + float64(-0.48700161491544713), // NormFloat64() + float64(-0.1684059662402393), // NormFloat64() + float64(0.37056410998929545), // NormFloat64() + float64(1.0156889027029008), // NormFloat64() + float64(-0.5174422210625114), // NormFloat64() + float64(-0.5565834214413804), // NormFloat64() + float64(0.778320596648391), // NormFloat64() + float64(-1.8970718197702225), // NormFloat64() + float64(0.5229525761688676), // NormFloat64() + float64(-1.5515595563231523), // NormFloat64() + float64(0.0182029289376123), // NormFloat64() + float64(-0.6820951356608795), // NormFloat64() + float64(-0.5987943422687668), // NormFloat64() + []int{}, // Perm(0) + []int{0}, // Perm(1) + []int{0, 4, 1, 3, 2}, // Perm(5) + []int{3, 1, 0, 4, 7, 5, 2, 6}, // Perm(8) + []int{5, 0, 3, 6, 7, 4, 2, 1, 8}, // Perm(9) + []int{4, 5, 0, 2, 6, 9, 3, 1, 8, 7}, // Perm(10) + []int{14, 2, 0, 8, 3, 5, 13, 12, 1, 4, 6, 7, 11, 9, 15, 10}, // Perm(16) + []int{}, // Perm(0) + []int{0}, // Perm(1) + []int{3, 0, 1, 2, 4}, // Perm(5) + []int{5, 1, 2, 0, 4, 7, 3, 6}, // Perm(8) + []int{4, 0, 6, 8, 1, 5, 2, 7, 3}, // Perm(9) + []int{8, 6, 1, 7, 5, 4, 3, 2, 9, 0}, // Perm(10) + []int{0, 3, 13, 2, 15, 4, 10, 1, 8, 14, 7, 6, 12, 9, 5, 11}, // Perm(16) + []int{}, // Perm(0) + []int{0}, // Perm(1) + []int{0, 4, 2, 1, 3}, // Perm(5) + []int{2, 1, 7, 0, 6, 3, 4, 5}, // Perm(8) + []int{8, 7, 5, 3, 4, 6, 0, 1, 2}, // Perm(9) + []int{1, 0, 2, 5, 7, 6, 9, 8, 3, 4}, // Perm(10) + uint32(4059586549), // Uint32() + uint32(1052117029), // Uint32() + uint32(2817310706), // Uint32() + uint32(233405013), // Uint32() + uint32(1578775030), // Uint32() + uint32(1243308993), // Uint32() + uint32(826517535), // Uint32() + uint32(2814630155), // Uint32() + uint32(3853314576), // Uint32() + uint32(718781857), // Uint32() + uint32(1239465936), // Uint32() + uint32(3876658295), // Uint32() + uint32(3649778518), // Uint32() + uint32(1172727096), // Uint32() + uint32(2615979505), // Uint32() + uint32(1089444252), // Uint32() + uint32(3327114623), // Uint32() + uint32(75079301), // Uint32() + uint32(3380456901), // Uint32() + uint32(3433369789), // Uint32() +} diff --git a/src/pkg/math/remainder_amd64p32.s b/src/pkg/math/remainder_amd64p32.s new file mode 100644 index 000000000..cd5cf55ff --- /dev/null +++ b/src/pkg/math/remainder_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "remainder_amd64.s" diff --git a/src/pkg/math/sin_amd64p32.s b/src/pkg/math/sin_amd64p32.s new file mode 100644 index 000000000..9f93eba20 --- /dev/null +++ b/src/pkg/math/sin_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "sin_amd64.s" diff --git a/src/pkg/math/sincos_amd64p32.s b/src/pkg/math/sincos_amd64p32.s new file mode 100644 index 000000000..360e94d09 --- /dev/null +++ b/src/pkg/math/sincos_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "sincos_amd64.s" diff --git a/src/pkg/math/sqrt_amd64p32.s b/src/pkg/math/sqrt_amd64p32.s new file mode 100644 index 000000000..d83a286c2 --- /dev/null +++ b/src/pkg/math/sqrt_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "sqrt_amd64.s" diff --git a/src/pkg/math/tan_amd64p32.s b/src/pkg/math/tan_amd64p32.s new file mode 100644 index 000000000..9b3f70de7 --- /dev/null +++ b/src/pkg/math/tan_amd64p32.s @@ -0,0 +1,5 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "tan_amd64.s" |