add and subtract elements
Modulenumeric-prelude-0.4.4Haskell98
NumericPrelude.Numeric
- 5 types
- 20 values
- Packagenumeric-prelude-0.4.4
- Exports82
- LanguageHaskell98
- LicenceBSD-3-Clause
- SourceAdditive.hs
add and subtract elements
inverse with respect to +
zero element of the vector space
subtract is (-) with swapped operand order.
This is the operand order which will be needed in most cases
of partial application.
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.
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.
\(QC.NonEmpty ns) -> A.sum ns == (A.sum1 ns :: Integer)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.
A prefix function of (Algebra.Ring.^)
with a parameter order that fits the needs of partial application
and function composition.
It has generalised exponent.
See: Argument order of expNat on
http://www.haskell.org/pipermail/haskell-cafe/2006-September/018022.html
\n (QC.NonZero m) -> let (q,r) = divMod n m in n == (q*m+r :: Integer)A prefix function of (Algebra.Field.^-).
It has a generalised exponent.
Needed to work around shortcomings in GHC.
\x -> (x::Rational) == (uncurry (+) $ mapFst fromInteger $ splitFraction x)\x -> uncurry (==) $ mapFst (((x::Double)-) . fromInteger) $ splitFraction x\x -> uncurry (==) $ mapFst (((x::Rational)-) . fromInteger) $ splitFraction x\x -> splitFraction x == (floor (x::Double) :: Integer, fraction x)\x -> splitFraction x == (floor (x::Rational) :: Integer, fraction x)\x -> let y = fraction (x::Double) in 0<=y && y<1\x -> let y = fraction (x::Rational) in 0<=y && y<1\x -> ceiling (-x) == negate (floor (x::Double) :: Integer)\x -> ceiling (-x) == negate (floor (x::Rational) :: Integer)\x -> ceiling (-x) == negate (floor (x::Double) :: Integer)\x -> ceiling (-x) == negate (floor (x::Rational) :: Integer)TODO: Should be moved to a continued fraction module.
Lossless conversion from any representation of a rational to Rational
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 yTODO: 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.
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) xLeast common multiple
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.EnumEq IntegerDefined in ghc-bignum-1.3 · GHC.Num.IntegerIntegral IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.RealData IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.NumOrd IntegerDefined in ghc-bignum-1.3 · GHC.Num.IntegerRead IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.RealShow IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.ShowIx IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.IxBits IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsPrintfArg IntegerDefined in base-4.20.2.0 · Text.PrintfNFData IntegerDefined in deepseq-1.5.0.0 · Control.DeepSeqPretty IntegerDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClassPretty IntegerDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClassRandom IntegerDefined in random-1.2.1.3 · System.RandomUniformRange IntegerDefined in random-1.2.1.3 · System.Random.InternalArbitrary IntegerDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.ArbitraryCoArbitrary IntegerDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.ArbitraryFunction IntegerDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionBinary IntegerDefined in binary-0.8.9.3 · Data.Binary.ClassC IntegerDefined in numeric-prelude-0.4.4 · Algebra.AbsoluteC IntegerDefined in numeric-prelude-0.4.4 · Algebra.RingC IntegerDefined in numeric-prelude-0.4.4 · Algebra.AdditiveC IntegerDefined in numeric-prelude-0.4.4 · Algebra.ToIntegerC IntegerDefined in numeric-prelude-0.4.4 · Algebra.ToRationalC IntegerDefined in numeric-prelude-0.4.4 · Algebra.PrincipalIdealDomainC IntegerDefined in numeric-prelude-0.4.4 · Algebra.UnitsC IntegerDefined in numeric-prelude-0.4.4 · Algebra.IntegralDomainC IntegerDefined in numeric-prelude-0.4.4 · Algebra.ZeroTestableC IntegerDefined in numeric-prelude-0.4.4 · Algebra.RealRingC IntegerDefined in numeric-prelude-0.4.4 · Algebra.IndexableC IntegerDefined in numeric-prelude-0.4.4 · Algebra.LatticeC IntegerDefined in numeric-prelude-0.4.4 · Algebra.RealIntegralC IntegerDefined in numeric-prelude-0.4.4 · Algebra.OrderDecisionC IntegerDefined in numeric-prelude-0.4.4 · Algebra.EqualityDecisionLift IntegerDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxC Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.ModuleC Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.ModuleBasisC Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.EuclideanSqr Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.EuclideanC Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.MaximumC Integer IntegerDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.SumC a => C Integer (T a)Defined in numeric-prelude-0.4.4 · Algebra.Module
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.EnumEnum IntDefined in ghc-internal-9.1003.0 · GHC.Internal.EnumEq IntDefined in ghc-prim-0.12.0 · GHC.ClassesIntegral IntDefined in ghc-internal-9.1003.0 · GHC.Internal.RealData IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum IntDefined in ghc-internal-9.1003.0 · GHC.Internal.NumOrd IntDefined in ghc-prim-0.12.0 · GHC.ClassesRead IntDefined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal IntDefined in ghc-internal-9.1003.0 · GHC.Internal.RealShow IntDefined in ghc-internal-9.1003.0 · GHC.Internal.ShowIx IntDefined in ghc-internal-9.1003.0 · GHC.Internal.IxBits IntDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsFiniteBits IntDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsStorable IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg IntDefined in base-4.20.2.0 · Text.PrintfNFData IntDefined in deepseq-1.5.0.0 · Control.DeepSeqPretty IntDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClassPretty IntDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClassRandom IntDefined in random-1.2.1.3 · System.RandomFinite IntDefined in random-1.2.1.3 · System.Random.GFiniteUniform IntDefined in random-1.2.1.3 · System.Random.InternalUniformRange IntDefined in random-1.2.1.3 · System.Random.InternalArbitrary IntDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.ArbitraryCoArbitrary IntDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.ArbitraryFunction IntDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionBinary IntDefined in binary-0.8.9.3 · Data.Binary.ClassC IntDefined in numeric-prelude-0.4.4 · Algebra.AbsoluteC IntDefined in numeric-prelude-0.4.4 · Algebra.RingC IntDefined in numeric-prelude-0.4.4 · Algebra.AdditiveC IntDefined in numeric-prelude-0.4.4 · Algebra.ToIntegerC IntDefined in numeric-prelude-0.4.4 · Algebra.ToRationalC IntDefined in numeric-prelude-0.4.4 · Algebra.PrincipalIdealDomainC IntDefined in numeric-prelude-0.4.4 · Algebra.UnitsC IntDefined in numeric-prelude-0.4.4 · Algebra.IntegralDomainC IntDefined in numeric-prelude-0.4.4 · Algebra.ZeroTestableC IntDefined in numeric-prelude-0.4.4 · Algebra.RealRingC IntDefined in numeric-prelude-0.4.4 · Algebra.RealIntegralC IntDefined in numeric-prelude-0.4.4 · Algebra.OrderDecisionC IntDefined in numeric-prelude-0.4.4 · Algebra.EqualityDecisionLift IntDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray IntDefined in array-0.5.8.0 · Data.Array.BaseC Int IntDefined in numeric-prelude-0.4.4 · Algebra.ModuleC Int IntDefined in numeric-prelude-0.4.4 · Algebra.ModuleBasisC Int IntDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.EuclideanSqr Int IntDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.EuclideanC Int IntDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.MaximumC Int IntDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.SumMArray IOUArray Int IODefined in array-0.5.8.0 · Data.Array.IO.InternalsGeneric1 (URec Int)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsFoldable UIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable UIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableMArray (STUArray s) Int (ST s)Defined in array-0.5.8.0 · Data.Array.BaseFunctor (URec Int)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsEq (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsOrd (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsShow (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsGeneric (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Genericstype Rep (URec Int p) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UInt"
'PrefixI 'True) (S1 ('MetaSel ('Just"uInt#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UInt))type Rep1 (URec Int) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UInt"
'PrefixI 'True) (S1 ('MetaSel ('Just"uInt#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UInt))data URec IntDefined in ghc-internal-9.1003.0 · GHC.Internal.GenericsUsed for marking occurrences of Int#
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 · orphanfromEnum 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.ClassesFloating FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.FloatFractional FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphanThis 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.DataNum FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphanThis 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.ClassesRead FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphanBeware 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.FloatRealFrac FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphanBeware 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 · orphanStorable FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg FloatDefined in base-4.20.2.0 · Text.PrintfNFData FloatDefined in deepseq-1.5.0.0 · Control.DeepSeqPretty FloatDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClassPretty FloatDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClassRandom FloatDefined in random-1.2.1.3 · System.RandomNote - random produces values in the closed range
[0,1].UniformRange FloatDefined in random-1.2.1.3 · System.Random.InternalArbitrary FloatDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.ArbitraryCoArbitrary FloatDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.ArbitraryFunction FloatDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionBinary FloatDefined in binary-0.8.9.3 · Data.Binary.ClassUses non-IEEE754 encoding. Does not round-trip NaN.
C FloatDefined in numeric-prelude-0.4.4 · Algebra.AbsoluteC FloatDefined in numeric-prelude-0.4.4 · Algebra.RingC FloatDefined in numeric-prelude-0.4.4 · Algebra.AdditiveC FloatDefined in numeric-prelude-0.4.4 · Algebra.AlgebraicC FloatDefined in numeric-prelude-0.4.4 · Algebra.FieldC FloatDefined in numeric-prelude-0.4.4 · Algebra.ToRationalC FloatDefined in numeric-prelude-0.4.4 · Algebra.ZeroTestableC FloatDefined in numeric-prelude-0.4.4 · Algebra.FloatingPointC FloatDefined in numeric-prelude-0.4.4 · Algebra.RealRingC FloatDefined in numeric-prelude-0.4.4 · Algebra.RealFieldC FloatDefined in numeric-prelude-0.4.4 · Algebra.OrderDecisionC FloatDefined in numeric-prelude-0.4.4 · Algebra.RealTranscendentalC FloatDefined in numeric-prelude-0.4.4 · Algebra.TranscendentalPower FloatDefined in numeric-prelude-0.4.4 · Number.ComplexC FloatDefined in numeric-prelude-0.4.4 · Algebra.EqualityDecisionZero FloatDefined in numeric-prelude-0.4.4 · Algebra.AffineSpaceLift FloatDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray FloatDefined in array-0.5.8.0 · Data.Array.BaseC Float FloatDefined in numeric-prelude-0.4.4 · Algebra.VectorSpaceC Float FloatDefined in numeric-prelude-0.4.4 · Algebra.ModuleC Float FloatDefined in numeric-prelude-0.4.4 · Algebra.ModuleBasisC Float FloatDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.EuclideanSqr Float FloatDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.EuclideanC Float FloatDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.MaximumC Float FloatDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.SumC Float FloatDefined in numeric-prelude-0.4.4 · Algebra.OccasionallyScalarC Float FloatDefined in numeric-prelude-0.4.4 · Algebra.AffineSpaceMArray IOUArray Float IODefined in array-0.5.8.0 · Data.Array.IO.InternalsGeneric1 (URec Float)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsFoldable UFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable UFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableMArray (STUArray s) Float (ST s)Defined in array-0.5.8.0 · Data.Array.BaseFunctor (URec Float)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsEq (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsOrd (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsShow (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsGeneric (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Genericstype Rep (URec Float p) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UFloat"
'PrefixI 'True) (S1 ('MetaSel ('Just"uFloat#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UFloat))type Rep1 (URec Float) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UFloat"
'PrefixI 'True) (S1 ('MetaSel ('Just"uFloat#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UFloat))data URec FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.GenericsUsed for marking occurrences of Float#
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 · orphanfromEnum 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.ClassesFloating DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.FloatFractional DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphanThis 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.DataNum DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphanThis 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.ClassesIEEE 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
NaNthen the result of the comparison is False, andinstanceOrd Double complies with this requirement. This violates the reflexivity: bothNaN<=NaNandNaN>=NaNare False.IEEE 754-2008, section 5.10 defines
totalOrderpredicate. Unfortunately, compare on Doubles violates the IEEE standard and does not define a total order. More specifically, both compareNaNxand comparexNaNalways return GT.Thus, users must be extremely cautious when using
instanceOrd 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 infp-ieeepackage asTotallyOrderednewtype.Moving further, the behaviour of min and max with regards to
NaNis also non-compliant. IEEE 754-2008, section 5.3.1 defines that quietNaNshould be treated as a missing data byminNumandmaxNumfunctions, for example,minNum(NaN, 1) = minNum(1, NaN) = 1. Some languages such as Java deviate from the standard implementingminNum(NaN, 1) = minNum(1, NaN) = NaN. However, min / max inbaseare even worse: minNaN1 is 1, but min 1NaNisNaN.IEEE 754-2008 compliant min / max can be found in
ieee754package underminNum/maxNumnames. Implementations compliant withminimumNumber/maximumNumberfrom a newer IEEE 754-2019, section 9.6 are available fromfp-ieeepackage.Read DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphanBeware 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.FloatRealFrac DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphanBeware 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 · orphanStorable DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg DoubleDefined in base-4.20.2.0 · Text.PrintfNFData DoubleDefined in deepseq-1.5.0.0 · Control.DeepSeqPretty DoubleDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClassPretty DoubleDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClassRandom DoubleDefined in random-1.2.1.3 · System.RandomNote - random produces values in the closed range
[0,1].UniformRange DoubleDefined in random-1.2.1.3 · System.Random.InternalArbitrary DoubleDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.ArbitraryCoArbitrary DoubleDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.ArbitraryFunction DoubleDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionBinary DoubleDefined in binary-0.8.9.3 · Data.Binary.ClassUses non-IEEE754 encoding. Does not round-trip NaN.
C DoubleDefined in numeric-prelude-0.4.4 · Algebra.AbsoluteC DoubleDefined in numeric-prelude-0.4.4 · Algebra.RingC DoubleDefined in numeric-prelude-0.4.4 · Algebra.AdditiveC DoubleDefined in numeric-prelude-0.4.4 · Algebra.AlgebraicC DoubleDefined in numeric-prelude-0.4.4 · Algebra.FieldC DoubleDefined in numeric-prelude-0.4.4 · Algebra.ToRationalC DoubleDefined in numeric-prelude-0.4.4 · Algebra.ZeroTestableC DoubleDefined in numeric-prelude-0.4.4 · Algebra.FloatingPointC DoubleDefined in numeric-prelude-0.4.4 · Algebra.RealRingC DoubleDefined in numeric-prelude-0.4.4 · Algebra.RealFieldC DoubleDefined in numeric-prelude-0.4.4 · Algebra.OrderDecisionC DoubleDefined in numeric-prelude-0.4.4 · Algebra.RealTranscendentalC DoubleDefined in numeric-prelude-0.4.4 · Algebra.TranscendentalPower DoubleDefined in numeric-prelude-0.4.4 · Number.ComplexC DoubleDefined in numeric-prelude-0.4.4 · Algebra.EqualityDecisionZero DoubleDefined in numeric-prelude-0.4.4 · Algebra.AffineSpaceLift DoubleDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray DoubleDefined in array-0.5.8.0 · Data.Array.BaseC Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.VectorSpaceC Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.ModuleC Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.ModuleBasisC Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.EuclideanSqr Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.EuclideanC Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.MaximumC Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.NormedSpace.SumC Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.OccasionallyScalarC Double DoubleDefined in numeric-prelude-0.4.4 · Algebra.AffineSpaceMArray IOUArray Double IODefined in array-0.5.8.0 · Data.Array.IO.InternalsGeneric1 (URec Double)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsFoldable UDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable UDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableMArray (STUArray s) Double (ST s)Defined in array-0.5.8.0 · Data.Array.BaseFunctor (URec Double)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsEq (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsOrd (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsShow (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsGeneric (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Genericstype Rep (URec Double p) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UDouble"
'PrefixI 'True) (S1 ('MetaSel ('Just"uDouble#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UDouble))type Rep1 (URec Double) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UDouble"
'PrefixI 'True) (S1 ('MetaSel ('Just"uDouble#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UDouble))data URec DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.GenericsUsed for marking occurrences of Double#
scale a vector by a scalar