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

Delta Between Two Patch Sets: src/pkg/big/nat.go

Issue 881050: code review 881050: big: Add Lsh and Value; convert pidigits to use big (Closed)
Left Patch Set: code review 881050: big: Add Lsh and Value; convert pidigits to use big Created 14 years, 11 months ago
Right Patch Set: code review 881050: big: Add Lsh and Value; convert pidigits to use big Created 14 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/big/int_test.go ('k') | src/pkg/big/nat_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 // This file contains operations on unsigned multi-precision integers. 5 // This file contains operations on unsigned multi-precision integers.
6 // These are the building blocks for the operations on signed integers 6 // These are the building blocks for the operations on signed integers
7 // and rationals. 7 // and rationals.
8 8
9 // This package implements multi-precision arithmetic (big numbers). 9 // This package implements multi-precision arithmetic (big numbers).
10 // The following numeric types are supported: 10 // The following numeric types are supported:
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 532
533 // To avoid losing the top n bits, dst should be sized so that 533 // To avoid losing the top n bits, dst should be sized so that
534 // len(dst) == len(src) + 1. 534 // len(dst) == len(src) + 1.
535 func shiftLeft(dst, src []Word, n uint) { 535 func shiftLeft(dst, src []Word, n uint) {
536 if len(src) == 0 { 536 if len(src) == 0 {
537 return 537 return
538 } 538 }
539 539
540 ñ := _W - n 540 ñ := _W - n
541 if len(dst) > len(src) { 541 if len(dst) > len(src) {
542 » » dst[len(dst)-1] |= src[len(src)-1] >> ñ 542 » » dst[len(src)] |= src[len(src)-1] >> ñ
543 } 543 }
544 for i := len(src) - 1; i >= 1; i-- { 544 for i := len(src) - 1; i >= 1; i-- {
545 » » dst[i] = src[i] << n | src[i-1] >> ñ 545 » » dst[i] = src[i]<<n | src[i-1]>>ñ
546 } 546 }
547 dst[0] = src[0] << n 547 dst[0] = src[0] << n
548 } 548 }
549 549
550 550
551 func shiftRight(dst, src []Word, n uint) { 551 func shiftRight(dst, src []Word, n uint) {
552 if len(src) == 0 { 552 if len(src) == 0 {
553 return 553 return
554 } 554 }
555 555
556 ñ := _W - n 556 ñ := _W - n
557 for i := 0; i < len(src)-1; i++ { 557 for i := 0; i < len(src)-1; i++ {
558 » » dst[i] = src[i] >> n | src[i+1] << ñ 558 » » dst[i] = src[i]>>n | src[i+1]<<ñ
559 } 559 }
560 dst[len(src)-1] = src[len(src)-1] >> n 560 dst[len(src)-1] = src[len(src)-1] >> n
561 } 561 }
562 562
563 563
564 // greaterThan returns true iff (x1<<_W + x2) > (y1<<_W + y2) 564 // greaterThan returns true iff (x1<<_W + x2) > (y1<<_W + y2)
565 func greaterThan(x1, x2, y1, y2 Word) bool { return x1 > y1 || x1 == y1 && x2 > y2 } 565 func greaterThan(x1, x2, y1, y2 Word) bool { return x1 > y1 || x1 == y1 && x2 > y2 }
566 566
567 567
568 // modNW returns x % d. 568 // modNW returns x % d.
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 } 782 }
783 if cmpNN(y, bigOne) == 0 { 783 if cmpNN(y, bigOne) == 0 {
784 return false 784 return false
785 } 785 }
786 } 786 }
787 return false 787 return false
788 } 788 }
789 789
790 return true 790 return true
791 } 791 }
LEFTRIGHT

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