HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulenumeric-prelude-0.4.4Haskell98

NumericPrelude.Numeric

  • 5 types
  • 20 values
method(+) :: a -> a -> a
#

add and subtract elements

method(-) :: a -> a -> a
#

add and subtract elements

methodnegate :: a -> a
#

inverse with respect to +

methodzero :: a
#

zero element of the vector space

valuesubtract :: C a => a -> a -> a
#

subtract is (-) with swapped operand order. This is the operand order which will be needed in most cases of partial application.

valuesum :: C a => [a] -> a
#

Sum up all elements of a list. An empty list yields zero.

This function is inappropriate for number types like Peano. Maybe we should make sum a method of Additive. This would also make lengthLeft and lengthRight superfluous.

valuesum1 :: C a => [a] -> a
#

Sum up all elements of a non-empty list. This avoids including a zero which is useful for types where no universal zero is available. ToDo: Should have NonEmpty type.

Property
\(QC.NonEmpty ns) -> A.sum ns == (A.sum1 ns :: Integer)
method(*) :: a -> a -> a
#
methodone :: a
#
method(^) :: a -> Integer -> a
#

The exponent has fixed type Integer in order to avoid an arbitrarily limitted range of exponents, but to reduce the need for the compiler to guess the type (default type). In practice the exponent is most oftenly fixed, and is most oftenly 2. Fixed exponents can be optimized away and thus the expensive computation of Integers doesn't matter. The previous solution used a C constrained type and the exponent was converted to Integer before computation. So the current solution is not less efficient.

A variant of ^ with more flexibility is provided by Algebra.Core.ringPower.

valuesqr :: C a => a -> a
#
methoddiv :: a -> a -> a
#
methodmod :: a -> a -> a
#
methoddivMod :: a -> a -> (a, a)
#
Property
\n (QC.NonZero m) -> let (q,r) = divMod n m in n == (q*m+r :: Integer)
method(/) :: a -> a -> a
#
valuefieldPower :: (C a, C b) => b -> a -> a
#

A prefix function of (Algebra.Field.^-). It has a generalised exponent.

methodsqrt :: a -> a
#
methodpi :: a
#
methodexp :: a -> a
#
methodlog :: a -> a
#
method(**) :: a -> a -> a
#
value(^?) :: C a => a -> a -> a
#
methodsin :: a -> a
#
methodcos :: a -> a
#
methodtan :: a -> a
#
methodasin :: a -> a
#
methodacos :: a -> a
#
methodatan :: a -> a
#
methodsinh :: a -> a
#
methodcosh :: a -> a
#
methodtanh :: a -> a
#
methodabs :: a -> a
#
methodquot :: a -> a -> a
#
methodrem :: a -> a -> a
#
methodsplitFraction :: C b => a -> (b, a)
#
Property
\x -> (x::Rational) == (uncurry (+) $ mapFst fromInteger $ splitFraction x)
Property
\x -> uncurry (==) $ mapFst (((x::Double)-) . fromInteger) $ splitFraction x
Property
\x -> uncurry (==) $ mapFst (((x::Rational)-) . fromInteger) $ splitFraction x
Property
\x -> splitFraction x == (floor (x::Double) :: Integer, fraction x)
Property
\x -> splitFraction x == (floor (x::Rational) :: Integer, fraction x)
methodfraction :: a -> a
#
Property
\x -> let y = fraction (x::Double) in 0<=y && y<1
Property
\x -> let y = fraction (x::Rational) in 0<=y && y<1
methodceiling :: C b => a -> b
#
Property
\x -> ceiling (-x) == negate (floor (x::Double) :: Integer)
Property
\x -> ceiling (-x) == negate (floor (x::Rational) :: Integer)
methodfloor :: C b => a -> b
#
Property
\x -> ceiling (-x) == negate (floor (x::Double) :: Integer)
Property
\x -> ceiling (-x) == negate (floor (x::Rational) :: Integer)
methodatan2 :: a -> a -> a
#
methodextendedGCD :: a -> a -> (a, (a, a))
#

