-
Notifications
You must be signed in to change notification settings - Fork 14
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
#6 add volume module #9
Conversation
As discussed a WIP to make sure I'm headed in the right direction before pushing on with the rest of the implementation. |
Looking good! As promised, a few small comments:
Oh, and go ahead and add yourself to the AUTHORS file =) You don't need to include your e-mail address if you'd prefer not to (I think GitHub username is fine). |
I'm happy to do all of that and write the tests - I know what you mean about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am do not have any authority so please feel free to ignore, but I noticed a potential problem with the cbrt
function.
src/Quantity.elm
Outdated
-} | ||
cbrt : Quantity Float (Cubed units) -> Quantity Float units | ||
cbrt (Quantity value) = | ||
Quantity (value ^ (1 /3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For negative values this will give NaN
. (i.e. in elm (-8) ^ (1/3)
is NaN
.)
This may be the desired behaviour but at the very least this should be documented as people may expect this to work for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent point @harrysarson, great catch! Given that we don't have direct access to Math.cbrt
from JavaScript, I think the implementation should probably be updated to
cbrt (Quantity value) =
if value >= 0 then
Quantity (value ^ (1 / 3))
else
Quantity -((-value) ^ (1 / 3))
Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harrysarson Thanks!
@ianmackenzie Do you want me to close this PR and open tomorrow when I think it's ready? Or are you happy for me to leave open and let you know? |
No, I would say leave it open! Just keep adding commits to your branch, and add comments here when you have questions/want feedback/think things might be ready to merge etc. (Unless that's more annoying on your end? I don't want to add extra work...) That's how I've done it with lots of other PRs and I think it's worked really well. I really see PRs as a sort of collaborative workspace where code can be added, changed, discussed by everyone and eventually (when everyone agrees) merged back into |
Works for me. Sometimes on internal projects it's hard to tell when the
person is ready to ask for review if the PR remains open and can end up in
wasted time flagging up stuff that is in progress. But collaboration and
continuous review sounds good to me for this. Would be nice if GitHub had a
flag to say in progress Vs think this is ready for merge... Though just
talking works too.
…On Thu, 4 Oct 2018, 18:29 Ian Mackenzie, ***@***.***> wrote:
No, I would say leave it open! Just keep adding commits to your branch,
and add comments here when you have questions/want feedback/think things
might be ready to merge etc. (Unless that's more annoying on your end? I
don't want to add extra work...)
That's how I've done it with lots of other PRs and I think it's worked
really well. I really see PRs as a sort of collaborative workspace where
code can be added, changed, discussed by everyone and eventually (when
everyone agrees) merged back into master. See ianmackenzie/elm-geometry#58
<ianmackenzie/elm-geometry#58>, for example -
after that one was opened we spent a *month* trying out different
approaches, discussing different corner cases, adding some new features
etc. before eventually merging something that was quite different from how
it started. Frankly, I think it would work well to start a PR with *no
commits at all* and then just do *all* work there...but I don't know if
GitHub supports that!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#9 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA0j9F3YkrBv4_iL0eJFOayCf0jNQR2lks5uhkVwgaJpZM4XHlbY>
.
|
src/Volume.elm
Outdated
-} | ||
liters : Float -> Volume | ||
liters numLiters = | ||
cubicMeters (1.0e-6 * numLiters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has been corrected to 0.001
src/Volume.elm
Outdated
-} | ||
inLiters : Volume -> Float | ||
inLiters volume = | ||
1.0e6 * inLiters volume |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has been corrected to 1000
src/Volume.elm
Outdated
-} | ||
usLiquidGallons : Float -> Volume | ||
usLiquidGallons numUsLiquidGallons = | ||
cubicMeters ( numUsLiquidGallons / 264.17220000000003 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a bit too extreme - but no harm done. @ianmackenzie Are you using any particular definitive doc to get the conversion factors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically I've just been scouring Wikipedia - for U.S. liquid gallons is there a reason not to use numUsLiquidGallons * 0.003785411784
? https://en.wikipedia.org/wiki/Gallon#US_liquid_gallon
I'm open to using a single definitive source if there's a good one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going in that direction I got a source to go up to 0.003785409668390542
And I thought it was a bit too much. Using 264.1722 seemed acceptable by many sources.
That's why I asked because I guess it would be good to try and reference one scientific body's docs rather than different ones.
My Current implementation returns:
Volume.inCubicMeters (Volume.usLiquidGallons 1)
>>0.0037854096683905417 : Float
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess it would good to find one reference - I'll try to evaluate some options. If you have any candidates, let me know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have had a little look around - nothing jumps out. Countries and disciplines seem to publish their own standards. I haven't done any comparing though to check for similarities. There's not an obvious international body.
I'm having trouble with the different Gallons - opinions seem to vary after the 3 or 4 significant digit. I'm starting to think we'd be better off only going to 4 significant digits for these calculations because of that... but have submitted with Quart support & a few tests!
Would it be a bad idea to grab the conversion constants I'm using in multiple places and stick them in functions for reuse? I don't think you've been doing that - so am trying to keep a consistent style.
I should be able to get the Pints and fl oz in today - so this hopefully will be ready to merge.
Happy to alter my non-metric liquid conversion factors to better ones if you manage to find any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some nits
src/Volume.elm
Outdated
--@docs usFluidOunces, imperialFluidOunces | ||
@docs usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts | ||
@docs --@docs usLiquidPints, usDryPints, imperialPints | ||
@docs --@docs usFluidOunces, imperialFluidOunces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@docs
appears twice here, once before and once after the comment.
src/Volume.elm
Outdated
@docs usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons | ||
@docs usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts | ||
--@docs usLiquidPints, usDryPints, imperialPints | ||
--@docs usFluidOunces, imperialFluidOunces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elm-format adds the extra @docs
leader every time - have left these here for ref but will be sorted before it's ready to merge.
@ianmackenzie Some of the conversion factors might need tweaking (and possibly moved out into constant functions) as discussed. Might also be some more equalPairs we should do - but I'm happy for this to go in as it is if you are. |
I think it would probably make sense to pull out some of the gallon conversion factors into (non-exposed) The alternative would be to define (for example) usLiquidQuarts : Float -> Volume
usLiquidQuarts numUsLiquidQuarts =
usLiquidGallons (numUsLiquidQuarts / 4)
inUsLiquidQuarts : Volume -> Float
inUsLiquidQuarts volume =
4 * inUsLiquidGallons volume Perhaps slightly less efficient (one extra function call), but I suspect that if you're working with "non-technical" units like quarts then you're less likely to be doing high-performance numerical code anyways. And it's easy enough to optimize later if that does become an issue. Thoughts? I think once we make a decision there this is probably ready to merge - I think it makes sense to open a new issue for switching to a single standard reference for conversion factors. |
Just added #10 to figure out a more rigorous way of determining conversion factors - would love to get your thoughts! |
I thought about composing the functions together at first but I think I prefer keeping all the functions as direct to and from Cubic Meters. Makes them more independent (not sure on the technical term) and feels cleaner. So can we go with the non-exposed constants? (Until I change my mind - when I find it was a bad decision...) |
Yup, I'm totally happy with the constants approach! We can also reassess later when we make a decision about what reference(s) to use for the conversion factors - it could be useful for the structure of the code to match up closely with how things are listed in whatever document we reference. |
OK I think this is ready now. I stuck some equal pairs tests in so we remember to verify relationships again when we settle on some conversion factors. I'm open you renaming the constants before you merge. They seem a bit verbose but others that I considered didn't seem as clear.
|
Looks good. |
Just renamed the constants to the Also took the liberty of rewording the docs to say things like "Construct a volume from a number of U.S. dry pints" instead of "Construct a volume from a number of usDryPints", and made a couple of other minor formatting tweaks. I think it is indeed ready to merge! |
No description provided.