This module adds some support for fixed precision integers. We intentionally limit the operations that you can do on fixed precision integers because in general it's difficult to decide whether a calculation will result in an overflow in the general case. At the same time having the ability to encode fixed precision integers in your domain model can be very useful. This module allows you to do that while making sure that you can only use arbitrary precision integers in your calculation.
Example use:
calc : Int8 -> Int16 -> Int8
calc a b =
let
arbA =
Int.fromInt8 a
abrB =
Int.fromInt16 b
in
arbA
* arbB
|> Int.toInt8
|> Maybe.withDefault 0
The above example shows how the user is required to either provide a default value or change the return type of the function to handle cases where the calculation might return a value that doesn't fit in the 8 bit precision.
Represents an 8 bit integer value.
fromInt8 : Int8 -> Basics.Int
Turn an 8 bit integer value into an arbitrary precision integer to use in calculations.
toInt8 : Basics.Int -> Maybe Int8
Turn an arbitrary precision integer into an 8 bit integer if it fits within the precision.
Represents a 16 bit integer value.
fromInt16 : Int16 -> Basics.Int
Turn an 16 bit integer value into an arbitrary precision integer to use in calculations.
toInt16 : Basics.Int -> Maybe Int16
Turn an arbitrary precision integer into an 16 bit integer if it fits within the precision.
Represents a 32 bit integer value.
fromInt32 : Int32 -> Basics.Int
Turn an 32 bit integer value into an arbitrary precision integer to use in calculations.
toInt32 : Basics.Int -> Maybe Int32
Turn an arbitrary precision integer into an 32 bit integer if it fits within the precision.
Represents a 64 bit integer value.
fromInt64 : Int64 -> Basics.Int
Turn an 64 bit integer value into an arbitrary precision integer to use in calculations.
toInt64 : Basics.Int -> Maybe Int64
Turn an arbitrary precision integer into an 64 bit integer if it fits within the precision.