Compute the greatest common divisor and solve a respective Diophantine equation.

  (g,(a,b)) = extendedGCD x y ==>
       g==a*x+b*y   &&  g == gcd x y

TODO: This method is not appropriate for the PID class, because there are rings like the one of the multivariate polynomials, where for all x and y greatest common divisors of x and y exist, but they cannot be represented as a linear combination of x and y. TODO: The definition of extendedGCD does not return the canonical associate.

methodgcd :: a -> a -> a
#

The Greatest Common Divisor is defined by:

  gcd x y == gcd y x
  divides z x && divides z y ==> divides z (gcd x y)   (specification)
  divides (gcd x y) x
methodlcm :: a -> a -> a
#

Least common multiple

valueeuclid :: (C a, C a) => (a -> a -> a) -> a -> a -> a
#
valueextendedEuclid :: (C a, C a) => (a -> a -> (a, a)) -> a -> a -> (a, (a, a))
#
value(%) :: C a => a -> a -> T a
#
datadata Integer
#

Arbitrary precision integers. In contrast with fixed-size integral types such as Int, the Integer type represents the entire infinite range of integers.

Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations.

If the value is small (i.e., fits into an Int), the IS constructor is used. Otherwise IP and IN constructors are used to store a BigNat representing the positive or the negative value magnitude, respectively.

Invariant: IP and IN are used iff the value does not fit in IS.

Instances44Enum, Eq, Integral, Data, Num, Ord, …
  • Enum IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Eq IntegerDefined in ghc-bignum-1.3 · GHC.Num.Integer
  • Integral IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Data IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Num
  • Ord IntegerDefined in ghc-bignum-1.3 · GHC.Num.Integer
  • Read IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Show IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Show
  • Ix IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Bits IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits
  • PrintfArg IntegerDefined in base-4.20.2.0 · Text.Printf
  • NFData IntegerDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Pretty IntegerDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClass
  • Pretty IntegerDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClass
  • Random IntegerDefined in random-1.2.1.3 · System.Random

    Note - random generates values in the Int range

  • UniformRange IntegerDefined in random-1.2.1.3 · System.Random.Internal
  • Arbitrary IntegerDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • CoArbitrary IntegerDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • Function IntegerDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function
  • Binary IntegerDefined in binary-0.8.9.3 · Data.Binary.Class
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.Absolute
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.Ring
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.Additive
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.ToInteger
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.PrincipalIdealDomain
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.Units
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.IntegralDomain
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.ZeroTestable
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.RealRing
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.Indexable
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.Lattice
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.RealIntegral
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.OrderDecision
  • C IntegerDefined in numeric-prelude-0.4.4 · Algebra.EqualityDecision
  • Lift IntegerDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • C Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.Module
  • C Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.ModuleBasis
  • C Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Euclidean
  • Sqr Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Euclidean
  • C Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Maximum
  • C Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Sum
  • C a => C Integer (T a)Defined in numeric-prelude-0.4.4 · Algebra.Module
datadata Int
#

A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]. The exact range for a given implementation can be determined by using Prelude.minBound and Prelude.maxBound from the Prelude.Bounded class.

