blob: b5570415c242bb1c0c47fddb87c527cc69adc6fd [file] [log] [blame]
Russ Cox0b477ef2012-02-16 23:48:57 -05001// run
Russ Cox08bfb392011-07-28 14:18:22 -04002
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07003// Copyright 2011 The Go Authors. All rights reserved.
Russ Cox08bfb392011-07-28 14:18:22 -04004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
Rob Pike83976e32012-02-19 14:28:53 +11007// Test divide corner cases.
Russ Cox08bfb392011-07-28 14:18:22 -04008
9package main
10
11import "fmt"
12
13func f8(x, y, q, r int8) {
14 if t := x / y; t != q {
15 fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
Alan Donovan052c9422013-02-12 13:17:49 -050016 panic("divide")
Russ Cox08bfb392011-07-28 14:18:22 -040017 }
18 if t := x % y; t != r {
19 fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
Alan Donovan052c9422013-02-12 13:17:49 -050020 panic("divide")
Russ Cox08bfb392011-07-28 14:18:22 -040021 }
22}
23
24func f16(x, y, q, r int16) {
25 if t := x / y; t != q {
26 fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
Alan Donovan052c9422013-02-12 13:17:49 -050027 panic("divide")
Russ Cox08bfb392011-07-28 14:18:22 -040028 }
29 if t := x % y; t != r {
30 fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
Alan Donovan052c9422013-02-12 13:17:49 -050031 panic("divide")
Russ Cox08bfb392011-07-28 14:18:22 -040032 }
33}
34
35func f32(x, y, q, r int32) {
36 if t := x / y; t != q {
37 fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
Alan Donovan052c9422013-02-12 13:17:49 -050038 panic("divide")
Russ Cox08bfb392011-07-28 14:18:22 -040039 }
40 if t := x % y; t != r {
41 fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
Alan Donovan052c9422013-02-12 13:17:49 -050042 panic("divide")
Russ Cox08bfb392011-07-28 14:18:22 -040043 }
44}
45
46func f64(x, y, q, r int64) {
47 if t := x / y; t != q {
48 fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
Alan Donovan052c9422013-02-12 13:17:49 -050049 panic("divide")
Russ Cox08bfb392011-07-28 14:18:22 -040050 }
51 if t := x % y; t != r {
52 fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
Alan Donovan052c9422013-02-12 13:17:49 -050053 panic("divide")
Russ Cox08bfb392011-07-28 14:18:22 -040054 }
55}
56
57func main() {
58 f8(-1<<7, -1, -1<<7, 0)
59 f16(-1<<15, -1, -1<<15, 0)
60 f32(-1<<31, -1, -1<<31, 0)
61 f64(-1<<63, -1, -1<<63, 0)
62}