PeterO.Numbers.EDecimals

## PeterO.Numbers.EDecimals

public static class EDecimals

A class that implements additional operations on arbitrary-precision decimal numbers. Many of them are listed as miscellaneous operations in the General Decimal Arithmetic Specification version 1.70.

Member Summary

### And

public static PeterO.Numbers.EDecimal And(
    PeterO.Numbers.EDecimal ed1,
    PeterO.Numbers.EDecimal ed2,
    PeterO.Numbers.EContext ec);

Performs a logical AND operation on two decimal numbers in the form of logical operands. A logical operand is a non-negative base-10 number with an Exponent property of 0 and no other base-10 digits than 0 or 1 (examples include 01001 and 111001 , but not 02001 or 99999 ). The logical AND operation sets each digit of the result to 1 if the corresponding digits of each logical operand are both 1, and to 0 otherwise. For example, 01001 AND 111010=01000 .

Parameters:

Return Value:

The result of the logical AND operation as a logical operand. Signals an invalid operation and returns not-a-number (NaN) if ed1 , ed2 , or both are not logical operands.

### BooleanToEDecimal

public static PeterO.Numbers.EDecimal BooleanToEDecimal(
    bool b,
    PeterO.Numbers.EContext ec);

Converts a boolean value (either true or false) to an arbitrary-precision decimal number.

Parameters:

Return Value:

Either 1 if b is true, or 0 if b is false.. The result will be rounded as specified by the given context, if any.

### Canonical

public static PeterO.Numbers.EDecimal Canonical(
    PeterO.Numbers.EDecimal ed);

Returns a canonical version of the given arbitrary-precision number object. In this method, this method behaves like the Copy method.

Parameters:

Return Value:

A copy of the parameter ed .

### CompareTotal

public static int CompareTotal(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EDecimal other,
    PeterO.Numbers.EContext ec);

Compares the values of one arbitrary-precision number object and another object, imposing a total ordering on all possible values. In this method:

Parameters:

Return Value:

The number 0 if both objects are null or equal, or -1 if the first object is null or less than the other object, or 1 if the first object is greater or the other object is null. Does not signal flags if either value is signaling NaN.

### CompareTotalMagnitude

public static int CompareTotalMagnitude(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EDecimal other,
    PeterO.Numbers.EContext ec);

Compares the absolute values of two arbitrary-precision number objects, imposing a total ordering on all possible values (ignoring their signs). In this method:

Parameters:

Return Value:

The number 0 if both objects are null or equal (ignoring their signs), or -1 if the first object is null or less than the other value (ignoring their signs), or 1 if the first object is greater (ignoring their signs) or the other object is null. Does not signal flags if either value is signaling NaN.

### Copy

public static PeterO.Numbers.EDecimal Copy(
    PeterO.Numbers.EDecimal ed);

Creates a copy of the given arbitrary-precision number object.

Parameters:

Return Value:

A copy of the given arbitrary-precision number object.

Exceptions:

### CopyAbs

public static PeterO.Numbers.EDecimal CopyAbs(
    PeterO.Numbers.EDecimal ed);

Returns an arbitrary-precision number object with the same value as the given number object but with a nonnegative sign (that is, the given number object’s absolute value).

Parameters:

Return Value:

An arbitrary-precision number object with the same value as the given number object but with a nonnegative sign.

Exceptions:

### CopyNegate

public static PeterO.Numbers.EDecimal CopyNegate(
    PeterO.Numbers.EDecimal ed);

Returns an arbitrary-precision number object with the sign reversed from the given number object.

Parameters:

Return Value:

An arbitrary-precision number object with the sign reversed from the given number object.

Exceptions:

### CopySign

public static PeterO.Numbers.EDecimal CopySign(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EDecimal other);

Returns an arbitrary-precision number object with the same value as the first given number object but with a the same sign (positive or negative) as the second given number object.

Parameters:

Return Value:

An arbitrary-precision number object with the same value as the first given number object but with a the same sign (positive or negative) as the second given number object.

