modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/divide.go (about)

     1  // run
     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  // Test divide corner cases.
     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)
    16  		panic("divide")
    17  	}
    18  	if t := x % y; t != r {
    19  		fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
    20  		panic("divide")
    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)
    27  		panic("divide")
    28  	}
    29  	if t := x % y; t != r {
    30  		fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
    31  		panic("divide")
    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)
    38  		panic("divide")
    39  	}
    40  	if t := x % y; t != r {
    41  		fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
    42  		panic("divide")
    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)
    49  		panic("divide")
    50  	}
    51  	if t := x % y; t != r {
    52  		fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
    53  		panic("divide")
    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  }