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

add math module #357

Merged
merged 8 commits into from
Mar 12, 2021
Merged

add math module #357

merged 8 commits into from
Mar 12, 2021

Conversation

b5
Copy link
Contributor

@b5 b5 commented Mar 5, 2021

closes #78.

cc @dustmop, @adonovan, & @essobedo

lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/trig.go Outdated Show resolved Hide resolved
starlark/testdata/math.star Outdated Show resolved Hide resolved
starlark/testdata/math.star Outdated Show resolved Hide resolved
starlark/testdata/math.star Outdated Show resolved Hide resolved
Copy link

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Hooray another one! :-) Thanks @b5 for pushing this!
Looks almost perfect. Maybe just rename floatFunc to floatFunc1 to match the other name and add the in radians comment to the documentation of all trigonometric functions. It's missing for some functions at the end of the file. But it's only my two cent...

@essobedo
Copy link
Contributor

essobedo commented Mar 6, 2021

@b5 I take it over

@google-cla
Copy link

google-cla bot commented Mar 6, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@essobedo
Copy link
Contributor

essobedo commented Mar 6, 2021

@googlebot I consent.

@essobedo
Copy link
Contributor

essobedo commented Mar 6, 2021

@adonovan I believe that I have made all the requested changes except Let's call this abs, and overload it for int and float.. I tried something regarding this remark, but I don't like it, could you please tell me what you had in mind exactly?

lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
@essobedo
Copy link
Contributor

essobedo commented Mar 8, 2021

@adonovan Fixed, please check again

lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
starlark/testdata/math.star Show resolved Hide resolved
@essobedo
Copy link
Contributor

essobedo commented Mar 8, 2021

@adonovan all fixed, please check again

@essobedo
Copy link
Contributor

essobedo commented Mar 8, 2021

It sounds that there is an issue with the build, the status is never reported

lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
@essobedo
Copy link
Contributor

essobedo commented Mar 8, 2021

@adonovan done, please check it again

lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
@essobedo
Copy link
Contributor

essobedo commented Mar 8, 2021

@adonovan Done, I also added some new functions

@essobedo
Copy link
Contributor

essobedo commented Mar 9, 2021

@adonovan done, please check again

Copy link
Collaborator

@adonovan adonovan left a comment

Choose a reason for hiding this comment

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

Nearly there!

lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
lib/math/math.go Outdated Show resolved Hide resolved
@essobedo
Copy link
Contributor

essobedo commented Mar 9, 2021

@adonovan done

Copy link
Collaborator

@adonovan adonovan left a comment

Choose a reason for hiding this comment

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

Looks good. Many thanks.

@adonovan
Copy link
Collaborator

adonovan commented Mar 9, 2021

Jon, can you merge this PR? It LGTM.

@b5
Copy link
Contributor Author

b5 commented Mar 9, 2021

Thanks again @adonovan & @essobedo! Excited to keep these moving

@brandjon
Copy link
Collaborator

The status check for CI never returned. Can you try force-pushing a new commit (e.g. with git commit --amend --no-edit), as suggested here?

@brandjon
Copy link
Collaborator

Actually looks like our travis CI integration method is deprecated. Will reconfigure on my side...

@brandjon
Copy link
Collaborator

Actually it looks like we've received status updates recently from this hook and the deprecation that article's talking about happened a while ago, so let's just force push and see if that fixes it.

@b5
Copy link
Contributor Author

b5 commented Mar 10, 2021

ok, force pushed, doesn't look like we're having any luck ☹️

@fenollp
Copy link
Contributor

fenollp commented Mar 11, 2021

Hi! Sorry to barge in a little late.
I see the type floatOrInt float64 was introduced to Unpack arguments of all builtins.
Are we not loosing precision here? We seem to be discarding anything that doesn't fit in float64 (so big.Ints).
But I don't see this mentioned. Did I miss it?

Am I correct in assuming that Unpacking a litteral bigint into float64 returns an error?

abs(9007199254740992+1) # = abs(1+2^53) does this fail?

@adonovan
Copy link
Collaborator

adonovan commented Mar 11, 2021

