Table of Contents

BigDecimal Struct

Definition

Namespace
Bodu.Numerics
Assembly
Bodu.Numerics.dll
Package
Bodu.Numerics 1.0.0
Source
BigDecimal.Arithmetic.cs

Represents an immutable, arbitrary-precision decimal number - a BigInteger unscaled value together with a base-ten scale.

public readonly struct BigDecimal : INumber<BigDecimal>, IComparable, IComparable<BigDecimal>, IComparisonOperators<BigDecimal, BigDecimal, bool>, IModulusOperators<BigDecimal, BigDecimal, BigDecimal>, ISignedNumber<BigDecimal>, INumberBase<BigDecimal>, IEquatable<BigDecimal>, ISpanFormattable, IFormattable, ISpanParsable<BigDecimal>, IParsable<BigDecimal>, IUtf8SpanFormattable, IUtf8SpanParsable<BigDecimal>, IAdditionOperators<BigDecimal, BigDecimal, BigDecimal>, IAdditiveIdentity<BigDecimal, BigDecimal>, IDecrementOperators<BigDecimal>, IDivisionOperators<BigDecimal, BigDecimal, BigDecimal>, IEqualityOperators<BigDecimal, BigDecimal, bool>, IIncrementOperators<BigDecimal>, IMultiplicativeIdentity<BigDecimal, BigDecimal>, IMultiplyOperators<BigDecimal, BigDecimal, BigDecimal>, ISubtractionOperators<BigDecimal, BigDecimal, BigDecimal>, IUnaryNegationOperators<BigDecimal, BigDecimal>, IUnaryPlusOperators<BigDecimal, BigDecimal>
Implements
Inherited Members
Extension Methods

Examples

BigDecimal price = BigDecimal.Parse("19.99");
BigDecimal tax = price * BigDecimal.Parse("0.10");   // 1.999
BigDecimal total = price + tax;                      // 21.989

BigDecimal third = BigDecimal.One / 3;               // 0.3333… (50 places, half-even)
BigDecimal half = BigDecimal.One / 2;                // 0.5 (exact)

Remarks

A BigDecimal is the value UnscaledValue × 10-Scale. Unlike decimal it has no fixed precision or range limit: both the number of significant digits and the exponent grow as needed.

Every value is held in a single canonical form so equal values share one representation and compare and hash equally: trailing zeros are removed from the unscaled value down to - but never past - a scale of zero, so 1.0 and 1.00 are the same value, and an integer such as 100 keeps a scale of zero.

Addition, subtraction, multiplication, and remainder are exact. Division is generally not exact (for example 1 / 3), so the / operator and Divide(BigDecimal, BigDecimal) round to a default working scale of DefaultDivisionScale decimal places using ToEven; use Divide(BigDecimal, BigDecimal, int, MidpointRounding) to choose the scale and rounding explicitly. Exact quotients self-trim through canonicalization, so 1 / 2 is 0.5.

Constructors

BigDecimal(BigInteger)

Initializes a new instance of the BigDecimal struct representing the integer value.

public BigDecimal(BigInteger value)

Parameters

value BigInteger

The integer value the decimal represents.

BigDecimal(BigInteger, int)

Initializes a new instance of the BigDecimal struct from an unscaled value and scale, reducing the result to canonical form.

public BigDecimal(BigInteger unscaledValue, int scale)

Parameters

unscaledValue BigInteger

The unscaled integer significand.

scale int

The base-ten scale; a negative scale multiplies the unscaled value by 10-scale.

Fields

DefaultDivisionScale

The default number of fractional decimal places produced by the / operator and Divide(BigDecimal, BigDecimal).

public const int DefaultDivisionScale = 50

Field Value

int

Properties

IsInteger

Gets a value indicating whether the value is an integer - has no fractional part.

public bool IsInteger { get; }

Property Value

bool

true when the canonical scale is zero; otherwise false.

IsNegative

Gets a value indicating whether the value is negative.

public bool IsNegative { get; }

Property Value

bool

true when the value is less than zero; otherwise false.

IsPositive

Gets a value indicating whether the value is positive - strictly greater than zero.

public bool IsPositive { get; }

Property Value

bool

true when the value is greater than zero; otherwise false.

IsZero

Gets a value indicating whether the value is zero.

public bool IsZero { get; }

Property Value

bool

true when the value is zero; otherwise false.

MinusOne

Gets a BigDecimal representing the value negative one.

public static BigDecimal MinusOne { get; }

Property Value

BigDecimal

The value -1.

Precision

Gets the precision - the number of significant decimal digits in the unscaled value.

public int Precision { get; }

Property Value

int

The digit count of the unscaled value; 1 for zero.

Scale

Gets the base-ten scale of the canonical form - the number of fractional decimal places.

public int Scale { get; }

Property Value

int

A non-negative scale; zero for an integer value.

Sign

Gets the sign of the value.

public int Sign { get; }

Property Value

int

-1 when negative, 0 when zero, and 1 when positive.

Ten

Gets a BigDecimal representing the value ten.

