Skip to content

Implement float is_integer method #112

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
Oct 5, 2019
Merged
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
Prev Previous commit
Next Next commit
float: modified is_integer method
  • Loading branch information
DoDaek committed Oct 4, 2019
commit d78d5155a325c544bcf0ceec98e8b0c3bc92b0de
12 changes: 6 additions & 6 deletions py/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,14 @@ func (a Float) M__ge__(other Object) (Object, error) {
func init() {
FloatType.Dict["is_integer"] = MustNewMethod("is_integer", func(self Object) (Object, error) {
if a, ok := convertToFloat(self); ok {
f, err := FloatAsFloat64(a)
if err != nil {
return nil, err
f, _ := FloatAsFloat64(a)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please return nil, err when FloatAsFloat64 return error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll change that.

if math.Floor(f) == f {
return True, nil
}
b := math.Abs(f - math.Round(f))
return NewBool(b < math.SmallestNonzeroFloat64), nil;
return False, nil
}
return nil, AttributeError
_, e := cantConvert(self, "float")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please return cantConvert directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I use the second return value directly?

Sorry, I'm looking for that. But I can't find any information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, e := cantConvert(self, "float")
return cantConvert(self, "float")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hth :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for helping me out.
I couldn't think so....

return nil, e
}, 0, "is_integer() -> Return True if the float instance is finite with integral value, and False otherwise.")
}

Expand Down