Closed ianmackenzie closed 3 years ago
After some discussion on the Elm Slack, decided to go with
Quantity.sign : Quantity Float units -> Float
since getting the sign of an integer quantity is very rarely needed, and this allows better handling of NaN (the implementation can then use Basics.isNaN
, which is only available for Float
values).
Returning a Float
is useful to allow multiplication by the sign later, but in case branching on sign is desired then Quantity.compare
can be used instead:
case Quantity.compare quantity Quantity.zero of
GT ->
-- quantity is positive
LT ->
-- quantity is negative
EQ ->
-- quantity is zero
Signature
or perhaps even
for greatest flexibility (e.g. getting the sign of a floating-point quantity as an
Int
).