blob: 5c0f45059a2bf8c02de9aef2741399611dae4ef7 [file] [log] [blame]
Russ Cox08bfb392011-07-28 14:18:22 -04001// $G $D/$F.go && $L $F.$A && ./$A.out
2
3// Copyright 2011 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// divide corner cases
8
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)
16 }
17 if t := x % y; t != r {
18 fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
19 }
20}
21
22func f16(x, y, q, r int16) {
23 if t := x / y; t != q {
24 fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
25 }
26 if t := x % y; t != r {
27 fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
28 }
29}
30
31func f32(x, y, q, r int32) {
32 if t := x / y; t != q {
33 fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
34 }
35 if t := x % y; t != r {
36 fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
37 }
38}
39
40func f64(x, y, q, r int64) {
41 if t := x / y; t != q {
42 fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
43 }
44 if t := x % y; t != r {
45 fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
46 }
47}
48
49func main() {
50 f8(-1<<7, -1, -1<<7, 0)
51 f16(-1<<15, -1, -1<<15, 0)
52 f32(-1<<31, -1, -1<<31, 0)
53 f64(-1<<63, -1, -1<<63, 0)
54}