text-printer-0.4: Abstract interface for text builders/printers.

Safe HaskellNone

Text.Printer.Fractional

Contents

Description

Print fractions.

Synopsis

Positional numeral systems

class PositionalSystem s whereSource

Positional numeral system.

Methods

systemName :: s -> StringSource

The name of the system (e.g. "binary", "decimal").

radixIn :: Num α => s -> αSource

The radix of the system.

isDigitIn :: s -> Char -> BoolSource

Test if a character is a digit.

isNzDigitIn :: s -> Char -> BoolSource

Test if a character is a non-zero digit.

fromDigitIn :: Num α => s -> Char -> Maybe αSource

Map digits to the corresponding numbers. Return Nothing on other inputs.

fromNzDigitIn :: Num α => s -> Char -> Maybe αSource

Map non-zero digits to the corresponding numbers. Return Nothing on other inputs.

unsafeFromDigitIn :: Num α => s -> Char -> αSource

Map digits to the corresponding numbers. No checks are performed.

intToDigitIn :: s -> Int -> CharSource

Map Int values to the corresponding digits. Inputs must be non-negative and less than the radix.

printDigitIn :: Printer p => s -> Char -> pSource

Print a digit.

printZeroIn :: Printer p => s -> pSource

class PositionalSystem s => BitSystem s whereSource

Positonal numeral system with a power of two radix.

Methods

digitBitsIn :: s -> IntSource

Numer of bits occupied by a digit.

digitMaskIn :: Num α => s -> αSource

The number that has digitBitsIn least significant bits set to ones and all the other bits set to zeroes.

lastDigitIn :: Bits α => s -> α -> IntSource

Map the last digit of a number to the corresponding Int value.

data Binary Source

The binary numeral system.

Constructors

Binary 

data Octal Source

The octal numeral system.

Constructors

Octal 

data Decimal Source

The decimal numeral system.

Constructors

Decimal 

data Hexadecimal Source

The hexadecimal numeral system.

Constructors

Hexadecimal 

data LowHex Source

The hexadecimal numeral system, using lower case digits.

Constructors

LowHex 

data UpHex Source

The hexadecimal numeral system, using upper case digits.

Constructors

UpHex 

Optionality characteristic

isOptional :: Optional -> BoolSource

True if the supplied value is Optional and false otherwise.

isRequired :: Optional -> BoolSource

True if the supplied value is Required and false otherwise.

Fraction printers

fraction'Source

Arguments

:: (PositionalSystem s, Real α, Printer p) 
=> s 
-> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> p

Numerator/denominator separator

-> Optional

Whether to print invisible denominators

-> α 
-> p 

Print a fraction, writing the numerator and the denominator in the specified positional numeral system.

fraction :: (Real α, Printer p) => α -> pSource

Print a fraction. The numerator and the denominator are written in the decimal numeral system and separated by a slash. Negative values are prefixed with a minus sign. Invisible denominators are omitted.