Skip to content

Implement float is_integer method - #112

Merged
corona10 merged 3 commits into
go-python:masterfrom
DoDaek:issue-111
Oct 5, 2019
Merged

Implement float is_integer method#112
corona10 merged 3 commits into
go-python:masterfrom
DoDaek:issue-111

Conversation

@DoDaek

Copy link
Copy Markdown
Contributor

ISSUE : #111

@DoDaek

Copy link
Copy Markdown
ContributorAuthor

In Go: 1.9.x, there is no math.Round method

github.com/go-python/gpython/py
# github.com/go-python/gpython/py
py/float.go:405:22: undefined: math.Round
The command "eval go get -v -t ./... " failed 3 times.

@sbinet

Copy link
Copy Markdown
Member

we could drop support for 1.9 (and 1.10) and bump to 1.11.x, 1.12.x and 1.13.x (as is done by the Go project).

@sbinet

Copy link
Copy Markdown
Member

please rebase on top of the latest master (6ba973e) to fix the travis failure.

@codecov-io

codecov-io commented Oct 2, 2019

Copy link
Copy Markdown

Codecov Report

Merging #112 into master will increase coverage by 0.06%.
The diff coverage is 62.5%.

Impacted file tree graph

@@ Coverage Diff @@## master #112 +/- ##
==========================================
+ Coverage 72.54% 72.61% +0.06% 
==========================================
Files 60 60 Lines 11887 11895 +8 ==========================================
+ Hits 8623 8637 +14 + Misses 2739 2731 -8 - Partials 525 527 +2
Impacted FilesCoverage Δ
py/float.go40.9% <62.5%> (+5.06%)⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ba973e...3b0574d. Read the comment docs.

Comment threadpy/float.go Outdated
return nil, err
}
b := math.Abs(f - math.Round(f))
return NewBool(b < math.SmallestNonzeroFloat64), nil;

@corona10corona10Oct 3, 2019

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there any reason to use this logic?
CPython check the float is an integer by using the floor API.

o= (floor(x) ==x) ? Py_True : Py_False;

@DoDaekDoDaekOct 3, 2019

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Calculating the difference between rounded value and original value.
If the difference is less than the minimum value of float64, I think that it would be an integer.

I'll check the Cpython and then fix that part by using floor API.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment threadpy/float.go Outdated
b := math.Abs(f - math.Round(f))
return NewBool(b < math.SmallestNonzeroFloat64), nil;
}
return nil, AttributeError

@corona10corona10Oct 3, 2019

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

returnnil, cantConvert(a, "float")

might be better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll change that part with cantConvert method.

Comment threadpy/float.go Outdated
f, err := FloatAsFloat64(a)
if err != nil {
return nil, err
f, _ := FloatAsFloat64(a)

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

Comment threadpy/float.go Outdated
return False, nil
}
return nil, AttributeError
_, e := cantConvert(self, "float")

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

Comment threadpy/float.go Outdated
}
return False, nil
}
_, e := cantConvert(self, "float")

Copy link
Copy Markdown
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")
returncantConvert(self, "float")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hth :)

Copy link
Copy Markdown
ContributorAuthor

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....

@corona10corona10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@corona10
corona10 merged commit 720c16a into go-python:masterOct 5, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@DoDaek@sbinet@codecov-io@corona10