Skip to content

Commit 9d5dc9a

Browse files
committed
mostly comment fixes
1 parent d0d3a0f commit 9d5dc9a

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

overflow.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
// Add, Sub, Mul, Div are for int. Add64, Add32, etc. are specifically sized.
1616
//
1717
// If anybody wishes an unsigned version, submit a pull request for code and new tests.
18-
1918
package overflow
2019

21-
//go:generate ./overflow_template.sh
20+
//go:generate ./overflow_template.sh
2221

2322
import "math"
2423

@@ -27,7 +26,6 @@ func _is64Bit() bool {
2726
return ((maxU32 << 1) >> 1) == maxU32
2827
}
2928

30-
3129
/********** PARTIAL TEST COVERAGE FROM HERE DOWN *************
3230
3331
The only way that I could see to do this is a combination of
@@ -40,6 +38,7 @@ So, FEEL FREE to carefully review the code visually.
4038

4139
// Unspecified size, i.e. normal signed int
4240

41+
// Add sums two ints, returning the result and a boolean status.
4342
func Add(a, b int) (int, bool) {
4443
if _is64Bit() {
4544
r64, ok := Add64(int64(a), int64(b))
@@ -49,6 +48,7 @@ func Add(a, b int) (int, bool) {
4948
return int(r32), ok
5049
}
5150

51+
// Sub returns the difference of two ints and a boolean status.
5252
func Sub(a, b int) (int, bool) {
5353
if _is64Bit() {
5454
r64, ok := Sub64(int64(a), int64(b))
@@ -58,6 +58,7 @@ func Sub(a, b int) (int, bool) {
5858
return int(r32), ok
5959
}
6060

61+
// Mul returns the product of two ints and a boolean status.
6162
func Mul(a, b int) (int, bool) {
6263
if _is64Bit() {
6364
r64, ok := Mul64(int64(a), int64(b))
@@ -67,6 +68,7 @@ func Mul(a, b int) (int, bool) {
6768
return int(r32), ok
6869
}
6970

71+
// Div returns the quotient of two ints and a boolean status
7072
func Div(a, b int) (int, bool) {
7173
if _is64Bit() {
7274
r64, ok := Div64(int64(a), int64(b))
@@ -76,6 +78,7 @@ func Div(a, b int) (int, bool) {
7678
return int(r32), ok
7779
}
7880

81+
// Quotient returns the quotient, remainder and status of two ints
7982
func Quotient(a, b int) (int, int, bool) {
8083
if _is64Bit() {
8184
q64, r64, ok := Quotient64(int64(a), int64(b))
@@ -87,6 +90,7 @@ func Quotient(a, b int) (int, int, bool) {
8790

8891
/************* Panic versions for int ****************/
8992

