aboutsummaryrefslogtreecommitdiff
path: root/src/math/bits/make_examples.go
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2017-11-02 11:19:23 +0100
committerRobert Griesemer <gri@golang.org>2017-11-03 20:12:07 +0000
commit89bcbf40b86ebad81d5cf34f6457f11a6f23b808 (patch)
tree3cc56b5df65a744c66009891634bdcb99f895604 /src/math/bits/make_examples.go
parent483e298daad38f39515ba20c0fcedc20b5475ae8 (diff)
downloadgo-89bcbf40b86ebad81d5cf34f6457f11a6f23b808.tar.xz
math/bits: add examples for right rotation
Right rotation is achieved using negative k in RotateLeft*(x, k). Add examples demonstrating that functionality. Change-Id: I15dab159accd2937cb18d3fa8ca32da8501567d3 Reviewed-on: https://go-review.googlesource.com/75371 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/math/bits/make_examples.go')
-rw-r--r--src/math/bits/make_examples.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/math/bits/make_examples.go b/src/math/bits/make_examples.go
index ac537d5778..cd81cd6c4d 100644
--- a/src/math/bits/make_examples.go
+++ b/src/math/bits/make_examples.go
@@ -37,6 +37,7 @@ func main() {
name string
in int
out [4]interface{}
+ out2 [4]interface{}
}{
{
name: "LeadingZeros",
@@ -57,6 +58,7 @@ func main() {
name: "RotateLeft",
in: 15,
out: [4]interface{}{bits.RotateLeft8(15, 2), bits.RotateLeft16(15, 2), bits.RotateLeft32(15, 2), bits.RotateLeft64(15, 2)},
+ out2: [4]interface{}{bits.RotateLeft8(15, -2), bits.RotateLeft16(15, -2), bits.RotateLeft32(15, -2), bits.RotateLeft64(15, -2)},
},
{
name: "Reverse",
@@ -85,12 +87,16 @@ func main() {
fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", %d)\n", size, e.in)
if e.name == "RotateLeft" {
fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d, 2))\n", size, f, e.in)
+ fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d, -2))\n", size, f, e.in)
} else {
fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d))\n", size, f, e.in)
}
fmt.Fprintf(w, "\t// Output:\n")
fmt.Fprintf(w, "\t// %0*b\n", size, e.in)
fmt.Fprintf(w, "\t// %0*b\n", size, e.out[i])
+ if e.name == "RotateLeft" && e.out2[i] != nil {
+ fmt.Fprintf(w, "\t// %0*b\n", size, e.out2[i])
+ }
default:
fmt.Fprintf(w, "\tfmt.Printf(\"%s(%%0%db) = %%d\\n\", %d, bits.%s(%d))\n", f, size, e.in, f, e.in)
fmt.Fprintf(w, "\t// Output:\n")