Data.Int
- Package
- purescript-integers
- Repository
- purescript/purescript-integers
#fromNumber Source
fromNumber :: Number -> Maybe Int
Creates an Int
from a Number
value. The number must already be an
integer and fall within the valid range of values for the Int
type
otherwise Nothing
is returned.
#fromString Source
fromString :: String -> Maybe Int
Reads an Int
from a String
value. The number must parse as an integer
and fall within the valid range of values for the Int
type, otherwise
Nothing
is returned.
#Parity Source
data Parity
A type for describing whether an integer is even or odd.
The Ord
instance considers Even
to be less than Odd
.
The Semiring
instance allows you to ask about the parity of the results
of arithmetical operations, given only the parities of the inputs. For
example, the sum of an odd number and an even number is odd, so
Odd + Even == Odd
. This also works for multiplication, eg. the product
of two odd numbers is odd, and therefore Odd * Odd == Odd
.
More generally, we have that
parity x + parity y == parity (x + y)
parity x * parity y == parity (x * y)
for any integers x
, y
. (A mathematician would say that parity
is a
ring homomorphism.)
After defining addition and multiplication on Parity
in this way, the
Semiring
laws now force us to choose zero = Even
and one = Odd
.
This Semiring
instance actually turns out to be a Field
.
Constructors
Instances
#Radix Source
newtype Radix
The number of unique digits (including zero) used to represent integers in a specific base.
#hexadecimal Source
hexadecimal :: Radix
The base-16 system.
- Modules
- Data.
Int - Data.
Int. Bits