# FloatΒΆ

Float implements arbitrary precision floating point arithmetic. The number of significant digits of each operation can be set to an arbitrary value (the default is 20 decimal digits). The operation float(mantissa, exponent, base) for integer `mantissa`, `exponent` specifies the number `mantissa` * base ^ `exponent` The underlying representation for floats is binary not decimal. The implications of this are described below. The model adopted is that arithmetic operations are rounded to to nearest unit in the last place, that is, accurate to within 2^(-bits). Also, the elementary functions and constants are accurate to one unit in the last place. A float is represented as a record of two integers, the mantissa and the exponent. The base of the representation is binary, hence a `Record(m: mantissa, e: exponent)` represents the number `m * 2 ^ e`. Though it is not assumed that the underlying integers are represented with a binary base, the code will be most efficient when this is the the case (this is `true` in most implementations of Lisp). The decision to choose the base to be binary has some unfortunate consequences. First, decimal numbers like 0.3 cannot be represented exactly. Second, there is a further loss of accuracy during conversion to decimal for output. To compensate for this, if `d` digits of precision are specified, `1 + ceiling(log2(10^d))` bits are used. Two numbers that are displayed identically may therefore be not equal. On the other hand, a significant efficiency loss would be incurred if we chose to use a decimal base when the underlying integer base is binary. Algorithms used: For the elementary functions, the general approach is to apply identities so that the taylor series can be used, and, so that it will converge within `O( sqrt n )` steps. For example, using the identity `exp(x) = exp(x/2)^2`, we can compute `exp(1/3)` to `n` digits of precision as follows. We have `exp(1/3) = exp(2 ^ (-sqrt s) / 3) ^ (2 ^ sqrt s)`. The taylor series will converge in less than sqrt `n` steps and the exponentiation requires sqrt `n` multiplications for a total of `2 sqrt n` multiplications. Assuming integer multiplication costs `O( n^2 )` the overall running time is `O( sqrt(n) n^2 )`. This approach is the best known approach for precisions up to about 10, 000 digits at which point the methods of Brent which are `O( log(n) n^2 )` become competitive. Note also that summing the terms of the taylor series for the elementary functions is done using integer operations. This avoids the overhead of floating point operations and results in efficient code at low precisions. This implementation makes no attempt to reuse storage, relying on the underlying system to do spadgloss{garbage collection}. `I` estimate that the efficiency of this package at low precisions could be improved by a factor of 2 if in-place operations were available. Running times: in the following, `n` is the number of bits of precision `*`, `/`, `sqrt`, `pi`, `exp1`, `log2`, `log10`: `` O( n^2 )`` `exp`, `log`, `sin`, `atan`: `` O( sqrt(n) n^2 )`` The other elementary functions are coded in terms of the ones above.

0: %

from AbelianMonoid

1: %

from MagmaWithUnit

*: (%, %) -> %

from LeftModule %

*: (%, Fraction Integer) -> %
*: (Fraction Integer, %) -> %
*: (Integer, %) -> %

from AbelianGroup

*: (NonNegativeInteger, %) -> %

from AbelianMonoid

*: (PositiveInteger, %) -> %

from AbelianSemiGroup

+: (%, %) -> %

from AbelianSemiGroup

-: % -> %

from AbelianGroup

-: (%, %) -> %

from AbelianGroup

/: (%, %) -> %

from Field

/: (%, Integer) -> %
<=: (%, %) -> Boolean

from PartialOrder

<: (%, %) -> Boolean

from PartialOrder

=: (%, %) -> Boolean

from BasicType

>=: (%, %) -> Boolean

from PartialOrder

>: (%, %) -> Boolean

from PartialOrder

^: (%, %) -> %
^: (%, Fraction Integer) -> %

^: (%, Integer) -> %

from DivisionRing

^: (%, NonNegativeInteger) -> %

from MagmaWithUnit

^: (%, PositiveInteger) -> %

from Magma

~=: (%, %) -> Boolean

from BasicType

abs: % -> %

from OrderedRing

acos: % -> %
acosh: % -> %
acot: % -> %
acoth: % -> %
acsc: % -> %
acsch: % -> %
annihilate?: (%, %) -> Boolean

from Rng

antiCommutator: (%, %) -> %
asec: % -> %
asech: % -> %
asin: % -> %
asinh: % -> %
associates?: (%, %) -> Boolean

from EntireRing

associator: (%, %, %) -> %
atan: % -> %
atan: (%, %) -> %

`atan(x, y)` computes the arc tangent from `x` with phase `y`.

atanh: % -> %
base: () -> PositiveInteger
bits: () -> PositiveInteger
bits: PositiveInteger -> PositiveInteger
ceiling: % -> %

