]> Cypherpunks repositories - gostls13.git/commitdiff
math/big: incorporate feedback by josharian (Example_fibonacci)
authorRobert Griesemer <gri@golang.org>
Wed, 17 Jun 2015 20:19:33 +0000 (13:19 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 17 Jun 2015 20:29:35 +0000 (20:29 +0000)
Change-Id: I376ff39594b532a5490f13e3985b7a6ff4b6761d
Reviewed-on: https://go-review.googlesource.com/11191
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/math/big/example_test.go

index 384b50e51ca25176bc926889b3ff54f3ae3936d3..37b1bd090ad1179000db309aa69ca979af7fbffb 100644 (file)
@@ -63,15 +63,21 @@ func Example_fibonacci() {
 
        // loop while fib1 is smaller than 1e100
        for fib1.Cmp(&limit) < 0 {
+               // Compute the next Fibonacci number:
+               //    t1 := fib2
+               //    t2 := fib1.Add(fib1, fib2) // Note that Add "assigns" to fib1!
+               //    fib1 = t1
+               //    fib2 = t2
+               // Using Go's multi-value ("parallel") assignment, we can simply write:
                fib1, fib2 = fib2, fib1.Add(fib1, fib2)
        }
 
-       fmt.Println(fib1) // 100-digits fibonacci number
+       fmt.Println(fib1) // 100-digit Fibonacci number
 
        // Test fib1 for primality. The ProbablyPrimes parameter sets the number
        // of Miller-Rabin rounds to be performed. 20 is a good value.
        isPrime := fib1.ProbablyPrime(20)
-       fmt.Println(isPrime) // false
+       fmt.Println(isPrime)
 
        // Output:
        // 1344719667586153181419716641724567886890850696275767987106294472017884974410332069524504824747437757