/usr/share/go-1.7/test/ken/divmod.go is in golang-1.7-src 1.7.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | // run
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test integer division and modulus.
package main
const (
// example from the spec
n1 = +5
n2 = -5
d1 = +3
d2 = -3
q1 = +1
q2 = -1
q3 = -1
q4 = +1
r1 = +2
r2 = -2
r3 = +2
r4 = -2
)
func main() {
/* ideals */
if n1/d1 != q1 || n1%d1 != r1 {
println("ideal-1", n1, d1, n1/d1, n1%d1)
panic("fail")
}
if n2/d1 != q2 || n2%d1 != r2 {
println("ideal-2", n2, d1, n2/d1, n2%d1)
panic("fail")
}
if n1/d2 != q3 || n1%d2 != r3 {
println("ideal-3", n1, d2, n1/d2, n1%d2)
panic("fail")
}
if n2/d2 != q4 || n2%d2 != r4 {
println("ideal-4", n2, d2, n2/d2, n2%d2)
panic("fail")
}
/* int */
var in1 int = +5
var in2 int = -5
var id1 int = +3
var id2 int = -3
if in1/id1 != q1 || in1%id1 != r1 {
println("int-1", in1, id1, in1/id1, in1%id1)
panic("fail")
}
if in2/id1 != q2 || in2%id1 != r2 {
println("int-2", in2, id1, in2/id1, in2%id1)
panic("fail")
}
if in1/id2 != q3 || in1%id2 != r3 {
println("int-3", in1, id2, in1/id2, in1%id2)
panic("fail")
}
if in2/id2 != q4 || in2%id2 != r4 {
println("int-4", in2, id2, in2/id2, in2%id2)
panic("fail")
}
/* int8 */
var bn1 int8 = +5
var bn2 int8 = -5
var bd1 int8 = +3
var bd2 int8 = -3
if bn1/bd1 != q1 || bn1%bd1 != r1 {
println("int8-1", bn1, bd1, bn1/bd1, bn1%bd1)
panic("fail")
}
if bn2/bd1 != q2 || bn2%bd1 != r2 {
println("int8-2", bn2, bd1, bn2/bd1, bn2%bd1)
panic("fail")
}
if bn1/bd2 != q3 || bn1%bd2 != r3 {
println("int8-3", bn1, bd2, bn1/bd2, bn1%bd2)
panic("fail")
}
if bn2/bd2 != q4 || bn2%bd2 != r4 {
println("int8-4", bn2, bd2, bn2/bd2, bn2%bd2)
panic("fail")
}
/* int16 */
var sn1 int16 = +5
var sn2 int16 = -5
var sd1 int16 = +3
var sd2 int16 = -3
if sn1/sd1 != q1 || sn1%sd1 != r1 {
println("int16-1", sn1, sd1, sn1/sd1, sn1%sd1)
panic("fail")
}
if sn2/sd1 != q2 || sn2%sd1 != r2 {
println("int16-2", sn2, sd1, sn2/sd1, sn2%sd1)
panic("fail")
}
if sn1/sd2 != q3 || sn1%sd2 != r3 {
println("int16-3", sn1, sd2, sn1/sd2, sn1%sd2)
panic("fail")
}
if sn2/sd2 != q4 || sn2%sd2 != r4 {
println("int16-4", sn2, sd2, sn2/sd2, sn2%sd2)
panic("fail")
}
/* int32 */
var ln1 int32 = +5
var ln2 int32 = -5
var ld1 int32 = +3
var ld2 int32 = -3
if ln1/ld1 != q1 || ln1%ld1 != r1 {
println("int32-1", ln1, ld1, ln1/ld1, ln1%ld1)
panic("fail")
}
if ln2/ld1 != q2 || ln2%ld1 != r2 {
println("int32-2", ln2, ld1, ln2/ld1, ln2%ld1)
panic("fail")
}
if ln1/ld2 != q3 || ln1%ld2 != r3 {
println("int32-3", ln1, ld2, ln1/ld2, ln1%ld2)
panic("fail")
}
if ln2/ld2 != q4 || ln2%ld2 != r4 {
println("int32-4", ln2, ld2, ln2/ld2, ln2%ld2)
panic("fail")
}
/* int64 */
var qn1 int64 = +5
var qn2 int64 = -5
var qd1 int64 = +3
var qd2 int64 = -3
if qn1/qd1 != q1 || qn1%qd1 != r1 {
println("int64-1", qn1, qd1, qn1/qd1, qn1%qd1)
panic("fail")
}
if qn2/qd1 != q2 || qn2%qd1 != r2 {
println("int64-2", qn2, qd1, qn2/qd1, qn2%qd1)
panic("fail")
}
if qn1/qd2 != q3 || qn1%qd2 != r3 {
println("int64-3", qn1, qd2, qn1/qd2, qn1%qd2)
panic("fail")
}
if qn2/qd2 != q4 || qn2%qd2 != r4 {
println("int64-4", qn2, qd2, qn2/qd2, qn2%qd2)
panic("fail")
}
if n1/qd1 != q1 || n1%qd1 != r1 {
println("mixed int64-1", n1, qd1, n1/qd1, n1%qd1)
panic("fail")
}
if n2/qd1 != q2 || n2%qd1 != r2 {
println("mixed int64-2", n2, qd1, n2/qd1, n2%qd1)
panic("fail")
}
if n1/qd2 != q3 || n1%qd2 != r3 {
println("mixed int64-3", n1, qd2, n1/qd2, n1%qd2)
panic("fail")
}
if n2/qd2 != q4 || n2%qd2 != r4 {
println("mixed int64-4", n2, qd2, n2/qd2, n2%qd2)
panic("fail")
}
if qn1/d1 != q1 || qn1%d1 != r1 {
println("mixed int64-5", qn1, d1, qn1/d1, qn1%d1)
panic("fail")
}
if qn2/d1 != q2 || qn2%d1 != r2 {
println("mixed int64-6", qn2, d1, qn2/d1, qn2%d1)
panic("fail")
}
if qn1/d2 != q3 || qn1%d2 != r3 {
println("mixed int64-7", qn1, d2, qn1/d2, qn1%d2)
panic("fail")
}
if qn2/d2 != q4 || qn2%d2 != r4 {
println("mixed int64-8", qn2, d2, qn2/d2, qn2%d2)
panic("fail")
}
/* uint */
var uin1 uint = +5
var uid1 uint = +3
if uin1/uid1 != q1 || uin1%uid1 != r1 {
println("uint", uin1, uid1, uin1/uid1, uin1%uid1)
panic("fail")
}
/* uint8 */
var ubn1 uint8 = +5
var ubd1 uint8 = +3
if ubn1/ubd1 != q1 || ubn1%ubd1 != r1 {
println("uint8", ubn1, ubd1, ubn1/ubd1, ubn1%ubd1)
panic("fail")
}
/* uint16 */
var usn1 uint16 = +5
var usd1 uint16 = +3
if usn1/usd1 != q1 || usn1%usd1 != r1 {
println("uint16", usn1, usd1, usn1/usd1, usn1%usd1)
panic("fail")
}
/* uint32 */
var uln1 uint32 = +5
var uld1 uint32 = +3
if uln1/uld1 != q1 || uln1%uld1 != r1 {
println("uint32", uln1, uld1, uln1/uld1, uln1%uld1)
panic("fail")
}
/* uint64 */
var uqn1 uint64 = +5
var uqd1 uint64 = +3
if uqn1/uqd1 != q1 || uqn1%uqd1 != r1 {
println("uint64", uqn1, uqd1, uqn1/uqd1, uqn1%uqd1)
panic("fail")
}
if n1/uqd1 != q1 || n1%uqd1 != r1 {
println("mixed uint64-1", n1, uqd1, n1/uqd1, n1%uqd1)
panic("fail")
}
if uqn1/d1 != q1 || uqn1%d1 != r1 {
println("mixed uint64-2", uqn1, d1, uqn1/d1, uqn1%d1)
panic("fail")
}
}
|