Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(836)

Side by Side Diff: src/pkg/math/big/nat_test.go

Issue 90080043: code review 90080043: math/big: fix Int.Exp (Closed)
Patch Set: diff -r c313673339c4 https://code.google.com/p/go/ Created 9 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/math/big/nat.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package big 5 package big
6 6
7 import ( 7 import (
8 "io" 8 "io"
9 "runtime" 9 "runtime"
10 "strings" 10 "strings"
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 t.Errorf("got 0x%s.trailingZeroBits() = %d; want %d", y. string(lowercaseDigits[0:16]), n, i) 707 t.Errorf("got 0x%s.trailingZeroBits() = %d; want %d", y. string(lowercaseDigits[0:16]), n, i)
708 } 708 }
709 y = y.shl(y, 1) 709 y = y.shl(y, 1)
710 } 710 }
711 } 711 }
712 712
713 var expNNTests = []struct { 713 var expNNTests = []struct {
714 x, y, m string 714 x, y, m string
715 out string 715 out string
716 }{ 716 }{
717 {"0", "0", "0", "1"},
718 {"0", "0", "1", "0"},
719 {"1", "1", "1", "0"},
720 {"2", "1", "1", "0"},
721 {"2", "2", "1", "0"},
722 {"10", "100000000000", "1", "0"},
717 {"0x8000000000000000", "2", "", "0x40000000000000000000000000000000"}, 723 {"0x8000000000000000", "2", "", "0x40000000000000000000000000000000"},
718 {"0x8000000000000000", "2", "6719", "4944"}, 724 {"0x8000000000000000", "2", "6719", "4944"},
719 {"0x8000000000000000", "3", "6719", "5447"}, 725 {"0x8000000000000000", "3", "6719", "5447"},
720 {"0x8000000000000000", "1000", "6719", "1603"}, 726 {"0x8000000000000000", "1000", "6719", "1603"},
721 {"0x8000000000000000", "1000000", "6719", "3199"}, 727 {"0x8000000000000000", "1000000", "6719", "3199"},
722 { 728 {
723 "293846293847298347298365972634901724928749102651274623976452561 2965293865296239471239874193284792387498274256129746192347", 729 "293846293847298347298365972634901724928749102651274623976452561 2965293865296239471239874193284792387498274256129746192347",
724 "298472983472983471903246121093472394872319615612417471234712061 ", 730 "298472983472983471903246121093472394872319615612417471234712061 ",
725 "298347298347298347293472908467295612625449587239564956156295692 34729836259263598127342374289365912465901365498236492183464", 731 "298347298347298347293472908467295612625449587239564956156295692 34729836259263598127342374289365912465901365498236492183464",
726 "235377407001840541625081751255547017131532166817902451291571913 91322321508055833908509185839069455749219131480588829346291", 732 "235377407001840541625081751255547017131532166817902451291571913 91322321508055833908509185839069455749219131480588829346291",
727 }, 733 },
728 } 734 }
729 735
730 func TestExpNN(t *testing.T) { 736 func TestExpNN(t *testing.T) {
731 for i, test := range expNNTests { 737 for i, test := range expNNTests {
732 x, _, _ := nat(nil).scan(strings.NewReader(test.x), 0) 738 x, _, _ := nat(nil).scan(strings.NewReader(test.x), 0)
733 y, _, _ := nat(nil).scan(strings.NewReader(test.y), 0) 739 y, _, _ := nat(nil).scan(strings.NewReader(test.y), 0)
734 out, _, _ := nat(nil).scan(strings.NewReader(test.out), 0) 740 out, _, _ := nat(nil).scan(strings.NewReader(test.out), 0)
735 741
736 var m nat 742 var m nat
737 743
738 if len(test.m) > 0 { 744 if len(test.m) > 0 {
739 m, _, _ = nat(nil).scan(strings.NewReader(test.m), 0) 745 m, _, _ = nat(nil).scan(strings.NewReader(test.m), 0)
740 } 746 }
741 747
742 z := nat(nil).expNN(x, y, m) 748 z := nat(nil).expNN(x, y, m)
743 if z.cmp(out) != 0 { 749 if z.cmp(out) != 0 {
744 » » » t.Errorf("#%d got %v want %v", i, z, out) 750 » » » t.Errorf("#%d got %s want %s", i, z.decimalString(), out .decimalString())
745 } 751 }
746 } 752 }
747 } 753 }
748 754
749 func ExpHelper(b *testing.B, x, y Word) { 755 func ExpHelper(b *testing.B, x, y Word) {
750 var z nat 756 var z nat
751 for i := 0; i < b.N; i++ { 757 for i := 0; i < b.N; i++ {
752 z.expWW(x, y) 758 z.expWW(x, y)
753 } 759 }
754 } 760 }
755 761
756 func BenchmarkExp3Power0x10(b *testing.B) { ExpHelper(b, 3, 0x10) } 762 func BenchmarkExp3Power0x10(b *testing.B) { ExpHelper(b, 3, 0x10) }
757 func BenchmarkExp3Power0x40(b *testing.B) { ExpHelper(b, 3, 0x40) } 763 func BenchmarkExp3Power0x40(b *testing.B) { ExpHelper(b, 3, 0x40) }
758 func BenchmarkExp3Power0x100(b *testing.B) { ExpHelper(b, 3, 0x100) } 764 func BenchmarkExp3Power0x100(b *testing.B) { ExpHelper(b, 3, 0x100) }
759 func BenchmarkExp3Power0x400(b *testing.B) { ExpHelper(b, 3, 0x400) } 765 func BenchmarkExp3Power0x400(b *testing.B) { ExpHelper(b, 3, 0x400) }
760 func BenchmarkExp3Power0x1000(b *testing.B) { ExpHelper(b, 3, 0x1000) } 766 func BenchmarkExp3Power0x1000(b *testing.B) { ExpHelper(b, 3, 0x1000) }
761 func BenchmarkExp3Power0x4000(b *testing.B) { ExpHelper(b, 3, 0x4000) } 767 func BenchmarkExp3Power0x4000(b *testing.B) { ExpHelper(b, 3, 0x4000) }
762 func BenchmarkExp3Power0x10000(b *testing.B) { ExpHelper(b, 3, 0x10000) } 768 func BenchmarkExp3Power0x10000(b *testing.B) { ExpHelper(b, 3, 0x10000) }
763 func BenchmarkExp3Power0x40000(b *testing.B) { ExpHelper(b, 3, 0x40000) } 769 func BenchmarkExp3Power0x40000(b *testing.B) { ExpHelper(b, 3, 0x40000) }
764 func BenchmarkExp3Power0x100000(b *testing.B) { ExpHelper(b, 3, 0x100000) } 770 func BenchmarkExp3Power0x100000(b *testing.B) { ExpHelper(b, 3, 0x100000) }
765 func BenchmarkExp3Power0x400000(b *testing.B) { ExpHelper(b, 3, 0x400000) } 771 func BenchmarkExp3Power0x400000(b *testing.B) { ExpHelper(b, 3, 0x400000) }
OLDNEW
« no previous file with comments | « src/pkg/math/big/nat.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b