public static BigDecimal Ten { get; }

Property Value

BigDecimal

The value 10.

UnscaledValue

Gets the unscaled integer significand of the canonical form.

public BigInteger UnscaledValue { get; }

Property Value

BigInteger

The value V such that this decimal equals V × 10-Scale.

Methods

Abs(BigDecimal)

Returns the absolute value.

public static BigDecimal Abs(BigDecimal value)

Parameters

value BigDecimal

The value.

Returns

BigDecimal

The magnitude of value.

Add(BigDecimal, BigDecimal)

Adds two values exactly.

public static BigDecimal Add(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

BigDecimal

The exact sum.

Ceiling(BigDecimal)

Returns the smallest integer value greater than or equal to value.

public static BigDecimal Ceiling(BigDecimal value)

Parameters

value BigDecimal

The value to ceiling.

Returns

BigDecimal

The ceiling of value.

CompareTo(BigDecimal)

Compares this value with another BigDecimal.

public int CompareTo(BigDecimal other)

Parameters

other BigDecimal

The value to compare with.

Returns

int

A negative number when this value is less than other, zero when they are equal, and a positive number when this value is greater.

Remarks

The comparison decides on sign, then on equal scales, then on the operands' integer-magnitude bounds, and only rescales to a common scale when the magnitudes genuinely overlap. Rescaling multiplies an unscaled value by 10 raised to the scale gap, so short-circuiting first bounds the transient allocation that a pathological scale difference would otherwise force on every comparison.

CompareTo(object?)

Compares this value with another object.

public int CompareTo(object? obj)

Parameters

obj object

The object to compare with, which must be a BigDecimal or null.

Returns

int

A negative number when this value is less than obj, zero when they are equal, and a positive number when this value is greater. A null object sorts before every value.

Exceptions

ArgumentException

obj is not a BigDecimal.

Deconstruct(out BigInteger, out int)

Deconstructs the value into its canonical unscaled value and scale.

public void Deconstruct(out BigInteger unscaledValue, out int scale)

Parameters

unscaledValue BigInteger

When this method returns, contains the canonical unscaled value.

scale int

When this method returns, contains the canonical scale.

Divide(BigDecimal, BigDecimal)

Divides one value by another, rounding to DefaultDivisionScale decimal places using ToEven.

public static BigDecimal Divide(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The dividend.

right BigDecimal

The divisor.

Returns

BigDecimal

The quotient; an exact quotient is trimmed to its shortest canonical form.

Exceptions

DivideByZeroException

right is zero.

Divide(BigDecimal, BigDecimal, int, MidpointRounding)

Divides one value by another, rounding the result to the specified number of decimal places.

public static BigDecimal Divide(BigDecimal left, BigDecimal right, int scale, MidpointRounding mode)

Parameters

left BigDecimal

The dividend.

right BigDecimal

The divisor.

scale int

The number of fractional decimal places to round the quotient to.

mode MidpointRounding

The rounding mode applied at the requested scale.

Returns

BigDecimal

The quotient rounded to scale decimal places, in canonical form.

Exceptions

DivideByZeroException

right is zero.

ArgumentOutOfRangeException

scale is negative.

Equals(BigDecimal)

Determines whether this value equals another BigDecimal.

public bool Equals(BigDecimal other)

Parameters

other BigDecimal

The value to compare with.

Returns

bool

true when the values are numerically equal; otherwise false.

Remarks

Because every value is held in canonical form, numerically equal values (for example 1.0 and 1.00) share the same unscaled value and scale and therefore compare equal.

Equals(object?)

Determines whether this value equals another object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with.

Returns

bool

true when obj is a BigDecimal equal to this value; otherwise false.

Floor(BigDecimal)

Returns the largest integer value less than or equal to value.

public static BigDecimal Floor(BigDecimal value)

Parameters

value BigDecimal

The value to floor.

Returns

BigDecimal

The floor of value.

FromDecimal(decimal)

Converts a decimal to a BigDecimal exactly.

public static BigDecimal FromDecimal(decimal value)

Parameters

value decimal

The decimal value.

Returns

BigDecimal

The exact decimal value.

FromDouble(double)

Converts a double to a BigDecimal via its shortest round-trip decimal text.

public static BigDecimal FromDouble(double value)

Parameters

value double

The value to convert.

Returns

BigDecimal

The decimal value.

Exceptions

ArgumentException

value is not a finite number.

GetHashCode()

Returns a hash code consistent with Equals(BigDecimal).

public override int GetHashCode()

Returns

int

A hash code for the value.

Max(BigDecimal, BigDecimal)

Returns the larger of two values.

public static BigDecimal Max(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

BigDecimal

The greater of the two values.

Min(BigDecimal, BigDecimal)

Returns the smaller of two values.

public static BigDecimal Min(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

BigDecimal

The lesser of the two values.

Multiply(BigDecimal, BigDecimal)

Multiplies two values exactly.

public static BigDecimal Multiply(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

BigDecimal

The exact product.

Exceptions

OverflowException

The resulting scale (left.Scale + right.Scale) does not fit in an int.

Negate(BigDecimal)

Negates a value.

public static BigDecimal Negate(BigDecimal value)

Parameters

value BigDecimal

The value to negate.

Returns

BigDecimal

The additive inverse of value.

Parse(string)

Parses the decimal text representation of a value.

public static BigDecimal Parse(string s)

Parameters

s string

The text to parse.

Returns

BigDecimal

The parsed value.

Exceptions

ArgumentNullException

s is null.

FormatException

s is not a valid decimal representation.

Pow(BigDecimal, int)

Raises a value to an integer power.

public static BigDecimal Pow(BigDecimal value, int exponent)

Parameters

value BigDecimal

The base value.

exponent int

The integer exponent.

Returns

BigDecimal

value raised to exponent. A non-negative exponent is exact; a negative exponent divides into one at DefaultDivisionScale decimal places.

Exceptions

DivideByZeroException

value is zero and exponent is negative.

OverflowException

The resulting scale (value.Scale × exponent) does not fit in an int.

Remainder(BigDecimal, BigDecimal)

Returns the remainder of dividing one value by another - the exact value of left - Truncate(left / right) × right.

public static BigDecimal Remainder(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The dividend.

right BigDecimal

The divisor.

Returns

BigDecimal

The exact remainder, whose sign matches left.

Exceptions

DivideByZeroException

right is zero.

Round(BigDecimal)

Rounds a value to the nearest integer using ToEven.

public static BigDecimal Round(BigDecimal value)

Parameters

value BigDecimal

The value to round.

Returns

BigDecimal

The nearest integer value.

Round(BigDecimal, int)

Rounds a value to the specified number of decimal places using ToEven.

public static BigDecimal Round(BigDecimal value, int scale)

Parameters

value BigDecimal

The value to round.

scale int

The number of fractional decimal places to round to.

Returns

BigDecimal

The rounded value.

Exceptions

ArgumentOutOfRangeException

scale is negative.

Round(BigDecimal, int, MidpointRounding)

Rounds a value to the specified number of decimal places using the specified rounding mode.

public static BigDecimal Round(BigDecimal value, int scale, MidpointRounding mode)

Parameters

value BigDecimal

The value to round.

scale int

The number of fractional decimal places to round to.

mode MidpointRounding

The rounding mode.

Returns

BigDecimal

The rounded value; if value already has fewer decimal places it is returned unchanged.

Exceptions

ArgumentOutOfRangeException

scale is negative, or mode is not a defined MidpointRounding value.

Subtract(BigDecimal, BigDecimal)

Subtracts one value from another exactly.

public static BigDecimal Subtract(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The value to subtract from.

right BigDecimal

The value to subtract.

Returns

BigDecimal

The exact difference.

ToBigInteger()

Returns the integer part of the value, truncated toward zero.

public BigInteger ToBigInteger()

Returns

BigInteger

The truncated integer value.

ToDecimal()

Converts the value to a decimal.

public decimal ToDecimal()

Returns

decimal

The value as a decimal.

Exceptions

OverflowException

The value is outside the range of decimal.

ToDouble()

Converts the value to the nearest double.

public double ToDouble()

Returns

double

The nearest double, or PositiveInfinity / NegativeInfinity when the value lies outside the finite double range.

ToString()

Returns the plain (non-scientific) decimal string representation of the value using the invariant culture.

public override string ToString()

Returns

string

The canonical decimal text, for example "0.5", "100", or "-3.14".

ToString(string?)

Formats the value using the specified format specifier and the invariant culture, consistent with the parameterless ToString().

public string ToString(string? format)

Parameters

format string

The format specifier: "G" (or null) for the plain canonical form, or "F" optionally followed by a digit count for a fixed number of decimal places.

Returns

string

The formatted text.

Exceptions

FormatException

format is not a supported specifier.

ToString(string?, IFormatProvider?)

Formats the value using the specified format specifier and format provider.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format specifier: "G" (or null) for the plain canonical form, or "F" optionally followed by a digit count for a fixed number of decimal places.

formatProvider IFormatProvider

The format provider supplying the decimal separator and sign symbols.

Returns

string

The formatted text.

Exceptions

FormatException

format is not a supported specifier.

Truncate(BigDecimal)

Returns the integer part of value, discarding any fractional digits.

public static BigDecimal Truncate(BigDecimal value)

Parameters

value BigDecimal

The value to truncate.

Returns

BigDecimal

The truncated value.

TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)

Tries to format the value of the current instance as UTF-8 into the provided span of bytes.

public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

utf8Destination Span<byte>

The span in which to write this instance's value formatted as a span of bytes.

bytesWritten int

When this method returns, contains the number of bytes that were written in utf8Destination.

format ReadOnlySpan<char>

A span containing the characters that represent a standard or custom format string that defines the acceptable format for utf8Destination.

provider IFormatProvider

An optional object that supplies culture-specific formatting information for utf8Destination.

Returns

bool

true if the formatting was successful; otherwise, false.

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Tries to format the value of the current instance into the provided span of characters.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

destination Span<char>

The span in which to write this instance's value formatted as a span of characters.

charsWritten int

When this method returns, contains the number of characters that were written in destination.

format ReadOnlySpan<char>

A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination.

provider IFormatProvider

An optional object that supplies culture-specific formatting information for destination.

Returns

bool

true if the formatting was successful; otherwise, false.

TryParse(string?, out BigDecimal)

Attempts to parse the decimal text representation of a value using the current culture.

public static bool TryParse(string? s, out BigDecimal result)

Parameters

s string

The text to parse.

result BigDecimal

When this method returns, contains the parsed value, or zero on failure.

Returns

bool

true if parsing succeeded; otherwise, false.

TryToDecimal(out decimal)

Attempts to convert the value to a decimal.

public bool TryToDecimal(out decimal result)

Parameters

result decimal

When this method returns, contains the converted value, or zero on failure.

Returns

bool

true if the value fits the decimal range; otherwise, false.

TryToDouble(out double)

Attempts to convert the value to the nearest double.

public bool TryToDouble(out double result)

Parameters

result double

When this method returns, contains the converted value, or zero on failure.

Returns

bool

true if the value has a finite double-precision approximation; false when it lies outside the finite double range.

Operators

explicit operator decimal(BigDecimal)

Explicitly converts a BigDecimal to a decimal.

public static explicit operator decimal(BigDecimal value)

Parameters

value BigDecimal

The value to convert.

Returns

decimal

The value as a decimal.

Exceptions

OverflowException

value is outside the range of decimal.

explicit operator double(BigDecimal)

Explicitly converts a BigDecimal to the nearest double.

public static explicit operator double(BigDecimal value)

Parameters

value BigDecimal

The value to convert.

Returns

double

The nearest double.

explicit operator BigInteger(BigDecimal)

Explicitly converts a BigDecimal to a BigInteger, truncating toward zero.

public static explicit operator BigInteger(BigDecimal value)

Parameters

value BigDecimal

The value to convert.

Returns

BigInteger

The integer part of value.

explicit operator BigDecimal(double)

Explicitly converts a double to a BigDecimal via its shortest round-trip decimal text - so 0.1d becomes 0.1, not its exact binary expansion.

public static explicit operator BigDecimal(double value)

Parameters

value double

The value to convert.

Returns

BigDecimal

The decimal value.

Exceptions

ArgumentException

value is not a finite number.

implicit operator BigDecimal(decimal)

Implicitly converts a decimal to a BigDecimal exactly.

public static implicit operator BigDecimal(decimal value)

Parameters

value decimal

The decimal value.

Returns

BigDecimal

The exact decimal value.

implicit operator BigDecimal(int)

Implicitly converts a 32-bit signed integer to a BigDecimal.

public static implicit operator BigDecimal(int value)

Parameters

value int

The integer value.

Returns

BigDecimal

The exact decimal value.

implicit operator BigDecimal(long)

Implicitly converts a 64-bit signed integer to a BigDecimal.

public static implicit operator BigDecimal(long value)

Parameters

value long

The integer value.

Returns

BigDecimal

The exact decimal value.

implicit operator BigDecimal(BigInteger)

Implicitly converts a BigInteger to a BigDecimal.

public static implicit operator BigDecimal(BigInteger value)

Parameters

value BigInteger

The integer value.

Returns

BigDecimal

The exact decimal value.

Explicit Interface Implementations

One

Gets a BigDecimal representing the value one.

static BigDecimal One { get; }

Returns

BigDecimal

The value 1.

Parse(ReadOnlySpan<byte>, IFormatProvider?)

Parses the UTF-8 decimal text representation of a value.

static BigDecimal Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)

Parameters

utf8Text ReadOnlySpan<byte>

The UTF-8 text to parse.

provider IFormatProvider

The format provider supplying the decimal separator and sign symbols.

Returns

BigDecimal

The parsed value.

Exceptions

FormatException

utf8Text is not a valid decimal representation.

Parse(ReadOnlySpan<char>, IFormatProvider?)

Parses the decimal text representation of a value from a character span.

static BigDecimal Parse(ReadOnlySpan<char> s, IFormatProvider? provider)

Parameters

s ReadOnlySpan<char>

The text to parse.

provider IFormatProvider

The format provider supplying the decimal separator and sign symbols.

Returns

BigDecimal

The parsed value.

Exceptions

FormatException

s is not a valid decimal representation.

Parse(string, IFormatProvider?)

Parses the decimal text representation of a value using the specified format provider.

static BigDecimal Parse(string s, IFormatProvider? provider)

Parameters

s string

The text to parse.

provider IFormatProvider

The format provider supplying the decimal separator and sign symbols.

Returns

BigDecimal

The parsed value.

Exceptions

ArgumentNullException

s is null.

FormatException

s is not a valid decimal representation.

IAdditiveIdentity<BigDecimal, BigDecimal>.AdditiveIdentity

Gets the additive identity of the current type.

static BigDecimal IAdditiveIdentity<BigDecimal, BigDecimal>.AdditiveIdentity { get; }

Returns

BigDecimal

IMultiplicativeIdentity<BigDecimal, BigDecimal>.MultiplicativeIdentity

Gets the multiplicative identity of the current type.

static BigDecimal IMultiplicativeIdentity<BigDecimal, BigDecimal>.MultiplicativeIdentity { get; }

Returns

BigDecimal

INumberBase<BigDecimal>.Abs(BigDecimal)

Computes the absolute of a value.

static BigDecimal INumberBase<BigDecimal>.Abs(BigDecimal value)

Parameters

value BigDecimal

The value for which to get its absolute.

Returns

BigDecimal

The absolute of value.

Exceptions

OverflowException

The absolute of value is not representable by BigDecimal.

INumberBase<BigDecimal>.IsCanonical(BigDecimal)

Determines if a value is in its canonical representation.

static bool INumberBase<BigDecimal>.IsCanonical(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is in its canonical representation; otherwise, false.

INumberBase<BigDecimal>.IsComplexNumber(BigDecimal)

Determines if a value represents a complex number.

static bool INumberBase<BigDecimal>.IsComplexNumber(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is a complex number; otherwise, false.

INumberBase<BigDecimal>.IsEvenInteger(BigDecimal)

Determines if a value represents an even integral number.

static bool INumberBase<BigDecimal>.IsEvenInteger(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is an even integer; otherwise, false.

INumberBase<BigDecimal>.IsFinite(BigDecimal)

Determines if a value is finite.

static bool INumberBase<BigDecimal>.IsFinite(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is finite; otherwise, false.

INumberBase<BigDecimal>.IsImaginaryNumber(BigDecimal)

Determines if a value represents a pure imaginary number.

static bool INumberBase<BigDecimal>.IsImaginaryNumber(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is a pure imaginary number; otherwise, false.

INumberBase<BigDecimal>.IsInfinity(BigDecimal)

Determines if a value is infinite.

static bool INumberBase<BigDecimal>.IsInfinity(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is infinite; otherwise, false.

INumberBase<BigDecimal>.IsInteger(BigDecimal)

Determines if a value represents an integral number.

static bool INumberBase<BigDecimal>.IsInteger(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is an integer; otherwise, false.

INumberBase<BigDecimal>.IsNaN(BigDecimal)

Determines if a value is NaN.

static bool INumberBase<BigDecimal>.IsNaN(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is NaN; otherwise, false.

INumberBase<BigDecimal>.IsNegative(BigDecimal)

Determines if a value represents a negative real number.

static bool INumberBase<BigDecimal>.IsNegative(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value represents negative zero or a negative real number; otherwise, false.

INumberBase<BigDecimal>.IsNegativeInfinity(BigDecimal)

Determines if a value is negative infinity.

static bool INumberBase<BigDecimal>.IsNegativeInfinity(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is negative infinity; otherwise, false.

INumberBase<BigDecimal>.IsNormal(BigDecimal)

Determines if a value is normal.

static bool INumberBase<BigDecimal>.IsNormal(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is normal; otherwise, false.

INumberBase<BigDecimal>.IsOddInteger(BigDecimal)

Determines if a value represents an odd integral number.

static bool INumberBase<BigDecimal>.IsOddInteger(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is an odd integer; otherwise, false.

INumberBase<BigDecimal>.IsPositive(BigDecimal)

Determines if a value represents zero or a positive real number.

static bool INumberBase<BigDecimal>.IsPositive(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value represents (positive) zero or a positive real number; otherwise, false.

INumberBase<BigDecimal>.IsPositiveInfinity(BigDecimal)

Determines if a value is positive infinity.

static bool INumberBase<BigDecimal>.IsPositiveInfinity(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is positive infinity; otherwise, false.

INumberBase<BigDecimal>.IsRealNumber(BigDecimal)

Determines if a value represents a real number.

static bool INumberBase<BigDecimal>.IsRealNumber(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is a real number; otherwise, false.

INumberBase<BigDecimal>.IsSubnormal(BigDecimal)

Determines if a value is subnormal.

static bool INumberBase<BigDecimal>.IsSubnormal(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is subnormal; otherwise, false.

INumberBase<BigDecimal>.IsZero(BigDecimal)

Determines if a value is zero.

static bool INumberBase<BigDecimal>.IsZero(BigDecimal value)

Parameters

value BigDecimal

The value to be checked.

Returns

bool

true if value is zero; otherwise, false.

INumberBase<BigDecimal>.MaxMagnitude(BigDecimal, BigDecimal)

Compares two values to compute which has the greater magnitude.

static BigDecimal INumberBase<BigDecimal>.MaxMagnitude(BigDecimal x, BigDecimal y)

Parameters

x BigDecimal

The value to compare with y.

y BigDecimal

The value to compare with x.

Returns

BigDecimal

x if it has a greater magnitude than y; otherwise, y.

INumberBase<BigDecimal>.MaxMagnitudeNumber(BigDecimal, BigDecimal)

Compares two values to compute which has the greater magnitude and returning the other value if an input is NaN.

static BigDecimal INumberBase<BigDecimal>.MaxMagnitudeNumber(BigDecimal x, BigDecimal y)

Parameters

x BigDecimal

The value to compare with y.

y BigDecimal

The value to compare with x.

Returns

BigDecimal

x if it has a greater magnitude than y; otherwise, y.

INumberBase<BigDecimal>.MinMagnitude(BigDecimal, BigDecimal)

Compares two values to compute which has the lesser magnitude.

static BigDecimal INumberBase<BigDecimal>.MinMagnitude(BigDecimal x, BigDecimal y)

Parameters

x BigDecimal

The value to compare with y.

y BigDecimal

The value to compare with x.

Returns

BigDecimal

x if it has a lesser magnitude than y; otherwise, y.

INumberBase<BigDecimal>.MinMagnitudeNumber(BigDecimal, BigDecimal)

Compares two values to compute which has the lesser magnitude and returning the other value if an input is NaN.

static BigDecimal INumberBase<BigDecimal>.MinMagnitudeNumber(BigDecimal x, BigDecimal y)

Parameters

x BigDecimal

The value to compare with y.

y BigDecimal

The value to compare with x.

Returns

BigDecimal

x if it has a lesser magnitude than y; otherwise, y.

INumberBase<BigDecimal>.Parse(ReadOnlySpan<char>, NumberStyles, IFormatProvider)

Parses a span of characters into a value.

static BigDecimal INumberBase<BigDecimal>.Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider)

Parameters

s ReadOnlySpan<char>

The span of characters to parse.

style NumberStyles

A bitwise combination of number styles that can be present in s.

provider IFormatProvider

An object that provides culture-specific formatting information about s.

Returns

BigDecimal

The result of parsing s.

Exceptions

ArgumentException

style is not a supported NumberStyles value.

FormatException

s is not in the correct format.

OverflowException

s is not representable by BigDecimal.

INumberBase<BigDecimal>.Parse(string, NumberStyles, IFormatProvider)

Parses a string into a value.

static BigDecimal INumberBase<BigDecimal>.Parse(string s, NumberStyles style, IFormatProvider provider)

Parameters

s string

The string to parse.

style NumberStyles

A bitwise combination of number styles that can be present in s.

provider IFormatProvider

An object that provides culture-specific formatting information about s.

Returns

BigDecimal

The result of parsing s.

Exceptions

ArgumentException

style is not a supported NumberStyles value.

ArgumentNullException

s is null.

FormatException

s is not in the correct format.

OverflowException

s is not representable by BigDecimal.

INumberBase<BigDecimal>.Radix

Gets the radix, or base, for the type.

static int INumberBase<BigDecimal>.Radix { get; }

Returns

int

INumberBase<BigDecimal>.TryConvertFromChecked<TOther>(TOther, out BigDecimal)

Tries to convert a value to an instance of the the current type, throwing an overflow exception for any values that fall outside the representable range of the current type.

static bool INumberBase<BigDecimal>.TryConvertFromChecked<TOther>(TOther value, out BigDecimal result) where TOther : INumberBase<TOther>

Parameters

value TOther

The value that's used to create the instance of BigDecimal.

result BigDecimal

When this method returns, contains an instance of BigDecimal converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type of value.

Exceptions

OverflowException

value is not representable by BigDecimal.

INumberBase<BigDecimal>.TryConvertFromSaturating<TOther>(TOther, out BigDecimal)

Tries to convert a value to an instance of the the current type, saturating any values that fall outside the representable range of the current type.

static bool INumberBase<BigDecimal>.TryConvertFromSaturating<TOther>(TOther value, out BigDecimal result) where TOther : INumberBase<TOther>

Parameters

value TOther

The value that is used to create the instance of BigDecimal.

result BigDecimal

When this method returns, contains an instance of BigDecimal converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type of value.

INumberBase<BigDecimal>.TryConvertFromTruncating<TOther>(TOther, out BigDecimal)

Tries to convert a value to an instance of the the current type, truncating any values that fall outside the representable range of the current type.

static bool INumberBase<BigDecimal>.TryConvertFromTruncating<TOther>(TOther value, out BigDecimal result) where TOther : INumberBase<TOther>

Parameters

value TOther

The value that is used to create the instance of BigDecimal.

result BigDecimal

When this method returns, contains an instance of BigDecimal converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type of value.

INumberBase<BigDecimal>.TryConvertToChecked<TOther>(BigDecimal, out TOther)

Tries to convert an instance of the the current type to another type, throwing an overflow exception for any values that fall outside the representable range of the current type.

static bool INumberBase<BigDecimal>.TryConvertToChecked<TOther>(BigDecimal value, out TOther result) where TOther : INumberBase<TOther>

Parameters

value BigDecimal

The value that is used to create the instance of TOther.

result TOther

When this method returns, contains an instance of TOther converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type to which value should be converted.

Exceptions

OverflowException

value is not representable by TOther.

INumberBase<BigDecimal>.TryConvertToSaturating<TOther>(BigDecimal, out TOther)

Tries to convert an instance of the the current type to another type, saturating any values that fall outside the representable range of the current type.

static bool INumberBase<BigDecimal>.TryConvertToSaturating<TOther>(BigDecimal value, out TOther result) where TOther : INumberBase<TOther>

Parameters

value BigDecimal

The value that is used to create the instance of TOther.

result TOther

When this method returns, contains an instance of TOther converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type to which value should be converted.

INumberBase<BigDecimal>.TryConvertToTruncating<TOther>(BigDecimal, out TOther)

Tries to convert an instance of the the current type to another type, truncating any values that fall outside the representable range of the current type.

static bool INumberBase<BigDecimal>.TryConvertToTruncating<TOther>(BigDecimal value, out TOther result) where TOther : INumberBase<TOther>

Parameters

value BigDecimal

The value that is used to create the instance of TOther.

result TOther

When this method returns, contains an instance of TOther converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type to which value should be converted.

INumberBase<BigDecimal>.TryParse(ReadOnlySpan<char>, NumberStyles, IFormatProvider, out BigDecimal)

Tries to parse a span of characters into a value.

static bool INumberBase<BigDecimal>.TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out BigDecimal result)

Parameters

s ReadOnlySpan<char>

The span of characters to parse.

style NumberStyles

A bitwise combination of number styles that can be present in s.

provider IFormatProvider

An object that provides culture-specific formatting information about s.

result BigDecimal

On return, contains the result of succesfully parsing s or an undefined value on failure.

Returns

bool

true if s was successfully parsed; otherwise, false.

Exceptions

ArgumentException

style is not a supported NumberStyles value.

INumberBase<BigDecimal>.TryParse(string, NumberStyles, IFormatProvider, out BigDecimal)

Tries to parse a string into a value.

static bool INumberBase<BigDecimal>.TryParse(string s, NumberStyles style, IFormatProvider provider, out BigDecimal result)

Parameters

s string

The string to parse.

style NumberStyles

A bitwise combination of number styles that can be present in s.

provider IFormatProvider

An object that provides culture-specific formatting information about s.

result BigDecimal

On return, contains the result of succesfully parsing s or an undefined value on failure.

Returns

bool

true if s was successfully parsed; otherwise, false.

Exceptions

ArgumentException

style is not a supported NumberStyles value.

INumber<BigDecimal>.Clamp(BigDecimal, BigDecimal, BigDecimal)

Clamps a value to an inclusive minimum and maximum value.

static BigDecimal INumber<BigDecimal>.Clamp(BigDecimal value, BigDecimal min, BigDecimal max)

Parameters

value BigDecimal

The value to clamp.

min BigDecimal

The inclusive minimum to which value should clamp.

max BigDecimal

The inclusive maximum to which value should clamp.

Returns

BigDecimal

The result of clamping value to the inclusive range of min and max.

Exceptions

ArgumentException

min is greater than max.

INumber<BigDecimal>.CopySign(BigDecimal, BigDecimal)

Copies the sign of a value to the sign of another value.

static BigDecimal INumber<BigDecimal>.CopySign(BigDecimal value, BigDecimal sign)

Parameters

value BigDecimal

The value whose magnitude is used in the result.

sign BigDecimal

The value whose sign is used in the result.

Returns

BigDecimal

A value with the magnitude of value and the sign of sign.

INumber<BigDecimal>.Max(BigDecimal, BigDecimal)

Compares two values to compute which is greater.

static BigDecimal INumber<BigDecimal>.Max(BigDecimal x, BigDecimal y)

Parameters

x BigDecimal

The value to compare with y.

y BigDecimal

The value to compare with x.

Returns

BigDecimal

x if it is greater than y; otherwise, y.

INumber<BigDecimal>.MaxNumber(BigDecimal, BigDecimal)

Compares two values to compute which is greater and returning the other value if an input is NaN.

static BigDecimal INumber<BigDecimal>.MaxNumber(BigDecimal x, BigDecimal y)

Parameters

x BigDecimal

The value to compare with y.

y BigDecimal

The value to compare with x.

Returns

BigDecimal

x if it is greater than y; otherwise, y.

INumber<BigDecimal>.Min(BigDecimal, BigDecimal)

Compares two values to compute which is lesser.

static BigDecimal INumber<BigDecimal>.Min(BigDecimal x, BigDecimal y)

Parameters

x BigDecimal

The value to compare with y.

y BigDecimal

The value to compare with x.

Returns

BigDecimal

x if it is less than y; otherwise, y.

INumber<BigDecimal>.MinNumber(BigDecimal, BigDecimal)

Compares two values to compute which is lesser and returning the other value if an input is NaN.

static BigDecimal INumber<BigDecimal>.MinNumber(BigDecimal x, BigDecimal y)

Parameters

x BigDecimal

The value to compare with y.

y BigDecimal

The value to compare with x.

Returns

BigDecimal

x if it is less than y; otherwise, y.

INumber<BigDecimal>.Sign(BigDecimal)

Computes the sign of a value.

static int INumber<BigDecimal>.Sign(BigDecimal value)

Parameters

value BigDecimal

The value whose sign is to be computed.

Returns

int

A positive value if value is positive, 0 if value is zero, and a negative value if value is negative.

ISignedNumber<BigDecimal>.NegativeOne

Gets the value -1 for the type.

static BigDecimal ISignedNumber<BigDecimal>.NegativeOne { get; }

Returns

BigDecimal

TryParse(ReadOnlySpan<byte>, IFormatProvider?, out BigDecimal)

Attempts to parse the UTF-8 decimal text representation of a value.

static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out BigDecimal result)

Parameters

utf8Text ReadOnlySpan<byte>

The UTF-8 text to parse.

provider IFormatProvider

The format provider supplying the decimal separator and sign symbols.

result BigDecimal

When this method returns, contains the parsed value, or zero on failure.

Returns

bool

true if parsing succeeded; otherwise, false.

TryParse(ReadOnlySpan<char>, IFormatProvider?, out BigDecimal)

Attempts to parse the decimal text representation of a value from a character span.

static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out BigDecimal result)

Parameters

s ReadOnlySpan<char>

The text to parse.

provider IFormatProvider

The format provider supplying the decimal separator and sign symbols.

result BigDecimal

When this method returns, contains the parsed value, or zero on failure.

Returns

bool

true if parsing succeeded; otherwise, false.

TryParse(string?, IFormatProvider?, out BigDecimal)

Attempts to parse the decimal text representation of a value.

static bool TryParse(string? s, IFormatProvider? provider, out BigDecimal result)

Parameters

s string

The text to parse.

provider IFormatProvider

The format provider supplying the decimal separator and sign symbols.

result BigDecimal

When this method returns, contains the parsed value, or zero on failure.

Returns

bool

true if parsing succeeded; otherwise, false.

Zero

Gets a BigDecimal representing the value zero.

static BigDecimal Zero { get; }

Returns

BigDecimal

The value 0.

operator +(BigDecimal, BigDecimal)

Adds two values exactly.

static BigDecimal operator +(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

BigDecimal

The exact sum.

operator --(BigDecimal)

Decrements a value by one.

static BigDecimal operator --(BigDecimal value)

Parameters

value BigDecimal

The value to decrement.

Returns

BigDecimal

The value minus one.

operator /(BigDecimal, BigDecimal)

Divides one value by another, rounding to DefaultDivisionScale decimal places.

static BigDecimal operator /(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The dividend.

right BigDecimal

The divisor.

Returns

BigDecimal

The rounded quotient.

Exceptions

DivideByZeroException

right is zero.

operator ==(BigDecimal, BigDecimal)

Determines whether two values are numerically equal.

static bool operator ==(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

bool

true when the values are equal; otherwise false.

operator >(BigDecimal, BigDecimal)

Determines whether one value is greater than another.

static bool operator >(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

bool

true when left is greater than right; otherwise false.

operator >=(BigDecimal, BigDecimal)

Determines whether one value is greater than or equal to another.

static bool operator >=(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

bool

true when left is greater than or equal to right; otherwise false.

operator ++(BigDecimal)

Increments a value by one.

static BigDecimal operator ++(BigDecimal value)

Parameters

value BigDecimal

The value to increment.

Returns

BigDecimal

The value plus one.

operator !=(BigDecimal, BigDecimal)

Determines whether two values are not numerically equal.

static bool operator !=(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

bool

true when the values differ; otherwise false.

operator <(BigDecimal, BigDecimal)

Determines whether one value is less than another.

static bool operator <(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

bool

true when left is less than right; otherwise false.

operator <=(BigDecimal, BigDecimal)

Determines whether one value is less than or equal to another.

static bool operator <=(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

bool

true when left is less than or equal to right; otherwise false.

operator %(BigDecimal, BigDecimal)

Returns the remainder of dividing one value by another.

static BigDecimal operator %(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The dividend.

right BigDecimal

The divisor.

Returns

BigDecimal

The exact remainder.

Exceptions

DivideByZeroException

right is zero.

operator *(BigDecimal, BigDecimal)

Multiplies two values exactly.

static BigDecimal operator *(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The first value.

right BigDecimal

The second value.

Returns

BigDecimal

The exact product.

operator -(BigDecimal, BigDecimal)

Subtracts one value from another exactly.

static BigDecimal operator -(BigDecimal left, BigDecimal right)

Parameters

left BigDecimal

The value to subtract from.

right BigDecimal

The value to subtract.

Returns

BigDecimal

The exact difference.

operator -(BigDecimal)

Negates a value.

static BigDecimal operator -(BigDecimal value)

Parameters

value BigDecimal

The value to negate.

Returns

BigDecimal

The additive inverse of value.

operator +(BigDecimal)

Returns the value unchanged.

static BigDecimal operator +(BigDecimal value)

Parameters

value BigDecimal

The value.

Returns

BigDecimal

The same value.

Applies to

ProductVersions
.NET8, 10