eris.decimal.arithmetic

Floating-point decimal arithmetic.

An implementation of the General Decimal Arithmetic Specification.

Members

Functions

abs
D abs(D arg, Context context)

Returns the absolute value of the argument.

add
D add(D left, D right, Context context, bool setFlags)

Adds the two operands. The result may be rounded and context flags may be set. Implements the 'add' function in the specification. (p. 26) Flags: INVALID_OPERATION, OVERFLOW.

add
D add(D left, U right, Context context, bool setFlags)

Adds the two operands. The result may be rounded and context flags may be set. Implements the 'add' function in the specification. (p. 26) Flags: INVALID_OPERATION, OVERFLOW.

classify
string classify(D num)

Returns a string indicating the class and sign of the argument.

compare
int compare(D left, D right, Context context)

Compares two operands numerically to the current precision.

compareSignal
int compareSignal(D left, D right, Context context)

Compares the numeric values of two numbers. CompareSignal is identical to compare except that quiet NaNs are treated as if they were signaling. This operation may set the invalid-operation flag. Implements the 'compare-signal' function in the specification. (p. 27) Flags: INVALID_OPERATION

compareTotal
int compareTotal(D left, D right)

Takes two numbers and compares the operands using their abstract representation rather than their numerical value. Numbers (representations which are not NaNs) are ordered such that a larger numerical value is higher in the ordering. If two representations have the same numerical value then the exponent is taken into account; larger (more positive) exponents are higher in the ordering. Returns -1 If the first operand is lower in the total ordering and returns 1 if the first operand is higher in the total ordering. Returns 0 only if the numbers are equal and have the same representation. Implements the 'compare-total' function in the specification. (p. 42-43) Flags: NONE.

compareTotalMagnitude
int compareTotalMagnitude(D left, D right)

compare-total-magnitude takes two numbers and compares them using their abstract representation rather than their numerical value with their sign ignored and assumed to be 0. The result is identical to that obtained by using compare-total on two operands which are the copy-abs copies of the operands. Implements the 'compare-total-magnitude' function in the specification. (p. 43) Flags: NONE.

div
D div(D x, D y, Context context)

Divides the first operand by the second operand and returns their quotient. Division by zero sets a flag and returns infinity. The result may be rounded and context flags may be set. Implements the 'divide' function in the specification. (p. 27-29)

div
D div(D x, U n, Context context)

Divides the first operand by the second operand and returns their quotient. Division by zero sets a flag and returns infinity. The result may be rounded and context flags may be set. Implements the 'divide' function in the specification. (p. 27-29)

div
D div(D x, U z, Context context)

Divides the first operand by the second operand and returns their quotient. Division by zero sets a flag and returns infinity. The result may be rounded and context flags may be set. Implements the 'divide' function in the specification. (p. 27-29)

divideInteger
D divideInteger(D x, D y)

Divides the first operand by the second and returns the integer portion of the quotient. Division by zero sets a flag and returns infinity. The result may be rounded and context flags may be set. Implements the 'divide-integer' function in the specification. (p. 30)

equals
bool equals(D left, D right, Context context)

Returns true if the operands are equal to the type precision. Finite numbers are equal if they are numerically equal to the type precision. Infinities are equal if they have the same sign. Zeros are equal regardless of sign. A NaN is not equal to any number, not even another NaN. In particular, a decimal NaN is not equal to itself (this != this).

fma
D fma(D x, D y, D z, Context context)

Multiplies the first two operands and adds the third operand to the result. The result of the multiplication is not rounded prior to addition. The result may be rounded and context flags may be set. Implements the 'fused-multiply-add' function in the specification. (p. 30)

ilogb
int ilogb(D num)

Returns the truncated base 10 logarithm of the argument.

invalidOperand
D invalidOperand(D num)

Returns a quiet NaN and sets the invalid-operation flag. "The result of any arithmetic operation which has an operand which is a NaN (a quiet NaN or a signaling NaN) is [s,qNaN] or [s,qNaN,d]. The sign and any diagnostic information is copied from the first operand which is a signaling NaN, or if neither is signaling then from the first operand which is a NaN." -- General Decimal Arithmetic Specification, p. 24

invalidOperand
D invalidOperand(D left, D right)

Returns a quiet NaN and sets the invalid-operation flag. "The result of any arithmetic operation which has an operand which is a NaN (a quiet NaN or a signaling NaN) is [s,qNaN] or [s,qNaN,d]. The sign and any diagnostic information is copied from the first operand which is a signaling NaN, or if neither is signaling then from the first operand which is a NaN." -- General Decimal Arithmetic Specification, p. 24

invalidOperation
D invalidOperation(ushort payload)

Sets the invalid-operation flag and returns a quiet NaN.

logb
D logb(D num)

Returns the truncated base 10 logarithm of the argument.

max
D max(D left, D right, Context context)

Returns the maximum of the two operands (or NaN).

maxMagnitude
D maxMagnitude(D left, D right, Context context)

Returns the larger of the two operands (or NaN). Returns the same result as the 'max' function if the signs of the operands are ignored. Implements the 'max-magnitude' function in the specification. (p. 32) Flags: NONE.

min
D min(D left, D right, Context context)

Returns the minimum of the two operands (or NaN). If either is a signaling NaN, or both are quiet NaNs, a NaN is returned. Otherwise, Any (finite or infinite) number is smaller than a NaN. If they are not numerically equal, the smaller is returned. If they are numerically equal: 1. If the signs differ, the one with the negative sign is returned. 2. If they are negative, the one with the larger exponent is returned. 3. If they are positive, the one with the smaller exponent is returned. 4. Otherwise, they are indistinguishable; the first is returned. Implements the 'min' function in the specification. (p. 32-33) Flags: INVALID_OPERATION, ROUNDED.

minMagnitude
D minMagnitude(D left, D right, Context context)

Returns the smaller of the two operands (or NaN). Returns the same result as the 'min' function if the signs of the operands are ignored. Implements the 'min-magnitude' function in the specification. (p. 33) Flags: INVALID_OPERATION, ROUNDED.

minus
D minus(D num, Context context)

Returns a copy of the argument with the opposite sign. The result is equivalent to subtract('0', arg).

mul
D mul(D x, D y, Context context)

Multiplies the two operands. The result may be rounded and context flags may be set. Implements the 'multiply' function in the specification. (p. 33-34)

mul
D mul(D x, U n, Context context)

Multiplies a decimal number by a long integer. The result may be rounded and context flags may be set. Not a required function, but useful because it avoids an unnecessary conversion to a decimal when multiplying by an integer.

mul
D mul(D x, U y, Context context)

Multiplies the two operands. The result may be rounded and context flags may be set. Implements the 'multiply' function in the specification. (p. 33-34)

nextMinus
D nextMinus(D num, Context context)

Returns the largest representable number that is smaller than the argument.

nextPlus
D nextPlus(D num, Context context)

Returns the smallest representable number that is larger than the argument.

nextToward
D nextToward(D left, D right, Context context)

Returns the representable number that is closest to the first operand in the direction of the second operand.

normalize
D normalize(D num, Context context)
Undocumented in source. Be warned that the author may not have intended to support it.
plus
D plus(D num, Context context)

Returns a copy of the argument with the same sign as the argument. The result is equivalent to add('0', arg).

precisionEquals
bool precisionEquals(D left, D right, int precision)

Returns true if the operands are equal to the specified precision. Special values are handled as in the equals() function. This function allows comparison at precision values other than the type precision.

quantize
D quantize(D left, D right, Context context)

Returns the number which is equal in value and sign to the first operand with the exponent of the second operand. The returned value is rounded to the current precision. This operation may set the invalid-operation flag. Implements the 'quantize' function in the specification. (p. 36-37)

quantum
D quantum(D x)

Returns a number with a coefficient of 1 and the same exponent as the argument. Flags: NONE.

reduce
D reduce(D num, Context context)

Returns the operand reduced to its simplest form.

