Skip to content

Commit cd69d37

Browse files
drew-512Drew O'Meara
and
Drew O'Meara
authored
builtin,py: use M__neg__ for IntMin
This CL special-cases IntMin to use M__neg__ instead of going through a conversion to BigInt. Co-authored-by: Drew O'Meara <[email protected]>
1 parent 3068cb5 commit cd69d37

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

builtin/tests/builtin.py

+11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@
66

77
doc="abs"
88
assert abs(0) == 0
9+
assert abs(-0) == 0
10+
assert abs(0.0) == 0.0
11+
assert abs(-0.0) == 0.0
912
assert abs(10) == 10
1013
assert abs(-10) == 10
14+
assert abs(12.3) == 12.3
15+
assert abs(-12.3) == 12.3
16+
assert abs(1 << 63) == 1 << 63
17+
assert abs(-1 << 63) == 1 << 63
18+
assert abs(-(1 << 63)) == 1 << 63
19+
assert abs(1 << 66) == 1 << 66
20+
assert abs(-1 << 66) == 1 << 66
21+
assert abs(-(1 << 66)) == 1 << 66
1122

1223
doc="all"
1324
assert all((0,0,0)) == False

py/int.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ func (a Int) M__pos__() (Object, error) {
254254

255255
func (a Int) M__abs__() (Object, error) {
256256
if a == IntMin {
257-
abig, _ := ConvertToBigInt(a)
258-
return abig.M__abs__()
257+
return a.M__neg__()
259258
}
260259
if a < 0 {
261260
return -a, nil

0 commit comments

Comments
 (0)