Exceptions:

### Int32ToEDecimal

public static PeterO.Numbers.EDecimal Int32ToEDecimal(
    int i32,
    PeterO.Numbers.EContext ec);

Creates an arbitrary-precision decimal number from a 32-bit signed integer.

Parameters:

Return Value:

An arbitrary-precision decimal number with the closest representable value to the given integer.

### Invert

public static PeterO.Numbers.EDecimal Invert(
    PeterO.Numbers.EDecimal ed1,
    PeterO.Numbers.EContext ec);

Performs a logical NOT operation on an arbitrary-precision decimal number in the form of a logical operand. A logical operand is a non-negative base-10 number with an Exponent property of 0 and no other base-10 digits than 0 or 1 (examples include 01001 and 111001 , but not 02001 or 99999 ). The logical NOT operation sets each digit of the result to 1 if the corresponding digit is 0, and to 0 otherwise; it can set no more digits than the maximum precision, however. For example, if the maximum precision is 8 digits, then NOT 111010=11000101 .

Parameters:

Return Value:

The result of the logical NOT operation as a logical operand. Signals an invalid operation and returns not-a-number (NaN) if ed1 is not a logical operand.

### IsCanonical

public static bool IsCanonical(
    PeterO.Numbers.EDecimal ed);

Returns whether the given arbitrary-precision number object is in a canonical form. For the current version of EDecimal, all EDecimal objects are in a canonical form.

Parameters:

Return Value:

Always true .

### IsFinite

public static bool IsFinite(
    PeterO.Numbers.EDecimal ed);

Returns whether the given arbitrary-precision number object is neither null nor infinity nor not-a-number (NaN).

Parameters:

Return Value:

Either true if the given arbitrary-precision number object is neither null nor infinity nor not-a-number (NaN), or false otherwise.

### IsInfinite

public static bool IsInfinite(
    PeterO.Numbers.EDecimal ed);

Returns whether the given arbitrary-precision number object is positive or negative infinity.

Parameters:

Return Value:

Either true if the given arbitrary-precision number object is positive or negative infinity, or false otherwise.

### IsNaN

public static bool IsNaN(
    PeterO.Numbers.EDecimal ed);

Returns whether the given arbitrary-precision number object is a not-a-number (NaN).

Parameters:

Return Value:

Either true or false .

### IsNormal

public static bool IsNormal(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EContext ec);

Returns whether the given number is a normal number. A subnormal number is a nonzero finite number whose Exponent property (or the number’s exponent when that number is expressed in scientific notation with one digit before the radix point) is less than the minimum possible exponent for that number. A normal number is nonzero and finite, but not subnormal.

Parameters:

Return Value:

Either true if the given number is subnormal, or false otherwise. Returns true if the given context is null or HasExponentRange of the given context is false .

### IsQuietNaN

public static bool IsQuietNaN(
    PeterO.Numbers.EDecimal ed);

Returns whether the given arbitrary-precision number object is a quiet not-a-number (NaN).

Parameters:

Return Value:

Either true or false .

### IsSignalingNaN

public static bool IsSignalingNaN(
    PeterO.Numbers.EDecimal ed);

Returns whether the given arbitrary-precision number object is a signaling not-a-number (NaN).

Parameters:

Return Value:

Either true or false .

### IsSigned

public static bool IsSigned(
    PeterO.Numbers.EDecimal ed);

Returns whether the given arbitrary-precision number object is negative (including negative infinity, negative not-a-number [NaN], or negative zero).

Parameters:

Return Value:

Either true or false .

### IsSubnormal

public static bool IsSubnormal(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EContext ec);

Returns whether the given number is a subnormal number. A subnormal number is a nonzero finite number whose Exponent property (or the number’s exponent when that number is expressed in scientific notation with one digit before the radix point) is less than the minimum possible exponent for that number.

Parameters:

Return Value:

Either true if the given number is subnormal, or false otherwise. Returns false if the given context is null or HasExponentRange of the given context is false .

