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

Lines changed: 11 additions & 13 deletions
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

Lines changed: 2 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy