Boolean-0.2.4: Generalized booleans and numbers

Data.Boolean.Numbers

Description

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.

Synopsis

# Documentation

class Num a => NumB a where #

An extension of Num that supplies the integer type of a given number type and a way to create that number from the integer.

Associated Types

type IntegerOf a #

The accociated integer type of the number.

Methods

fromIntegerB :: IntegerOf a -> a #

Construct the number from the associated integer.

Instances
 # Instance detailsDefined in Data.Boolean.Numbers Associated Typestype IntegerOf Double :: Type # Methods # Instance detailsDefined in Data.Boolean.Numbers Associated Typestype IntegerOf Float :: Type # Methods # Instance detailsDefined in Data.Boolean.Numbers Associated Typestype IntegerOf Int :: Type # Methods # Instance detailsDefined in Data.Boolean.Numbers Associated Typestype IntegerOf Integer :: Type # Methods

class (NumB a, OrdB a) => IntegralB a where #

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.

Minimal complete definition

toIntegerB

Methods

quot :: a -> a -> a #

Integer division truncated towards zero.

rem :: a -> a -> a #

Integer reminder, satisfying: (x quot y) * y + (x rem y) == x

div :: a -> a -> a #

Integer division truncated toward negative infinity.

mod :: a -> a -> a #

Integer modulus, satisfying: (x div y) * y + (x mod y) == x

quotRem :: a -> a -> (a, a) #

Simultaneous quot and rem.

divMod :: a -> a -> (a, a) #

Simultaneous div and mod.

toIntegerB :: a -> IntegerOf a #

Create a integer from this integral.

Instances
 # Instance detailsDefined in Data.Boolean.Numbers Methodsquot :: Int -> Int -> Int #rem :: Int -> Int -> Int #div :: Int -> Int -> Int #mod :: Int -> Int -> Int #quotRem :: Int -> Int -> (Int, Int) #divMod :: Int -> Int -> (Int, Int) # # Instance detailsDefined in Data.Boolean.Numbers MethodsquotRem :: Integer -> Integer -> (Integer, Integer) #divMod :: Integer -> Integer -> (Integer, Integer) #

class (NumB a, OrdB a, Fractional a) => RealFracB a where #

Deep embedded version of RealFloat. Extracting components of fractions.

Minimal complete definition: properFraction, RealFracB, RealFracB and RealFracB.

Minimal complete definition

Methods

properFraction :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> (b, a) #

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 as x; and
• f is a fraction with the same type and sign as x, and with absolute value less than 1.

The default definitions of the RealFracB, RealFracB, RealFracB and RealFracB functions are in terms of properFraction.

truncate :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b #

RealFracB x returns the integer nearest x between zero and x

round :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b #

RealFracB x returns the nearest integer to x; the even integer if x is equidistant between two integers

ceiling :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b #

RealFracB x returns the least integer not less than x

floor :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b #

RealFracB x returns the greatest integer not greater than x.

Instances
 # Instance detailsDefined in Data.Boolean.Numbers MethodsproperFraction :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> (b, Double) #truncate :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> b #round :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> b #ceiling :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> b #floor :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> b # # Instance detailsDefined in Data.Boolean.Numbers MethodsproperFraction :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> (b, Float) #truncate :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> b #round :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> b #ceiling :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> b #floor :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> b #

class (Boolean (BooleanOf a), RealFracB a, Floating a) => RealFloatB a where #

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.

Methods

isNaN :: a -> BooleanOf a #

true if the argument is an IEEE "not-a-number" (NaN) value.

isInfinite :: a -> BooleanOf a #

true if the argument is an IEEE infinity or negative infinity.

isNegativeZero :: a -> BooleanOf a #

true if the argument is an IEEE negative zero.

isIEEE :: a -> BooleanOf a #

true if the argument is an IEEE floating point number.

atan2 :: a -> a -> a #

a version of arctangent taking two real floating-point arguments. For real floating x and y, RealFloatB y x computes the angle (from the positive x-axis) of the vector from the origin to the point (x,y). RealFloatB y x returns a value in the range [-pi, pi]. It follows the Common Lisp semantics for the origin when signed zeroes are supported. RealFloatB y 1, with y in a type that is RealFloatB, should return the same value as atan y.

Instances
 # Instance detailsDefined in Data.Boolean.Numbers Methodsatan2 :: Double -> Double -> Double # # Instance detailsDefined in Data.Boolean.Numbers Methodsatan2 :: Float -> Float -> Float #

evenB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a #

Variant of even for generalized booleans.

oddB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a #

Variant of odd for generalized booleans.

fromIntegralB :: (IntegerOf a ~ IntegerOf b, IntegralB a, NumB b) => a -> b #

Variant of fromIntegral for generalized booleans.