Exceptions:

### IsZero

public static bool IsZero(
    PeterO.Numbers.EDecimal ed);

Returns whether the given arbitrary-precision number object is zero (positive zero or negative zero).

Parameters:

Return Value:

true if the given number has a value of zero (positive zero or negative zero); otherwise, false .

### LogB

public static PeterO.Numbers.EDecimal LogB(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EContext ec);

Returns the base-10 exponent of an arbitrary-precision decimal number (when that number is expressed in scientific notation with one digit before the radix point). For example, returns 3 for the numbers 6.66E + 3 and 666E + 1 .

Parameters:

Return Value:

The base-10 exponent of the given number (when that number is expressed in scientific notation with one nonzero digit before the radix point). Signals DivideByZero and returns negative infinity if ed is zero. Returns positive infinity if ed is positive infinity or negative infinity.

Exceptions:

### NumberClass

public static int NumberClass(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EContext ec);

Finds the number class for an arbitrary-precision decimal number object.

Parameters:

Return Value:

A 32-bit signed integer identifying the given number object, number class as follows: 0 = positive normal; 1 = negative normal, 2 = positive subnormal, 3 = negative subnormal, 4 = positive zero, 5 = negative zero, 6 = positive infinity, 7 = negative infinity, 8 = quiet not-a-number (NaN), 9 = signaling NaN.

Exceptions:

### NumberClassString

public static string NumberClassString(
    int nc);

Converts a number class identifier (ranging from 0 through 9) to a text string. An arbitrary-precision number object can belong in one of ten number classes.

Parameters:

Return Value:

A text string identifying the given number class as follows: 0 = “+Normal”; 1 = “-Normal”, 2 = “+Subnormal”, 3 = “-Subnormal”, 4 = “+Zero”, 5 = “-Zero”, 6 = “+Infinity”, 7 = “-Infinity”, 8 = “NaN”, 9 = “sNaN”.

Exceptions:

### Or

public static PeterO.Numbers.EDecimal Or(
    PeterO.Numbers.EDecimal ed1,
    PeterO.Numbers.EDecimal ed2,
    PeterO.Numbers.EContext ec);

Performs a logical OR operation on two decimal numbers in the form of logical operands. A logical operand is a non-negative base-10 number with an Exponent property of 0 and no other base-10 digits than 0 or 1 (examples include 01001 and 111001 , but not 02001 or 99999 ). The logical OR operation sets each digit of the result to 1 if either or both of the corresponding digits of the logical operands are 1, and to 0 otherwise. For example, 01001 OR 111010=111011 .

Parameters:

Return Value:

The result of the logical OR operation as a logical operand. Signals an invalid operation and returns not-a-number (NaN) if ed1 , ed2 , or both are not logical operands.

### Radix

public static PeterO.Numbers.EDecimal Radix(
    PeterO.Numbers.EContext ec);

Returns the number 10, the decimal radix.

Parameters:

Return Value:

The number 10, or the closest representable number to 10 in the arithmetic context.

### Rescale

public static PeterO.Numbers.EDecimal Rescale(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EDecimal scale,
    PeterO.Numbers.EContext ec);

Returns an arbitrary-precision decimal number with the same value as this object but with the given exponent, expressed as an arbitrary-precision decimal number. Note that this is not always the same as rounding to a given number of decimal places, since it can fail if the difference between this value’s exponent and the desired exponent is too big, depending on the maximum precision. If rounding to a number of decimal places is desired, it’s better to use the RoundToExponent and RoundToIntegral methods instead.

Remark: This method can be used to implement fixed-point decimal arithmetic, in which a fixed number of digits come after the decimal point. A fixed-point decimal arithmetic in which no digits come after the decimal point (a desired exponent of 0) is considered an “integer arithmetic” .

Parameters:

Return Value:

An arbitrary-precision decimal number with the same value as this object but with the exponent changed. Signals FlagInvalid and returns not-a-number (NaN) if the result can’t fit the given precision without rounding, or if the arithmetic context defines an exponent range and the given exponent is outside that range.

