Russ Cox | 0b477ef | 2012-02-16 23:48:57 -0500 | [diff] [blame] | 1 | // run |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 2 | |
Emmanuel Odeke | 53fd522 | 2016-04-10 14:32:26 -0700 | [diff] [blame] | 3 | // Copyright 2011 The Go Authors. All rights reserved. |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file. |
| 6 | |
Rob Pike | 83976e3 | 2012-02-19 14:28:53 +1100 | [diff] [blame] | 7 | // Test divide corner cases. |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 8 | |
| 9 | package main |
| 10 | |
| 11 | import "fmt" |
| 12 | |
| 13 | func 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 Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 16 | panic("divide") |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 17 | } |
| 18 | if t := x % y; t != r { |
| 19 | fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) |
Alan Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 20 | panic("divide") |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 21 | } |
| 22 | } |
| 23 | |
| 24 | func 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 Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 27 | panic("divide") |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 28 | } |
| 29 | if t := x % y; t != r { |
| 30 | fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) |
Alan Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 31 | panic("divide") |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
| 35 | func 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 Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 38 | panic("divide") |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 39 | } |
| 40 | if t := x % y; t != r { |
| 41 | fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) |
Alan Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 42 | panic("divide") |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | func 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 Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 49 | panic("divide") |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 50 | } |
| 51 | if t := x % y; t != r { |
| 52 | fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) |
Alan Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 53 | panic("divide") |
Russ Cox | 08bfb39 | 2011-07-28 14:18:22 -0400 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | func 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 | } |