Safe Haskell | None |
---|---|
Language | Haskell2010 |
Numeric.Discretized
Description
Discretized floating point numbers, where the scaling factor is kept as two phantom types denoting the rational number used for scaling.
Synopsis
- newtype Discretized (u :: Nat) (l :: Nat) = Discretized {}
- discretize :: forall a u l. (Real a, KnownNat u, KnownNat l) => a -> Discretized u l
Documentation
newtype Discretized (u :: Nat) (l :: Nat) Source #
A discretized value takes a floating point number n
and produces n *
fromIntegral l / fromIntegral u
where both u
and l
are given as
TypeLits
. I.e. a scaling factor of (u l) = (1 100)
does all
calculations in subdivisions of 100.
The main use of a Discretized
value is to enable calculations with Int
while somewhat pretending to use floating point values.
Be careful with certain operations like (*)
as they will easily cause the
numbers to arbitrarily wrong. (+)
and (-)
are fine, however.
NOTE Export and import of data is in the form of floating points, which can lead to additional loss of precision if one is careless!
TODO fast Show
methods required!
TODO blaze stuff?
TODO We might want to discretize LogDomain
style values. This requires
some thought on in which direction to wrap. Maybe, we want to log-domain
Discretized values, which probably just works.
Constructors
Discretized | |
Fields |
Instances
discretize :: forall a u l. (Real a, KnownNat u, KnownNat l) => a -> Discretized u l Source #
Discretizes any Real a
into the Discretized
value. This conversion
is lossy!