Visitar URL original
Implement float is_integer method by DoDaek · Pull Request #112 · go-python/gpython · GitHub
The Wayback Machine - https://web.archive.org/web/20200910211020/https://github.com/go-python/gpython/pull/112
Skip to content
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

Implement float is_integer method #112

Merged
merged 3 commits into from Oct 5, 2019
Merged

Conversation

@DoDaek
Copy link
Contributor

DoDaek commented Oct 2, 2019

ISSUE : #111

@DoDaek
Copy link
Contributor Author

DoDaek commented Oct 2, 2019

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
Member

sbinet commented Oct 2, 2019

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
Member

sbinet commented Oct 2, 2019

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

@codecov-io
Copy link

codecov-io commented Oct 2, 2019 •

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 Files Coverage Δ
py/float.go 40.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.

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

This comment has been minimized.

@corona10

corona10 Oct 3, 2019 •

Member

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;

This comment has been minimized.

@DoDaek

DoDaek Oct 3, 2019 •

Author Contributor

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.

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

This comment has been minimized.

@corona10

corona10 Oct 3, 2019 •

Member
return nil, cantConvert(a, "float")

might be better

This comment has been minimized.

@DoDaek

DoDaek Oct 3, 2019

Author Contributor

I'll change that part with cantConvert method.

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

This comment has been minimized.

@corona10

corona10 Oct 4, 2019

Member

Please return nil, err when FloatAsFloat64 return error

This comment has been minimized.

@DoDaek

DoDaek Oct 4, 2019

Author Contributor

Ok, I'll change that.

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

This comment has been minimized.

@corona10

corona10 Oct 4, 2019

Member

Please return cantConvert directly

This comment has been minimized.

@DoDaek

DoDaek Oct 4, 2019

Author Contributor

How do I use the second return value directly?

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

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

This comment has been minimized.

@sbinet

sbinet Oct 4, 2019

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

This comment has been minimized.

@sbinet

sbinet Oct 4, 2019

Member

hth :)

This comment has been minimized.

@DoDaek

DoDaek Oct 4, 2019

Author Contributor

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

Copy link
Member

corona10 left a comment

LGTM

@corona10 corona10 merged commit 720c16a into go-python:master Oct 5, 2019
3 of 4 checks passed
3 of 4 checks passed
codecov/patch 62.5% of diff hit (target 72.54%)
Details
codecov/project 72.61% (+0.06%) compared to 6ba973e
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.