Skip to content

Implementation of ceil/floor/rint for Quantities #162

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

Merged
merged 2 commits into from
Dec 29, 2016

Conversation

cquiroz
Copy link
Collaborator

@cquiroz cquiroz commented Dec 28, 2016

Often I need to truncate my Quantities and I need to extract the value, truncate and then rebuild the quantity. This PR would let me do it directly on a Quantity

Copy link

@sarahgerweck sarahgerweck left a comment

Choose a reason for hiding this comment

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

I think it's probably right to mirror the method names used by scala.math, but I would suggest that you make the Scaladoc slightly more descriptive. In particular, Returns the rint value doesn't mean much unless you're pretty familiar with the methods from scala.math. I would spell out ceiling and copy the language from the rint documentation. (I think this falls under fair use.)

There's an argument that rint should be called round, which is the name used for the analogous method on Double. However, that returns a Long instead of a Double. I think I agree that rint makes more sense since scala.math.rint has more directly analogous behavior.

I personally find it a little unfortunate that the scalar part of a Quantity is always a Double. (If we had Quantity[Double, A], I would suggest we do a .round that gave back a Quantity[Long, A].) That said, a discussion about parametrizing the scalar part of a quantity is obviously out of scope, and I don't think adding these methods makes it any more difficult to do that in the future if there was an agreement that it was an improvement.

As a matter of bookkeeping, my projects have generally done an "approve" when there are only trivial changes requested, rather than a "request changes." If the committer agrees with the suggestions, they're made and merged without further review. If the committer does not agree, then we hash it out in chat. (I believe "request changes" will force a second approval, which seems overkill for the changes I've requested if we're assuming good faith.) Do we have a policy for this project?

@cquiroz
Copy link
Collaborator Author

cquiroz commented Dec 28, 2016

Thanks for your comments. I'll add more documentation as suggested. You're right that unless you know the details of the functions in scala.math the differences between rint/ceil/floor is subtle and not very well known

I agree that being Quantity always a Double is a bit odd and limits e.g. round which would be a useful method

@cquiroz
Copy link
Collaborator Author

cquiroz commented Dec 28, 2016

About bookkeeping I don't think we have a policy but what you suggest sounds good to me. I guess larger changes will naturally fall into the category of requiring more approvals or discussions while smaller changes don't require so much ceremony

Feel free to create a page on the wiki where these policies could be discussed

@derekmorr derekmorr merged commit fc13ed4 into typelevel:master Dec 29, 2016
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.

4 participants