93+
// Addp returns the sum of two ints, panicking on overflow
9094
func Addp(a, b int) int {
9195
r, ok := Add(a, b)
9296
if !ok {
@@ -95,6 +99,7 @@ func Addp(a, b int) int {
9599
return r
96100
}
97101

102+
// Subp returns the difference of two ints, panicking on overflow.
98103
func Subp(a, b int) int {
99104
r, ok := Sub(a, b)
100105
if !ok {
@@ -103,6 +108,7 @@ func Subp(a, b int) int {
103108
return r
104109
}
105110

111+
// Mulp returns the product of two ints, panicking on overflow.
106112
func Mulp(a, b int) int {
107113
r, ok := Mul(a, b)
108114
if !ok {
@@ -111,6 +117,7 @@ func Mulp(a, b int) int {
111117
return r
112118
}
113119

120+
// Divp returns the quotient of two ints, panicking on overflow.
114121
func Divp(a, b int) int {
115122
r, ok := Div(a, b)
116123
if !ok {

overflow_impl.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func Mul8(a, b int8) (int8, bool) {
6262
}
6363

6464
// Mul8p is the unchecked panicing version of Mul8
65-
func Mulp8(a, b int8) int8 {
65+
func Mul8p(a, b int8) int8 {
6666
r, ok := Mul8(a, b)
6767
if !ok {
6868
panic("multiplication overflow")
@@ -80,7 +80,7 @@ func Div8(a, b int8) (int8, bool) {
8080
}
8181

8282
// Div8p is the unchecked panicing version of Div8
83-
func Divp8(a, b int8) int8 {
83+
func Div8p(a, b int8) int8 {
8484
r, ok := Div8(a, b)
8585
if !ok {
8686
panic("division failure")
@@ -157,7 +157,7 @@ func Mul16(a, b int16) (int16, bool) {
157157
}
158158

159159
// Mul16p is the unchecked panicing version of Mul16
160-
func Mulp16(a, b int16) int16 {
160+
func Mul16p(a, b int16) int16 {
161161
r, ok := Mul16(a, b)
162162
if !ok {
163163
panic("multiplication overflow")
@@ -175,7 +175,7 @@ func Div16(a, b int16) (int16, bool) {
175175
}
176176

177177
// Div16p is the unchecked panicing version of Div16
178-
func Divp16(a, b int16) int16 {
178+
func Div16p(a, b int16) int16 {
179179
r, ok := Div16(a, b)
180180
if !ok {
181181
panic("division failure")
@@ -252,7 +252,7 @@ func Mul32(a, b int32) (int32, bool) {
252252
}
253253

254254
// Mul32p is the unchecked panicing version of Mul32
255-
func Mulp32(a, b int32) int32 {
255+
func Mul32p(a, b int32) int32 {
256256
r, ok := Mul32(a, b)
257257
if !ok {
258258
panic("multiplication overflow")
@@ -270,7 +270,7 @@ func Div32(a, b int32) (int32, bool) {
270270
}
271271

272272
// Div32p is the unchecked panicing version of Div32
273-
func Divp32(a, b int32) int32 {
273+
func Div32p(a, b int32) int32 {
274274
r, ok := Div32(a, b)
275275
if !ok {
276276
panic("division failure")
@@ -347,7 +347,7 @@ func Mul64(a, b int64) (int64, bool) {
347347
}
348348

349349
// Mul64p is the unchecked panicing version of Mul64
350-
func Mulp64(a, b int64) int64 {
350+
func Mul64p(a, b int64) int64 {
351351
r, ok := Mul64(a, b)
352352
if !ok {
353353
panic("multiplication overflow")
@@ -365,7 +365,7 @@ func Div64(a, b int64) (int64, bool) {
365365
}
366366

367367
// Div64p is the unchecked panicing version of Div64
368-
func Divp64(a, b int64) int64 {
368+
func Div64p(a, b int64) int64 {
369369
r, ok := Div64(a, b)
370370
if !ok {
371371
panic("division failure")

overflow_template.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func Mul${SIZE}(a, b int${SIZE}) (int${SIZE}, bool) {
7070
}
7171
7272
// Mul${SIZE}p is the unchecked panicing version of Mul${SIZE}
73-
func Mulp${SIZE}(a, b int${SIZE}) int${SIZE} {
73+
func Mul${SIZE}p(a, b int${SIZE}) int${SIZE} {
7474
r, ok := Mul${SIZE}(a, b)
7575
if !ok {
7676
panic(\"multiplication overflow\")
@@ -88,7 +88,7 @@ func Div${SIZE}(a, b int${SIZE}) (int${SIZE}, bool) {
8888
}
8989
9090
// Div${SIZE}p is the unchecked panicing version of Div${SIZE}
91-
func Divp${SIZE}(a, b int${SIZE}) int${SIZE} {
91+
func Div${SIZE}p(a, b int${SIZE}) int${SIZE} {
9292
r, ok := Div${SIZE}(a, b)
9393
if !ok {
9494
panic(\"division failure\")

0 commit comments

Comments
 (0)