-
Notifications
You must be signed in to change notification settings - Fork 95
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
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") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please return cantConvert directly There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hth :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for helping me out. |
||||||
return nil, e | ||||||
}, 0, "is_integer() -> Return True if the float instance is finite with integral value, and False otherwise.") | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.