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

#6 add volume module #9

Merged
merged 18 commits into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ add your name to the end of this list!

Ian Mackenzie <[email protected]>
Matthias Devlamynck <[email protected]>
Katja Mordaunt <[email protected]>
3 changes: 2 additions & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"Resistance",
"Speed",
"Temperature",
"Voltage"
"Voltage",
"Volume"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
Expand Down
41 changes: 36 additions & 5 deletions src/Quantity.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Quantity exposing
( Quantity(..)
, Squared, Rate
, Squared, Cubed, Rate
, zero, infinity, positiveInfinity, negativeInfinity
, lessThan, greaterThan, compare, equalWithin, max, min, isNaN, isInfinite
, negate, plus, minus, product, ratio, scaleBy, divideBy, abs, clamp, squared, sqrt
, negate, plus, minus, product, ratio, scaleBy, divideBy, abs, clamp, squared, sqrt, cubed, cbrt
, round, floor, ceiling, truncate, toFloatQuantity
, sum, minimum, maximum, sort
, per, times, at, at_, inverse
Expand All @@ -17,10 +17,10 @@ module Quantity exposing

# Unit types

The `Squared` and `Rate` units types allow you to build up and work with
The `Squared`, `Cubed` and `Rate` units types allow you to build up and work with
composite units in a fairly flexible way.

@docs Squared, Rate
@docs Squared, Cubed, Rate


# Constants
Expand All @@ -35,7 +35,7 @@ composite units in a fairly flexible way.

# Arithmetic

@docs negate, plus, minus, product, ratio, scaleBy, divideBy, abs, clamp, squared, sqrt
@docs negate, plus, minus, product, ratio, scaleBy, divideBy, abs, clamp, squared, sqrt, cubed, cbrt


# `Int`/`Float` conversion
Expand Down Expand Up @@ -111,6 +111,17 @@ type Squared units
= Squared units


{-| Represents a units type that is the cube of some other units type; for
example, `Meters` is one units type (the units type of a `Length`) and `Cubed
Meters` is another (the units type of an `Volume`). This is useful because some
functions in this module (specifically [`cubed`](Quantity#cubed)
and [`cbrt`](Quantity#cbrt)) "know" about the
`Cubed` type and how to work with it.
-}
type Cubed units
= Cubed units


{-| Represents the units type of a rate or quotient such as a speed (`Rate
Meters Seconds`) or a pressure (`Rate Newtons SquareMeters`). As with `Squared`,
there are several functions that "know" about the `Rate` units type and how to
Expand Down Expand Up @@ -504,6 +515,26 @@ sqrt (Quantity value) =
Quantity (Basics.sqrt value)


{-| Cube a quantity with some `units`, resulting in a new quantity in
`Cubed units`.
ianmackenzie marked this conversation as resolved.
Show resolved Hide resolved
-}
cubed : Quantity number units -> Quantity number (Cubed units)
cubed (Quantity value) =
Quantity (value * value * value)


{-| Take a quantity in `Cubed units` and return the cube root of that
quantity in plain `units`.
-}
cbrt : Quantity Float (Cubed units) -> Quantity Float units
cbrt (Quantity value) =
if value >= 0 then
Quantity (value ^ (1 / 3))

else
Quantity -(-value ^ (1 / 3))



---------- INT/FLOAT CONVERSIONS ----------

Expand Down
Loading