Data.Int
#fromNumber
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.
#ceil
#floor
#round
#toNumber
#fromString
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.
#Radix
newtype Radix
The number of unique digits (including zero) used to represent integers in a specific base.
#hexadecimal
hexadecimal :: Radix
The base-16 system.
#fromStringAs
fromStringAs :: Radix -> String -> Maybe Int
Like fromString
, but the integer can be specified in a different base.
Example:
fromStringAs binary "100" == Just 4
fromStringAs hexadecimal "ff" == Just 255
#toStringAs
toStringAs :: Radix -> Int -> String
#Parity
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
#parity
#even
#quot
quot :: Int -> Int -> Int
The quot
function provides truncating integer division (see the
documentation for the EuclideanRing
class). It is identical to div
in
the EuclideanRing Int
instance if the dividend is positive, but will be
slightly different if the dividend is negative. For example:
div 2 3 == 0
quot 2 3 == 0
div (-2) 3 == (-1)
quot (-2) 3 == 0
div 2 (-3) == 0
quot 2 (-3) == 0
#rem
rem :: Int -> Int -> Int
The rem
function provides the remainder after truncating integer
division (see the documentation for the EuclideanRing
class). It is
identical to mod
in the EuclideanRing Int
instance if the dividend is
positive, but will be slightly different if the dividend is negative. For
example:
mod 2 3 == 2
rem 2 3 == 2
mod (-2) 3 == 1
rem (-2) 3 == (-2)
mod 2 (-3) == 2
rem 2 (-3) == 2
Modules
- Control.Alt
- Control.Alternative
- Control.Applicative
- Control.Apply
- Control.Biapplicative
- Control.Biapply
- Control.Bind
- Control.Category
- Control.Comonad
- Control.Extend
- Control.Lazy
- Control.Monad
- Control.Monad.Gen
- Control.Monad.Gen.Class
- Control.Monad.Gen.Common
- Control.Monad.Rec.Class
- Control.Monad.ST
- Control.Monad.ST.Class
- Control.Monad.ST.Global
- Control.Monad.ST.Internal
- Control.Monad.ST.Ref
- Control.MonadPlus
- Control.MonadZero
- Control.Plus
- Control.Semigroupoid
- Data.Array
- Data.Array.NonEmpty
- Data.Array.NonEmpty.Internal
- Data.Array.Partial
- Data.Array.ST
- Data.Array.ST.Iterator
- Data.Array.ST.Partial
- Data.Bifoldable
- Data.Bifunctor
- Data.Bifunctor.Clown
- Data.Bifunctor.Flip
- Data.Bifunctor.Join
- Data.Bifunctor.Joker
- Data.Bifunctor.Product
- Data.Bifunctor.Wrap
- Data.Bitraversable
- Data.Boolean
- Data.BooleanAlgebra
- Data.Bounded
- Data.Char
- Data.Char.Gen
- Data.Char.Utils
- Data.CommutativeRing
- Data.Distributive
- Data.DivisionRing
- Data.Either
- Data.Either.Inject
- Data.Either.Nested
- Data.Enum
- Data.Enum.Gen
- Data.Eq
- Data.EuclideanRing
- Data.Field
- Data.Foldable
- Data.FoldableWithIndex
- Data.Function
- Data.Function.Uncurried
- Data.Functor
- Data.Functor.Invariant
- Data.FunctorWithIndex
- Data.HeytingAlgebra
- Data.Identity
- Data.Int
- Data.Int.Bits
- Data.Maybe
- Data.Maybe.First
- Data.Maybe.Last
- Data.Monoid
- Data.Monoid.Additive
- Data.Monoid.Alternate
- Data.Monoid.Conj
- Data.Monoid.Disj
- Data.Monoid.Dual
- Data.Monoid.Endo
- Data.Monoid.Multiplicative
- Data.NaturalTransformation
- Data.Newtype
- Data.NonEmpty
- Data.Ord
- Data.Ord.Down
- Data.Ord.Max
- Data.Ord.Min
- Data.Ord.Unsafe
- Data.Ordering
- Data.Ring
- Data.Semigroup
- Data.Semigroup.First
- Data.Semigroup.Foldable
- Data.Semigroup.Last
- Data.Semigroup.Traversable
- Data.Semiring
- Data.Show
- Data.String
- Data.String.CaseInsensitive
- Data.String.CodePoints
- Data.String.CodeUnits
- Data.String.Common
- Data.String.Gen
- Data.String.NonEmpty
- Data.String.NonEmpty.CaseInsensitive
- Data.String.NonEmpty.CodePoints
- Data.String.NonEmpty.CodeUnits
- Data.String.NonEmpty.Internal
- Data.String.Pattern
- Data.String.Regex
- Data.String.Regex.Flags
- Data.String.Regex.Unsafe
- Data.String.Unsafe
- Data.String.Utils
- Data.Symbol
- Data.Traversable
- Data.Traversable.Accum
- Data.Traversable.Accum.Internal
- Data.TraversableWithIndex
- Data.Tuple
- Data.Tuple.Nested
- Data.Unfoldable
- Data.Unfoldable1
- Data.Unit
- Data.Void
- Effect
- Effect.Class
- Effect.Class.Console
- Effect.Console
- Effect.Ref
- Effect.Uncurried
- Effect.Unsafe
- Global
- Global.Unsafe
- MCPrelude
- Main
- Math
- PSCI.Support
- Partial
- Partial.Unsafe
- Prelude
- Prim
- Prim.Boolean
- Prim.Ordering
- Prim.Row
- Prim.RowList
- Prim.Symbol
- Prim.TypeError
- Record.Unsafe
- Type.Data.Row
- Type.Data.RowList
- Type.Equality
- Unsafe.Coerce