Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
improved Int.abs() and test coverage
  • Loading branch information
Drew O'Meara committed Feb 3, 2022
commit ace70b0b951b934190e4628c1ef6dd69f4f5fae2
12 changes: 12 additions & 0 deletions builtin/tests/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,18 @@ def gen2():
doc="open"
assert open(__file__) is not None

doc="abs"
assert abs(123) == 123
assert abs(-123) == 123
assert abs(12.3) == 12.3
assert abs(-12.3) == 12.3
assert abs(1 << 63) == 1 << 63
assert abs(-1 << 63) == 1 << 63
assert abs(-(1 << 63)) == 1 << 63
assert abs(1 << 66) == 1 << 66
assert abs(-1 << 66) == 1 << 66
assert abs(-(1 << 66)) == 1 << 66

Comment thread
drew-512 marked this conversation as resolved.
Outdated
doc="pow"
assert pow(2, 10) == 1024
assert pow(2, 10, 17) == 4
Expand Down
3 changes: 1 addition & 2 deletions py/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ func (a Int) M__pos__() (Object, error) {

func (a Int) M__abs__() (Object, error) {
if a == IntMin {
abig, _ := ConvertToBigInt(a)
return abig.M__abs__()
return a.M__neg__()
}
if a < 0 {
return -a, nil
Expand Down