Skip to content

better Int.abs() and test coverage #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 7, 2022
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

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