from RealNumberSystem

characteristic: () -> NonNegativeInteger
coerce: % -> %

from Algebra %

coerce: % -> DoubleFloat
coerce: % -> OutputForm
coerce: Fraction Integer -> %
coerce: Integer -> %
commutator: (%, %) -> %
convert: % -> DoubleFloat
convert: % -> Float
convert: % -> InputForm
convert: % -> Pattern Float
convert: % -> String
convert: DoubleFloat -> %

`convert(x)` converts a DoubleFloat `x` to a Float.

cos: % -> %
cosh: % -> %
cot: % -> %
coth: % -> %
csc: % -> %
csch: % -> %
D: % -> %

from DifferentialRing

D: (%, NonNegativeInteger) -> %

from DifferentialRing

decreasePrecision: Integer -> PositiveInteger
differentiate: % -> %

from DifferentialRing

differentiate: (%, NonNegativeInteger) -> %

from DifferentialRing

digits: () -> PositiveInteger
digits: PositiveInteger -> PositiveInteger
divide: (%, %) -> Record(quotient: %, remainder: %)

from EuclideanDomain

euclideanSize: % -> NonNegativeInteger

from EuclideanDomain

exp1: () -> %

`exp1()` returns exp 1: `2.7182818284...`.

exp: % -> %
exponent: % -> Integer
expressIdealMember: (List %, %) -> Union(List %, failed)
exquo: (%, %) -> Union(%, failed)

from EntireRing

extendedEuclidean: (%, %) -> Record(coef1: %, coef2: %, generator: %)

from EuclideanDomain

extendedEuclidean: (%, %, %) -> Union(Record(coef1: %, coef2: %), failed)

from EuclideanDomain

factor: % -> Factored %
float: (Integer, Integer) -> %
float: (Integer, Integer, PositiveInteger) -> %
floor: % -> %

from RealNumberSystem

fractionPart: % -> %

from RealNumberSystem

gcd: (%, %) -> %

from GcdDomain

gcd: List % -> %

from GcdDomain

gcdPolynomial: (SparseUnivariatePolynomial %, SparseUnivariatePolynomial %) -> SparseUnivariatePolynomial %

from GcdDomain

hash: % -> SingleInteger

from Hashable

hashUpdate!: (HashState, %) -> HashState

from Hashable

increasePrecision: Integer -> PositiveInteger
inv: % -> %

from DivisionRing

latex: % -> String

from SetCategory

lcm: (%, %) -> %

from GcdDomain

lcm: List % -> %

from GcdDomain

lcmCoef: (%, %) -> Record(llcm_res: %, coeff1: %, coeff2: %)

from LeftOreRing

leftPower: (%, NonNegativeInteger) -> %

from MagmaWithUnit

leftPower: (%, PositiveInteger) -> %

from Magma

leftRecip: % -> Union(%, failed)

from MagmaWithUnit

log10: % -> %

`log10(x)` computes the logarithm for `x` to base 10.

log10: () -> %

`log10()` returns `ln 10`: `2.3025809299...`.

log2: % -> %

`log2(x)` computes the logarithm for `x` to base 2.

log2: () -> %

`log2()` returns `ln 2`, i.e. `0.6931471805...`.

log: % -> %
mantissa: % -> Integer
max: (%, %) -> %

from OrderedSet

max: () -> % if
min: (%, %) -> %

from OrderedSet

min: () -> % if
multiEuclidean: (List %, %) -> Union(List %, failed)

from EuclideanDomain

negative?: % -> Boolean

from OrderedRing

norm: % -> %

from RealNumberSystem

normalize: % -> %

`normalize(x)` normalizes `x` at current precision.

nthRoot: (%, Integer) -> %

OMwrite: % -> String

from OpenMath

OMwrite: (%, Boolean) -> String

from OpenMath

OMwrite: (OpenMathDevice, %) -> Void

from OpenMath

OMwrite: (OpenMathDevice, %, Boolean) -> Void

from OpenMath

one?: % -> Boolean

from MagmaWithUnit

opposite?: (%, %) -> Boolean

from AbelianMonoid

order: % -> Integer
outputFixed: () -> Void

`outputFixed()` sets the output mode to fixed point notation; the output will contain a decimal point.

outputFixed: NonNegativeInteger -> Void

`outputFixed(n)` sets the output mode to fixed point notation, with `n` digits displayed after the decimal point.

outputFloating: () -> Void

`outputFloating()` sets the output mode to floating (scientific) notation, i.e. `mantissa * 10 exponent` is displayed as `0.mantissa E exponent`.