### Rotate

public static PeterO.Numbers.EDecimal Rotate(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EDecimal ed2,
    PeterO.Numbers.EContext ec);

Rotates the digits of an arbitrary-precision decimal number’s significand.

Parameters:

Return Value:

An arbitrary-precision decimal number whose significand is rotated the given number of digits. Signals an invalid operation and returns NaN (not-a-number) if ed2 is a signaling NaN or if ed2 is not an integer, is negative, has an exponent other than 0, or has an absolute value that exceeds the maximum precision specified in the context.

Exceptions:

### SameQuantum

public static bool SameQuantum(
    PeterO.Numbers.EDecimal ed1,
    PeterO.Numbers.EDecimal ed2);

Returns whether two arbitrary-precision numbers have the same exponent, they both are not-a-number (NaN), or they both are infinity (positive and/or negative).

Parameters:

Return Value:

Either true if the given arbitrary-precision numbers have the same exponent, they both are not-a-number (NaN), or they both are infinity (positive and/or negative); otherwise, false .

### ScaleB

public static PeterO.Numbers.EDecimal ScaleB(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EDecimal ed2,
    PeterO.Numbers.EContext ec);

Finds an arbitrary-precision decimal number whose decimal point is moved a given number of places.

Parameters:

Return Value:

The given arbitrary-precision decimal number whose decimal point is moved the given number of places. Signals an invalid operation and returns not-a-number (NaN) if ed2 is infinity or NaN, has an Exponent property other than 0. Signals an invalid operation and returns not-a-number (NaN) if ec defines a limited precision and exponent range and if ed2 ‘s absolute value is greater than twice the sum of the context’s EMax property and its Precision property.

Exceptions:

### Shift

public static PeterO.Numbers.EDecimal Shift(
    PeterO.Numbers.EDecimal ed,
    PeterO.Numbers.EDecimal ed2,
    PeterO.Numbers.EContext ec);

Shifts the digits of an arbitrary-precision decimal number’s significand.

Parameters:

Return Value:

An arbitrary-precision decimal number whose significand is shifted the given number of digits. Signals an invalid operation and returns NaN (not-a-number) if ed2 is a signaling NaN or if ed2 is not an integer, is negative, has an exponent other than 0, or has an absolute value that exceeds the maximum precision specified in the context.

Exceptions:

### Trim

public static PeterO.Numbers.EDecimal Trim(
    PeterO.Numbers.EDecimal ed1,
    PeterO.Numbers.EContext ec);

Returns an arbitrary-precision number with the same value as this one but with certain trailing zeros removed from its significand. If the number’s exponent is 0, it is returned unchanged (but may be rounded depending on the arithmetic context); if that exponent is greater 0, its trailing zeros are removed from the significand (then rounded if necessary); if that exponent is less than 0, its trailing zeros are removed from the significand until the exponent reaches 0 (then the number is rounded if necessary).

Parameters:

Return Value:

An arbitrary-precision number with the same value as this one but with certain trailing zeros removed from its significand. If ed1 is not-a-number (NaN) or infinity, it is generally returned unchanged.

### Xor

public static PeterO.Numbers.EDecimal Xor(
    PeterO.Numbers.EDecimal ed1,
    PeterO.Numbers.EDecimal ed2,
    PeterO.Numbers.EContext ec);

Performs a logical exclusive-OR (XOR) operation on two decimal numbers in the form of logical operands. A logical operand is a non-negative base-10 number with an exponent of 0 and no other base-10 digits than 0 or 1 (examples include 01001 and 111001 , but not 02001 or 99999 ). The logical exclusive-OR operation sets each digit of the result to 1 if either corresponding digit of the logical operands, but not both, is 1, and to 0 otherwise. For example, 01001 XOR 111010=101010 .

Parameters:

Return Value:

An arbitrary-precision decimal floating-point number.

Back to Numbers start page.