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

feat(stdlib): Add sign function to Number module #1079

Merged
merged 8 commits into from
Dec 29, 2021
Merged

Conversation

phated
Copy link
Member

@phated phated commented Dec 21, 2021

This adds the Number.sign(x) function, similar to the Math.sign function in JavaScript. It even accounts for the -0 case by multiplying the 0 result by the input number (you can see it working in the tests).

Opening as a draft, just to make sure we are good with the implementation.

Ref #1017

Copy link
Member

@peblair peblair 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 to me!

@phated
Copy link
Member Author

phated commented Dec 27, 2021

@peblair Cool! I'll convert it from a draft then.

@phated phated marked this pull request as ready for review December 27, 2021 19:13
@phated phated requested a review from a team December 27, 2021 19:13
Copy link
Member

@marcusroberts marcusroberts left a comment

Choose a reason for hiding this comment

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

It took me a second to work out why you needed _ => 0 * x, but clever!

stdlib/number.gr Outdated Show resolved Hide resolved
stdlib/number.gr Outdated Show resolved Hide resolved
stdlib/number.gr Outdated Show resolved Hide resolved
phated and others added 2 commits December 28, 2021 17:04
Co-authored-by: Oscar Spencer <oscar@grain-lang.org>
Co-authored-by: Oscar Spencer <oscar@grain-lang.org>
stdlib/number.gr Outdated Show resolved Hide resolved
@phated phated merged commit b6483d5 into main Dec 29, 2021
@phated phated deleted the phated/number-sign branch December 29, 2021 01:15
@github-actions github-actions bot mentioned this pull request May 31, 2022
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.

None yet

4 participants