outputFloating: NonNegativeInteger -> Void

`outputFloating(n)` sets the output mode to floating (scientific) notation with `n` significant digits displayed after the decimal point.

outputGeneral: () -> Void

`outputGeneral()` sets the output mode (default mode) to general notation; numbers will be displayed in either fixed or floating (scientific) notation depending on the magnitude.

outputGeneral: NonNegativeInteger -> Void

`outputGeneral(n)` sets the output mode to general notation with `n` significant digits displayed.

outputSpacing: NonNegativeInteger -> Void

`outputSpacing(n)` inserts a space after `n` (default 10) digits on output; outputSpacing(0) means no spaces are inserted.

patternMatch: (%, Pattern Float, PatternMatchResult(Float, %)) -> PatternMatchResult(Float, %)
pi: () -> %
plenaryPower: (%, PositiveInteger) -> %
positive?: % -> Boolean

from OrderedRing

precision: () -> PositiveInteger
precision: PositiveInteger -> PositiveInteger
prime?: % -> Boolean
principalIdeal: List % -> Record(coef: List %, generator: %)
quo: (%, %) -> %

from EuclideanDomain

rationalApproximation: (%, NonNegativeInteger) -> Fraction Integer

`rationalApproximation(f, n)` computes a rational approximation `r` to `f` with relative error `< 10^(-n)`.

rationalApproximation: (%, NonNegativeInteger, NonNegativeInteger) -> Fraction Integer

`rationalApproximation(f, n, b)` computes a rational approximation `r` to `f` with relative error `< b^(-n)`, that is `|(r-f)/f| < b^(-n)`.

recip: % -> Union(%, failed)

from MagmaWithUnit

relerror: (%, %) -> %

`relerror(x, y)` computes the absolute value of `(x - y)/y`, when `y \~= 0`.

rem: (%, %) -> %

from EuclideanDomain

retract: % -> Fraction Integer
retract: % -> Integer
retractIfCan: % -> Union(Fraction Integer, failed)
retractIfCan: % -> Union(Integer, failed)
rightPower: (%, NonNegativeInteger) -> %

from MagmaWithUnit

rightPower: (%, PositiveInteger) -> %

from Magma

rightRecip: % -> Union(%, failed)

from MagmaWithUnit

round: % -> %

from RealNumberSystem

sample: %

from AbelianMonoid

sec: % -> %
sech: % -> %
shift: (%, Integer) -> %

`shift(x, n)` adds `n` to the exponent of float `x`.

sign: % -> Integer

from OrderedRing

sin: % -> %
sinh: % -> %
sizeLess?: (%, %) -> Boolean

from EuclideanDomain

smaller?: (%, %) -> Boolean

from Comparable

sqrt: % -> %

squareFree: % -> Factored %
squareFreePart: % -> %
subtractIfCan: (%, %) -> Union(%, failed)
tan: % -> %
tanh: % -> %
toString: % -> String
toString: (%, NonNegativeInteger) -> String
truncate: % -> %

from RealNumberSystem

unit?: % -> Boolean

from EntireRing

unitCanonical: % -> %

from EntireRing

unitNormal: % -> Record(unit: %, canonical: %, associate: %)

from EntireRing

wholePart: % -> Integer

from RealNumberSystem

zero?: % -> Boolean

from AbelianMonoid

AbelianGroup

AbelianMonoid

AbelianSemiGroup

Approximate

arbitraryExponent

arbitraryPrecision

ArcHyperbolicFunctionCategory

ArcTrigonometricFunctionCategory

BasicType

BiModule(%, %)

CancellationAbelianMonoid

canonicalsClosed

canonicalUnitNormal

CharacteristicZero

CommutativeRing

CommutativeStar

Comparable

DifferentialRing

DivisionRing

ElementaryFunctionCategory

EntireRing

EuclideanDomain

Field

FloatingPointSystem

GcdDomain

Hashable

HyperbolicFunctionCategory

IntegralDomain

LeftOreRing

Magma

MagmaWithUnit

Monoid

NonAssociativeRing

NonAssociativeRng

NonAssociativeSemiRing

NonAssociativeSemiRng

noZeroDivisors

OpenMath

OrderedAbelianGroup

OrderedAbelianMonoid

OrderedAbelianSemiGroup

OrderedCancellationAbelianMonoid

OrderedRing

OrderedSet

PartialOrder

PrincipalIdealDomain

RealConstant

RealNumberSystem

Ring

Rng

SemiGroup

SemiRing

SemiRng

SetCategory

TranscendentalFunctionCategory

TrigonometricFunctionCategory

TwoSidedRecip

UniqueFactorizationDomain

unitsKnown