Copyright | (c) Jan Bracker 2013 |
---|---|
License | BSD3 |
Maintainer | jbra@informatik.uni-kiel.de |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
A generalized version of the class hirarchy for numbers. All functions that would break a potential deep embedding are removed or generalized to support deep embeddings.
The class hierarchy for numeric types keeps as close as possible to the
Prelude
hierarchy. A great part of the default implementation and comments
are copied and adopted from Prelude
.
- class Num a => NumB a where
- type IntegerOf a
- fromIntegerB :: IntegerOf a -> a
- class (NumB a, OrdB a) => IntegralB a where
- class (NumB a, OrdB a, Fractional a) => RealFracB a where
- properFraction :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> (b, a)
- truncate :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b
- round :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b
- ceiling :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b
- floor :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b
- class (Boolean (BooleanOf a), RealFracB a, Floating a) => RealFloatB a where
- isNaN :: a -> BooleanOf a
- isInfinite :: a -> BooleanOf a
- isNegativeZero :: a -> BooleanOf a
- isIEEE :: a -> BooleanOf a
- atan2 :: a -> a -> a
- evenB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a
- oddB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a
- fromIntegralB :: (IntegerOf a ~ IntegerOf b, IntegralB a, NumB b) => a -> b
Documentation
class Num a => NumB a where Source
An extension of Num
that supplies the integer type of a
given number type and a way to create that number from the
integer.
fromIntegerB :: IntegerOf a -> a Source
Construct the number from the associated integer.
class (NumB a, OrdB a) => IntegralB a where Source
A deep embedded version of Integral
.
Integral numbers, supporting integer division.
Minimal complete definition is either quotRem
and divMod
or the other four functions. Besides that toIntegerB
always
has to be implemented.
class (NumB a, OrdB a, Fractional a) => RealFracB a where Source
Deep embedded version of RealFloat
.
Extracting components of fractions.
Minimal complete definition: properFraction
,
round
, floor
and ceiling
.
properFraction :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> (b, a) Source
The function properFraction
takes a real fractional number x
and returns a pair (n,f)
such that x = n+f
, and:
n
is an integral number with the same sign asx
; andf
is a fraction with the same type and sign asx
, and with absolute value less than1
.
The default definitions of the ceiling
, floor
, truncate
and round
functions are in terms of properFraction
.
truncate :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b Source
returns the integer nearest truncate
xx
between zero and x
round :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b Source
returns the nearest integer to round
xx
;
the even integer if x
is equidistant between two integers
ceiling :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b Source
returns the least integer not less than ceiling
xx
floor :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b Source
returns the greatest integer not greater than floor
xx
.
class (Boolean (BooleanOf a), RealFracB a, Floating a) => RealFloatB a where Source
Deep embedded version of RealFloat
.
Efficient, machine-independent access to the components of a
floating-point number.
A complete definition has to define all functions.
isNaN :: a -> BooleanOf a Source
true
if the argument is an IEEE "not-a-number" (NaN) value.
isInfinite :: a -> BooleanOf a Source
true
if the argument is an IEEE infinity or negative infinity.
isNegativeZero :: a -> BooleanOf a Source
true
if the argument is an IEEE negative zero.
isIEEE :: a -> BooleanOf a Source
true
if the argument is an IEEE floating point number.
a version of arctangent taking two real floating-point arguments.
For real floating x
and y
,
computes the angle
(from the positive x-axis) of the vector from the origin to the
point atan2
y x(x,y)
.
returns a value in the range [atan2
y x-pi
,
pi
]. It follows the Common Lisp semantics for the origin when
signed zeroes are supported.
, with atan2
y 1y
in a type
that is RealFloatB
, should return the same value as
.atan
y
evenB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a Source
Variant of even
for generalized booleans.
oddB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a Source
Variant of odd
for generalized booleans.
fromIntegralB :: (IntegerOf a ~ IntegerOf b, IntegralB a, NumB b) => a -> b Source
Variant of fromIntegral
for generalized booleans.