-
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e22c518
Provide initial volume functions
katjam b0986d7
Add cubed and cbrt support to Quantity
katjam 4e12a92
Merge branch 'master' into 6-add-volume-module
katjam 41d3a1c
Remove unneccessary cm and mm function. Correct cbtr.
katjam 6e908c9
Merge branch '6-add-volume-module' of github.com:katjam/elm-units int…
katjam eed25b3
Tidier docs and remove deciliter stubs (no immediate need).
katjam 8edc9f4
Gallon conversions and correct Liter/Milliliter
katjam ccf08da
Volume fuzz tests and responsibility
katjam 89118f8
Convert to Quarts
katjam 1c8b749
Remove stray @doc added by elm-format
katjam 69c4b99
Add pints to Volume
katjam a041b4e
Add fluid ounces to Volume
katjam 348f813
Include conversion factors as helper constants
katjam a85a6aa
Tweak doc formatting
ianmackenzie 8a26370
Rename volume conversion constants
ianmackenzie d560643
Reword Volume doc comments
ianmackenzie 8d6c6ba
Merge remote-tracking branch 'upstream/master' into 6-add-volume-module
ianmackenzie 59b5d5c
Tweak documentation wording
ianmackenzie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
module Volume exposing | ||
( Volume, CubicMeters | ||
, cubicMeters, inCubicMeters | ||
, cubicMillimeters, inCubicMillimeters, cubicCentimeters, inCubicCentimeters | ||
, cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards | ||
--, milliliter, liter, deciliter | ||
--, usLiquidGallons, usDryGallons, imperialGallons | ||
--, usLiquidQuarts, usDryQuarts, imperialQuarts | ||
--, usLiquidPints, usDryPints, imperialPints | ||
--, usFluidOunces, imperialFluidOunces | ||
) | ||
|
||
{-| A `Volume` represents a volume in cubic meters, cubic feet, liters, | ||
US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic meters. | ||
|
||
@docs Volume, CubicMeters | ||
|
||
|
||
## Metric | ||
|
||
@docs cubicMeters, inCubicMeters | ||
@docs cubicMillimeters, inCubicMillimeters, cubicCentimeters, inCubicCentimeters | ||
@docs --@docs milliliters, inMilliliters, liters, etc | ||
|
||
|
||
## Imperial | ||
|
||
@docs cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards | ||
@docs --@docs usLiquidGallons, usDryGallons, imperialGallons | ||
@docs --@docs usLiquidQuarts, usDryQuarts, imperialQuarts | ||
@docs --@docs usLiquidPints, usDryPints, imperialPints | ||
@docs --@docs usFluidOunces, imperialFluidOunces | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
-} | ||
|
||
import Length exposing (Meters) | ||
import Quantity exposing (Quantity(..), Cubed) | ||
|
||
|
||
{-| -} | ||
type alias CubicMeters = | ||
Cubed Meters | ||
|
||
|
||
{-| -} | ||
type alias Volume = | ||
Quantity Float CubicMeters | ||
|
||
|
||
{-| Construct a volume from a number of cubic meters. | ||
-} | ||
cubicMeters : Float -> Volume | ||
cubicMeters numCubicMeters = | ||
Quantity numCubicMeters | ||
|
||
|
||
{-| Convert a volume to a number of cubic meters. | ||
-} | ||
inCubicMeters : Volume -> Float | ||
inCubicMeters (Quantity numCubicMeters) = | ||
numCubicMeters | ||
|
||
|
||
{-| Construct a volume from a number of cubic millimeters. | ||
-} | ||
cubicMillimeters : Float -> Volume | ||
cubicMillimeters numCubicMillimeters = | ||
cubicMeters (1.0e-9 * numCubicMillimeters) | ||
|
||
|
||
{-| Convert a volume to a number of cubic millimeters. | ||
-} | ||
inCubicMillimeters : Volume -> Float | ||
inCubicMillimeters volume = | ||
1.0e9 * inCubicMeters volume | ||
|
||
|
||
{-| Construct a volume from a number of cubic inches. | ||
-} | ||
cubicInches : Float -> Volume | ||
cubicInches numCubicInches = | ||
cubicMeters (0.0254 * 0.0254 * 0.0254 * numCubicInches) | ||
|
||
|
||
{-| Convert a volume to a number of cubic inches. | ||
-} | ||
inCubicInches : Volume -> Float | ||
inCubicInches volume = | ||
inCubicMeters volume / (0.0254 * 0.0254 * 0.0254) | ||
|
||
|
||
{-| Construct a volume from a number of cubic centimeters. | ||
-} | ||
cubicCentimeters : Float -> Volume | ||
cubicCentimeters numCubicCentimeters = | ||
cubicMeters (1.0e-6 * numCubicCentimeters) | ||
|
||
|
||
{-| Convert a volume to a number of cubic centimeters. | ||
-} | ||
inCubicCentimeters : Volume -> Float | ||
inCubicCentimeters volume = | ||
1.0e6 * inCubicMeters volume | ||
|
||
|
||
{-| Construct a volume from a number of cubic feet. | ||
-} | ||
cubicFeet : Float -> Volume | ||
cubicFeet numCubicFeet = | ||
cubicMeters (0.3048 * 0.3048 * 0.3048 * numCubicFeet) | ||
|
||
|
||
{-| Convert a volume to a number of cubic feet. | ||
-} | ||
inCubicFeet : Volume -> Float | ||
inCubicFeet volume = | ||
inCubicMeters volume / (0.3048 * 0.3048 * 0.3048) | ||
|
||
|
||
{-| Construct a volume from a number of cubic yards. | ||
-} | ||
cubicYards : Float -> Volume | ||
cubicYards numCubicYards = | ||
cubicMeters (0.9144 * 0.9144 * 0.9144 * numCubicYards) | ||
|
||
|
||
{-| Convert a volume to a number of cubic yards. | ||
-} | ||
inCubicYards : Volume -> Float | ||
inCubicYards volume = | ||
inCubicMeters volume / (0.9144 * 0.9144 * 0.9144) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)
isNaN
.)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 toDoes 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!