I see the type floatOrInt float64 was introduced to Unpack arguments of all builtins.
Are we not loosing precision here? We seem to be discarding anything that doesn't fit in float64 (so big.Ints).

An int of any magnitude is converted to a float. This will fail if the magnitude is bigger than about 1e308. However, the result of math.abs is always a floating-point number, even if the argument was an integer.

This is consistent with Python3, but it does argue in favor of renaming math.abs to math.fabs, both for consistency with Python, and to indicate that the result is a float. I'm not aware of how to compute abs of a big int in Python. We should also have a test for this.

UPDATE: Ah, Python's abs function (not in math package) returns the abs value without changing the type. Perhaps this should be added to the spec as a standard "universe" function.

@tetromino
Copy link
Collaborator

I manually kicked off the travis build, and it finally worked.

But now it seems we are missing the google cla check from one of the authors.

@essobedo and @b5 - please see googlebot's comment above-791891376 - you would need to make a comment with the literal words @googlebot I consent. to agree to the cla.

@tetromino
Copy link
Collaborator

Never mind, googlebot is now happy :)

@tetromino tetromino merged commit 74c10e2 into google:master Mar 12, 2021
@brandjon
Copy link
Collaborator

brandjon commented Mar 13, 2021

Thanks for taking care of the merge @tetromino.

@essobedo essobedo deleted the feat_math_module branch March 15, 2021 08:26
b5 added a commit to qri-io/starlib that referenced this pull request Apr 8, 2021
…am versions

After a *large* community effort, we've successfully moved two packages from
starlib into the "real" standard library in go-starlark:
* math: google/starlark-go#357
* time: google/starlark-go#327

Both of these packages have had a great deal of vetting & improvement in the
process of migrating. While this does introduce many breaking changes for both
packages, both packages have better stability & performance characteristics.

Moving forward, we'll try to follow the pattern of developing & testing packages
here, and for those deemed worthy, move them up into go-starlark. Once a package
lands there, we'll switch starlib to being a strict import-and-document-only,
which effectively locks their API. Keeping package APIs locked will cut down on
drift, benefitting the broader starlark ecosystem.

BREAKING CHANGE:
math & time modules have been overhauled. Refer to package documentation for
details
b5 added a commit to qri-io/starlib that referenced this pull request Apr 8, 2021
…am versions

After a *large* community effort, we've successfully moved two packages from
starlib into the "real" standard library in go-starlark:
* math: google/starlark-go#357
* time: google/starlark-go#327

In addition, both time & math imports have lost thier ".star" suffixes:

load("time.star", "time") -> load("time", "time")
load("math.star, "math") -> load("math", "math")

Both of these packages have had a great deal of vetting & improvement in the
process of migrating. While this does introduce many breaking changes for both
packages, both packages have better stability & performance characteristics.

Moving forward, we'll try to follow the pattern of developing & testing packages
here, and for those deemed worthy, move them up into go-starlark. Once a package
lands there, we'll switch starlib to being a strict import-and-document-only,
which effectively locks their API. Keeping package APIs locked will cut down on
drift, benefitting the broader starlark ecosystem.

BREAKING CHANGE:
math & time modules have been overhauled. Refer to package documentation for
details
b5 added a commit to qri-io/starlib that referenced this pull request Apr 8, 2021
…am versions

After a *large* community effort, we've successfully moved two packages from
starlib into the "real" standard library in go-starlark:
* math: google/starlark-go#357
* time: google/starlark-go#327

In addition, both time & math imports have lost thier ".star" suffixes:

load("time.star", "time") -> load("time", "time")
load("math.star, "math") -> load("math", "math")

Both of these packages have had a great deal of vetting & improvement in the
process of migrating. While this does introduce many breaking changes for both
packages, both packages have better stability & performance characteristics.

Moving forward, we'll try to follow the pattern of developing & testing packages
here, and for those deemed worthy, move them up into go-starlark. Once a package
lands there, we'll switch starlib to being a strict import-and-document-only,
which effectively locks their API. Keeping package APIs locked will cut down on
drift, benefitting the broader starlark ecosystem.

BREAKING CHANGE:
math & time modules have been overhauled. Refer to package documentation for
details
Sign up for free to 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.

a math library
7 participants