decimal-arithmetic-0.5.0.0: An implementation of the General Decimal Arithmetic Specification

Safe HaskellTrustworthy
LanguageHaskell2010

Numeric.Decimal.Encoding

Contents

Description

This module implements the decimal interchange format encodings described in IEEE 754-2008, including the decimal32, decimal64, and decimal128 formats, as well as arbitrary width decimal{k} formats through the use of Format with KPlus32 and/or KTimes2. For example, to use a decimal96 format:

type Decimal96 = ExtendedDecimal (Format (KPlus32 K64) DecimalCoefficient)

Currently only a decimal encoding of coefficients is implemented, but a binary encoding may be added in the future.

Synopsis

Primary convenience types

type Decimal32 = ExtendedDecimal Pdecimal32 Source #

A decimal floating point number with 7 digits of precision, rounding half even, and a 32-bit encoded representation using the decimal32 interchange format (with a decimal encoding for the coefficient)

type Decimal64 = ExtendedDecimal Pdecimal64 Source #

A decimal floating point number with 16 digits of precision, rounding half even, and a 64-bit encoded representation using the decimal64 interchange format (with a decimal encoding for the coefficient)

type Decimal128 = ExtendedDecimal Pdecimal128 Source #

A decimal floating point number with 34 digits of precision, rounding half even, and a 128-bit encoded representation using the decimal128 interchange format (with a decimal encoding for the coefficient)

Precision types

type Pdecimal32 = Format K32 DecimalCoefficient Source #

A type with Precision instance specifying decimal32 interchange format parameters (using a decimal encoding for the coefficient) having an effective precision of 7 decimal digits

type Pdecimal64 = Format K64 DecimalCoefficient Source #

A type with Precision instance specifying decimal64 interchange format parameters (using a decimal encoding for the coefficient) having an effective precision of 16 decimal digits

type Pdecimal128 = Format K128 DecimalCoefficient Source #

A type with Precision instance specifying decimal128 interchange format parameters (using a decimal encoding for the coefficient) having an effective precision of 34 decimal digits

Interchange format types

data Format k c Source #

A type (with a Precision instance) for specifying interchange format parameters k and coefficient encoding c

Instances

Parameters k => Binary (Decimal (Format k DecimalCoefficient) r) Source #

A Binary instance is defined for interchange formats for which a Parameters instance exists, and covers particularly the Decimal32, Decimal64, and Decimal128 types.

Parameters k => FinitePrecision (Format k c) Source # 
Parameters k => Precision (Format k c) Source #

This Precision instance automatically computes the precision and Emax of decimal numbers that use this format.

Methods

precision :: Format k c -> Maybe Int

eMax :: Format k c -> Maybe Exponent

eMin :: Format k c -> Maybe Exponent

Format parameters

class Parameters k Source #

Interchange format parameters used to define an encoding and derive the format's precision and Emax

Minimal complete definition

paramK32

Instances

data K32 Source #

Parameters for the decimal32 interchange format

Instances

type K64 = KPlus32 K32 Source #

Parameters for the decimal64 interchange format

type K128 = KTimes2 K64 Source #

Parameters for the decimal128 interchange format

data KPlus32 k Source #

Parameters for a decimal{k + 32} interchange format

Instances

data KTimes2 k Source #

Parameters for a decimal{k × 2} interchange format

Instances

Coefficient encodings

data DecimalCoefficient Source #

Specify a decimal encoding for the coefficient.

Instances

Parameters k => Binary (Decimal (Format k DecimalCoefficient) r) Source #

A Binary instance is defined for interchange formats for which a Parameters instance exists, and covers particularly the Decimal32, Decimal64, and Decimal128 types.

data BinaryCoefficient Source #

Specify a binary encoding for the coefficient (currently unimplemented).