percent-format-0.0.4: simple printf-style string formatting
Copyright(c) 2018 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Text.PercentFormat.Quotient

Description

The Quotient datatype. Similar to Rational but allows Infinity and NaN.

Synopsis

Documentation

data Quotient Source #

Our own Ratio type that allows Infinity and NaN

Instances

Instances details
Num Quotient Source # 
Instance details

Defined in Text.PercentFormat.Quotient

Fractional Quotient Source # 
Instance details

Defined in Text.PercentFormat.Quotient

Real Quotient Source # 
Instance details

Defined in Text.PercentFormat.Quotient

RealFrac Quotient Source # 
Instance details

Defined in Text.PercentFormat.Quotient

Methods

properFraction :: Integral b => Quotient -> (b, Quotient) #

truncate :: Integral b => Quotient -> b #

round :: Integral b => Quotient -> b #

ceiling :: Integral b => Quotient -> b #

floor :: Integral b => Quotient -> b #

Show Quotient Source # 
Instance details

Defined in Text.PercentFormat.Quotient

Eq Quotient Source #

Eq instance for Quotient. Follows the identity property except for NaN which is different from itself (this is consistent with Float & Double behaviour).

Instance details

Defined in Text.PercentFormat.Quotient

Ord Quotient Source #

Ord instance for Quotient. Follows the regular order properties except for NaN. When NaN is present in any of the operands of compare, GT is returned (consistent with Float & Double).

Instance details

Defined in Text.PercentFormat.Quotient

(%) :: Integer -> Integer -> Quotient infixl 7 Source #

Smart-constructor for Quotients

nan :: Quotient Source #

Not a number (0 / 0).

isInfinite :: Quotient -> Bool Source #

Returns whether a given quotient is an infinity (+/-).

isNaN :: Quotient -> Bool Source #

Returns if the quotient is not a number.

digits :: Int -> Quotient -> Either String ([Int], [Int], [Int]) Source #

Given a quotient (rational number), returns a tuple with its integer part, its fractional digits and the period size (last fractional digits). The signal is ignored.

> digits 10 (1234567 / 100)
Right ([1,2,3,4,5],[6,7],[])
> digits 10 (1/3)
Right ([0],[3],1)
> digits 10 (1/6)
Right ([0],[1,6],1)
> digits 10 (1/7)
Right ([0],[1,4,2,8,5,7],6)
> digits 10 (1/11)
Right ([0],[0,9],2)
digits 10 (1/12)
Right ([0],[0,8,3],1)
> digits 10 (1/13)
Right ([0],[0,7,6,9,2,3],6)
> digits 10 123
Right ([1,2,3],[],[])
> digits 10 (-4/3)
Right ([1],[],[3])
> digits 10 (-1/3)
Right ([0],[],[3])

fracDigits :: Int -> Quotient -> ([Int], [Int]) Source #

Givent a base, returns the fractional digits of a Quotient (including a period if present).

> fracDigits 10 (123 / 100)
([2,3],[])
> fracDigits 10 (12345 / 100)
([4,5],[])
> fracDigits 10 (12345 / 10)
([5],[])
> fracDigits 10 (100 / 10)
([],[])
> fracDigits 10 (1 / 3)
([],[3])
> fracDigits 10 (1 / 7)
([],[1,4,2,8,5,7])