Skip to content

Commit eb7e8f3

Browse files
committed
py: fix GoInt and GoInt64 for BigInts
1 parent af1ba18 commit eb7e8f3

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

py/bigint.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,26 @@ func (x *BigInt) MaybeInt() Object {
9797
return i
9898
}
9999

100-
// Truncates to go int64
100+
// Truncates to go int
101101
//
102-
// If it is outside the range of an go int64 it will return an error
103-
func (x *BigInt) GoInt() (int64, error) {
102+
// If it is outside the range of an go int it will return an error
103+
func (x *BigInt) GoInt() (int, error) {
104104
z, err := x.Int()
105105
if err != nil {
106106
return 0, err
107107
}
108-
return int64(z), nil
108+
return z.GoInt()
109109
}
110110

111-
// Truncates to go int
111+
// Truncates to go int64
112112
//
113-
// If it is outside the range of an go int it will return an error
114-
func (x *BigInt) GoInt64() (int, error) {
113+
// If it is outside the range of an go int64 it will return an error
114+
func (x *BigInt) GoInt64() (int64, error) {
115115
z, err := x.Int()
116116
if err != nil {
117-
return 0, overflowErrorGo
118-
}
119-
r := int(z)
120-
if Int(r) != z {
121-
return 0, overflowErrorGo
117+
return 0, err
122118
}
123-
return int(r), nil
119+
return int64(z), nil
124120
}
125121

126122
// Frexp produces frac and exp such that a ~= frac × 2**exp
@@ -589,3 +585,5 @@ var _ conversionBetweenTypes = (*BigInt)(nil)
589585
var _ I__bool__ = (*BigInt)(nil)
590586
var _ I__index__ = (*BigInt)(nil)
591587
var _ richComparison = (*BigInt)(nil)
588+
var _ IGoInt = (*BigInt)(nil)
589+
var _ IGoInt64 = (*BigInt)(nil)

py/int.go

+2
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,5 @@ var _ conversionBetweenTypes = Int(0)
712712
var _ I__bool__ = Int(0)
713713
var _ I__index__ = Int(0)
714714
var _ richComparison = Int(0)
715+
var _ IGoInt = Int(0)
716+
var _ IGoInt64 = Int(0)

0 commit comments

Comments
 (0)