Instances60Bounded, Enum, Integral, Data, Num, Read, …
  • Bounded IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Enum IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Eq IntDefined in ghc-prim-0.12.0 · GHC.Classes
  • Integral IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Data IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Num
  • Ord IntDefined in ghc-prim-0.12.0 · GHC.Classes
  • Read IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Show IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Show
  • Ix IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Bits IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits
  • FiniteBits IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits
  • Storable IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg IntDefined in base-4.20.2.0 · Text.Printf
  • NFData IntDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Pretty IntDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClass
  • Pretty IntDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClass
  • Random IntDefined in random-1.2.1.3 · System.Random
  • Finite IntDefined in random-1.2.1.3 · System.Random.GFinite
  • Uniform IntDefined in random-1.2.1.3 · System.Random.Internal
  • UniformRange IntDefined in random-1.2.1.3 · System.Random.Internal
  • Arbitrary IntDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • CoArbitrary IntDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • Function IntDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function
  • Binary IntDefined in binary-0.8.9.3 · Data.Binary.Class
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.Absolute
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.Ring
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.Additive
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.ToInteger
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.PrincipalIdealDomain
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.Units
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.IntegralDomain
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.ZeroTestable
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.RealRing
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.RealIntegral
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.OrderDecision
  • C IntDefined in numeric-prelude-0.4.4 · Algebra.EqualityDecision
  • Lift IntDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • IArray UArray IntDefined in array-0.5.8.0 · Data.Array.Base
  • C Int IntDefined in numeric-prelude-0.4.4 · Algebra.Module
  • C Int IntDefined in numeric-prelude-0.4.4 · Algebra.ModuleBasis
  • C Int IntDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Euclidean
  • Sqr Int IntDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Euclidean
  • C Int IntDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Maximum
  • C Int IntDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Sum
  • MArray IOUArray Int IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • Generic1 (URec Int)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Foldable UIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable
  • Traversable UIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Traversable
  • MArray (STUArray s) Int (ST s)Defined in array-0.5.8.0 · Data.Array.Base
  • Functor (URec Int)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Show (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Generic (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep (URec Int p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UInt" 'PrefixI 'True) (S1 ('MetaSel ('Just "uInt#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UInt))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep1 (URec Int) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UInt" 'PrefixI 'True) (S1 ('MetaSel ('Just "uInt#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UInt))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data URec IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics

    Used for marking occurrences of Int#

datadata Float
#

Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.

Instances63Enum, Floating, Fractional, Data, Num, Read, …
  • Enum FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    fromEnum just truncates its argument, beware of all sorts of overflows.

    List generators have extremely peculiar behavior, mandated by Haskell Report 2010:

    Example1 expression
    [0..1.5 :: Float][0.0,1.0,2.0]
  • Eq FloatDefined in ghc-prim-0.12.0 · GHC.Classes

    Note that due to the presence of NaN, Float's Eq instance does not satisfy reflexivity.

    Example1 expression
    0/0 == (0/0 :: Float)False

    Also note that Float's Eq instance does not satisfy extensionality:

    Example2 expressions
    0 == (-0 :: Float)Truerecip 0 == recip (-0 :: Float)False
  • Floating FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float
  • Fractional FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.

    Example4 expressions
    0 == (-0 :: Float)Truerecip 0 == recip (-0 :: Float)Falsemap (/ 0) [-1, 0, 1 :: Float][-Infinity,NaN,Infinity]map (* 0) $ map (/ 0) [-1, 0, 1 :: Float][NaN,NaN,NaN]
  • Data FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:

    Example3 expressions
    (0.1 + 0.1 :: Float) + 0.5 == 0.1 + (0.1 + 0.5)False(0.1 + 0.2 :: Float) * 0.9 == 0.1 * 0.9 + 0.2 * 0.9False(0.1 * 0.1 :: Float) * 0.9 == 0.1 * (0.1 * 0.9)False
  • Ord FloatDefined in ghc-prim-0.12.0 · GHC.Classes

    See instance Ord Double for discussion of deviations from IEEE 754 standard.

  • Read FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    Beware that toRational generates garbage for non-finite arguments:

    Example2 expressions
    toRational (1/0 :: Float)340282366920938463463374607431768211456 % 1toRational (0/0 :: Float)510423550381407695195061911147652317184 % 1
  • RealFloat FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float
  • RealFrac FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    Beware that results for non-finite arguments are garbage:

    Example2 expressions
    [ f x | f <- [round, floor, ceiling], x <- [-1/0, 0/0, 1/0 :: Float] ] :: [Int][0,0,0,0,0,0,0,0,0]map properFraction [-1/0, 0/0, 1/0] :: [(Int, Float)][(0,0.0),(0,0.0),(0,0.0)]

    and get even more non-sensical if you ask for Integer instead of Int.

  • Show FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan
  • Storable FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg FloatDefined in base-4.20.2.0 · Text.Printf
  • NFData FloatDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Pretty FloatDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClass
  • Pretty FloatDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClass
  • Random FloatDefined in random-1.2.1.3 · System.Random

    Note - random produces values in the closed range [0,1].

  • UniformRange FloatDefined in random-1.2.1.3 · System.Random.Internal
  • Arbitrary FloatDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • CoArbitrary FloatDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • Function FloatDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function
  • Binary FloatDefined in binary-0.8.9.3 · Data.Binary.Class

    Uses non-IEEE754 encoding. Does not round-trip NaN.

  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.Absolute
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.Ring
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.Additive
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.Algebraic
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.Field
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.ZeroTestable
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.FloatingPoint
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.RealRing
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.RealField
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.OrderDecision
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.RealTranscendental
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.Transcendental
  • Power FloatDefined in numeric-prelude-0.4.4 · Number.Complex
  • C FloatDefined in numeric-prelude-0.4.4 · Algebra.EqualityDecision
  • Zero FloatDefined in numeric-prelude-0.4.4 · Algebra.AffineSpace
  • Lift FloatDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • IArray UArray FloatDefined in array-0.5.8.0 · Data.Array.Base
  • C Float FloatDefined in numeric-prelude-0.4.4 · Algebra.VectorSpace
  • C Float FloatDefined in numeric-prelude-0.4.4 · Algebra.Module
  • C Float FloatDefined in numeric-prelude-0.4.4 · Algebra.ModuleBasis
  • C Float FloatDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Euclidean
  • Sqr Float FloatDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Euclidean
  • C Float FloatDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Maximum
  • C Float FloatDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Sum
  • C Float FloatDefined in numeric-prelude-0.4.4 · Algebra.OccasionallyScalar
  • C Float FloatDefined in numeric-prelude-0.4.4 · Algebra.AffineSpace
  • MArray IOUArray Float IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • Generic1 (URec Float)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Foldable UFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable
  • Traversable UFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Traversable
  • MArray (STUArray s) Float (ST s)Defined in array-0.5.8.0 · Data.Array.Base
  • Functor (URec Float)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Show (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Generic (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep (URec Float p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UFloat" 'PrefixI 'True) (S1 ('MetaSel ('Just "uFloat#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UFloat))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep1 (URec Float) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UFloat" 'PrefixI 'True) (S1 ('MetaSel ('Just "uFloat#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UFloat))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data URec FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics

    Used for marking occurrences of Float#

datadata Double
#

Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.

Instances63Enum, Floating, Fractional, Data, Num, Read, …
  • Enum DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    fromEnum just truncates its argument, beware of all sorts of overflows.

    List generators have extremely peculiar behavior, mandated by Haskell Report 2010:

    Example1 expression
    [0..1.5][0.0,1.0,2.0]
  • Eq DoubleDefined in ghc-prim-0.12.0 · GHC.Classes

    Note that due to the presence of NaN, Double's Eq instance does not satisfy reflexivity.

    Example1 expression
    0/0 == (0/0 :: Double)False

    Also note that Double's Eq instance does not satisfy substitutivity:

    Example2 expressions
    0 == (-0 :: Double)Truerecip 0 == recip (-0 :: Double)False
  • Floating DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float
  • Fractional DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.

    Example4 expressions
    0 == (-0 :: Double)Truerecip 0 == recip (-0 :: Double)Falsemap (/ 0) [-1, 0, 1][-Infinity,NaN,Infinity]map (* 0) $ map (/ 0) [-1, 0, 1][NaN,NaN,NaN]
  • Data DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:

    Example3 expressions
    (0.1 + 0.1) + 0.4 == 0.1 + (0.1 + 0.4)False(0.1 + 0.2) * 0.3 == 0.1 * 0.3 + 0.2 * 0.3False(0.1 * 0.1) * 0.3 == 0.1 * (0.1 * 0.3)False
  • Ord DoubleDefined in ghc-prim-0.12.0 · GHC.Classes

    IEEE 754 Double-precision type includes not only numbers, but also positive and negative infinities and a special element called NaN (which can be quiet or signal).

    IEEE 754-2008, section 5.11 requires that if at least one of arguments of <=, <, >, >= is NaN then the result of the comparison is False, and instance Ord Double complies with this requirement. This violates the reflexivity: both NaN <= NaN and NaN >= NaN are False.

    IEEE 754-2008, section 5.10 defines totalOrder predicate. Unfortunately, compare on Doubles violates the IEEE standard and does not define a total order. More specifically, both compare NaN x and compare x NaN always return GT.

    Thus, users must be extremely cautious when using instance Ord Double. For instance, one should avoid ordered containers with keys represented by Double, because data loss and corruption may happen. An IEEE-compliant compare is available in fp-ieee package as TotallyOrdered newtype.

    Moving further, the behaviour of min and max with regards to NaN is also non-compliant. IEEE 754-2008, section 5.3.1 defines that quiet NaN should be treated as a missing data by minNum and maxNum functions, for example, minNum(NaN, 1) = minNum(1, NaN) = 1. Some languages such as Java deviate from the standard implementing minNum(NaN, 1) = minNum(1, NaN) = NaN. However, min / max in base are even worse: min NaN 1 is 1, but min 1 NaN is NaN.

    IEEE 754-2008 compliant min / max can be found in ieee754 package under minNum / maxNum names. Implementations compliant with minimumNumber / maximumNumber from a newer IEEE 754-2019, section 9.6 are available from fp-ieee package.

  • Read DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    Beware that toRational generates garbage for non-finite arguments:

    Example2 expressions
    toRational (1/0)179769313 (and 300 more digits...) % 1toRational (0/0)269653970 (and 300 more digits...) % 1
  • RealFloat DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float
  • RealFrac DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    Beware that results for non-finite arguments are garbage:

    Example2 expressions
    [ f x | f <- [round, floor, ceiling], x <- [-1/0, 0/0, 1/0] ] :: [Int][0,0,0,0,0,0,0,0,0]map properFraction [-1/0, 0/0, 1/0] :: [(Int, Double)][(0,0.0),(0,0.0),(0,0.0)]

    and get even more non-sensical if you ask for Integer instead of Int.

  • Show DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan
  • Storable DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg DoubleDefined in base-4.20.2.0 · Text.Printf
  • NFData DoubleDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Pretty DoubleDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClass
  • Pretty DoubleDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClass
  • Random DoubleDefined in random-1.2.1.3 · System.Random

    Note - random produces values in the closed range [0,1].

  • UniformRange DoubleDefined in random-1.2.1.3 · System.Random.Internal
  • Arbitrary DoubleDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • CoArbitrary DoubleDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • Function DoubleDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function
  • Binary DoubleDefined in binary-0.8.9.3 · Data.Binary.Class

    Uses non-IEEE754 encoding. Does not round-trip NaN.

  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.Absolute
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.Ring
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.Additive
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.Algebraic
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.Field
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.ToRational
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.ZeroTestable
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.FloatingPoint
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.RealRing
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.RealField
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.OrderDecision
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.RealTranscendental
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.Transcendental
  • Power DoubleDefined in numeric-prelude-0.4.4 · Number.Complex
  • C DoubleDefined in numeric-prelude-0.4.4 · Algebra.EqualityDecision
  • Zero DoubleDefined in numeric-prelude-0.4.4 · Algebra.AffineSpace
  • Lift DoubleDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • IArray UArray DoubleDefined in array-0.5.8.0 · Data.Array.Base
  • C Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.VectorSpace
  • C Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.Module
  • C Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.ModuleBasis
  • C Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Euclidean
  • Sqr Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Euclidean
  • C Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Maximum
  • C Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.Sum
  • C Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.OccasionallyScalar
  • C Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.AffineSpace
  • MArray IOUArray Double IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • Generic1 (URec Double)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Foldable UDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable
  • Traversable UDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Traversable
  • MArray (STUArray s) Double (ST s)Defined in array-0.5.8.0 · Data.Array.Base
  • Functor (URec Double)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Show (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Generic (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep (URec Double p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UDouble" 'PrefixI 'True) (S1 ('MetaSel ('Just "uDouble#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UDouble))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep1 (URec Double) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UDouble" 'PrefixI 'True) (S1 ('MetaSel ('Just "uDouble#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UDouble))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data URec DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics

    Used for marking occurrences of Double#

method(*>) :: a -> v -> v
#

scale a vector by a scalar