remQuo
D remQuo(D x, D y, D quo)

Divides the first operand by the second and returns the integer portion of the quotient. Division by zero sets a flag and returns infinity. The result may be rounded and context flags may be set. Implements the 'divide-integer' function in the specification. (p. 30)

remainder
D remainder(D x, D y, Context context)

Divides the first operand by the second and returns the fractional remainder. Division by zero sets a flag and returns infinity. The sign of the remainder is the same as that of the first operand. The result may be rounded and context flags may be set. Implements the 'remainder' function in the specification. (p. 37-38)

remainderNear
D remainderNear(D x, D y)

Divides the first operand by the second and returns the fractional remainder. Division by zero sets a flag and returns Infinity. The sign of the remainder is the same as that of the first operand. This function corresponds to the "remainder" function in the General Decimal Arithmetic Specification.

rotate
D rotate(D x, U y, Context context)

Rotates the first operand by the specified number of decimal digits. (Not binary digits!) Positive values of the second operand rotate the first operand left (multiplying by tens). Negative values rotate right (divide by 10s). If the number is NaN, or if the rotate value is less than -precision or greater than precision, an INVALID_OPERATION is signaled. An infinite number is returned unchanged. Implements the 'rotate' function in the specification. (p. 47-48)

rotate
D rotate(D arg, U n, Context context)

(Not binary digits!) Positive values of the second operand rotate the first operand left (multiplying by tens). Negative values rotate right (divide by 10s). If the number is NaN, or if the rotate value is less than -precision or greater than precision, an INVALID_OPERATION is signaled. An infinite number is returned unchanged. Implements the 'rotate' function in the specification. (p. 47-48)

roundToInt
D roundToInt(D num, Round mode, bool setFlags)

Returns the nearest integer value to the argument. Context flags may be set. Implements the 'round-to-integral-exact' function in the specification. (p. 39) if setFlags is false, this is the 'round-to-integral-value' function.

sameQuantum
bool sameQuantum(D left, D right)

Returns true if the numbers have the same exponent. If either operand is NaN or Infinity, returns true if and only if both operands are NaN or Infinity, respectively. Flags: NONE

scaleb
D scaleb(D left, D right)

If the first operand is infinite then that operand is returned, otherwise the result is the first operand modified by adding the value of the second operand to its exponent.

sgn
int sgn(D num)

Returns -1, 0, or 1 if the argument is negative, zero, or positive, respectively. The sign of zero is ignored: returns 0 for +0 or -0.

shift
D shift(D x, D y, Context context)

Shifts the first operand by the specified number of DECIMAL digits. (NOT BINARY digits!) Positive values of the second operand shift the first operand left (multiplying by tens). Negative values shift right (dividing by tens). If the number is NaN, or if the shift value is less than -precision or greater than precision, an INVALID_OPERATION is signaled. An infinite number is returned unchanged. Implements the 'shift' function in the specification. (p. 49)

shift
D shift(D arg, U n, Context context)

Shifts the first operand by the specified number of DECIMAL digits. (NOT BINARY digits!) Positive values of the second operand shift the first operand left (multiplying by tens). Negative values shift right (dividing by tens). If the first operand is NaN, or if the shift value is less than -precision or greater than precision, an INVALID_OPERATION is signaled. An infinite number is returned unchanged. Implements the 'shift' function in the specification. (p. 49)

sqr
D sqr(D arg, Context context)

Squares the argument and returns the result. The result may be rounded and context flags may be set.

sub
D sub(D left, U right, Context context, bool setFlags)

Subtracts the second operand from the first operand. The result may be rounded and context flags may be set. Implements the 'subtract' function in the specification. (p. 26)

sub
D sub(D x, U y, Context context, bool setFlags)

Subtracts the second operand from the first operand. The result may be rounded and context flags may be set. Implements the 'subtract' function in the specification. (p. 26)

Meta

Authors

Paul D. Anderson

Standards

Conforms to the General Decimal Arithmetic Specification, Version 1.70, (25 March 2009).

License

<a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>