Struct BigDecimal
Operators and methods for comparing BigDecimals.
Implements
IConvertible
ICloneable
Assembly: Galaxon.Numerics.BigDecimal.dll
Syntax
Constructors
BigDecimal()
Declaration
BigDecimal(BigInteger, Int32, Boolean)
Declaration
public BigDecimal(BigInteger significand, int exponent = 0, bool roundSigFigs = false)
Parameters
| Type |
Name |
Description |
| BigInteger |
significand |
The significand or mantissa.
|
| System.Int32 |
exponent |
The exponent.
|
| System.Boolean |
roundSigFigs |
If the value should be rounded off to the current value of
MaxSigFigs.
|
Fields
DecimalPrecision
Precision supported by the decimal type.
Declaration
public const int DecimalPrecision = null
Field Value
| Type |
Description |
| System.Int32 |
|
DoublePrecision
Precision supported by the double type.
Declaration
public const int DoublePrecision = null
Field Value
| Type |
Description |
| System.Int32 |
|
FloatPrecision
Precision supported by the float type.
Declaration
public const int FloatPrecision = null
Field Value
| Type |
Description |
| System.Int32 |
|
HalfPrecision
Precision supported by the Half type.
Declaration
public const int HalfPrecision = null
Field Value
| Type |
Description |
| System.Int32 |
|
Properties
AdditiveIdentity
Declaration
public static readonly BigDecimal AdditiveIdentity { get; }
Property Value
E
Declaration
public static readonly BigDecimal E { get; }
Property Value
Exponent
Declaration
public int Exponent { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
Ln10
The natural logarithm of 10.
Declaration
public static readonly BigDecimal Ln10 { get; }
Property Value
MaxSigFigs
This property determines the maximum number of significant figures to keep in a BigDecimal
value.
After any calculation, the result will be rounded to this many significant figures.
This not only helps control memory usage by controlling the size of the significand, but
also determines when to halt numerical methods, e.g. for calculating a square root or
logarithm.
If this property is modified, only new objects and calculations are affected by it.
If you want to reduce the number of significant figures in an existing value, use
RoundSigFigs().
Declaration
public static int MaxSigFigs { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
MultiplicativeIdentity
Declaration
public static readonly BigDecimal MultiplicativeIdentity { get; }
Property Value
NegativeOne
Declaration
public static readonly BigDecimal NegativeOne { get; }
Property Value
NumSigFigs
Get the number of significant figures.
Declaration
public readonly int NumSigFigs { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
One
Declaration
public static readonly BigDecimal One { get; }
Property Value
Phi
Declaration
public static readonly BigDecimal Phi { get; }
Property Value
Pi
Declaration
public static readonly BigDecimal Pi { get; }
Property Value
Radix
Declaration
public static readonly int Radix { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
Sign
The sign of the value. The same convention is used as for BigInteger except sbyte is used
instead of an int.
-1 for negative
0 for zero
1 for positive
Declaration
public readonly sbyte Sign { get; }
Property Value
| Type |
Description |
| System.SByte |
|
Significand
The part of a number in scientific notation or in floating-point representation, consisting
of its significant digits.
Declaration
public BigInteger Significand { get; set; }
Property Value
| Type |
Description |
| BigInteger |
|
Tau
Declaration
public static readonly BigDecimal Tau { get; }
Property Value
Zero
Declaration
public static readonly BigDecimal Zero { get; }
Property Value
Methods
Abs(BigDecimal)
Declaration
public static BigDecimal Abs(BigDecimal bd)
Parameters
Returns
Acos(BigDecimal)
Declaration
public static BigDecimal Acos(BigDecimal x)
Parameters
Returns
Acosh(BigDecimal)
Declaration
public static BigDecimal Acosh(BigDecimal x)
Parameters
Returns
AcosPi(BigDecimal)
Declaration
public static BigDecimal AcosPi(BigDecimal x)
Parameters
Returns
ArithmeticGeometricMean(BigDecimal, BigDecimal)
Compute the arithmetic-geometric mean of two values.
Declaration
public static BigDecimal ArithmeticGeometricMean(BigDecimal x, BigDecimal y)
Parameters
Returns
Asin(BigDecimal)
Declaration
public static BigDecimal Asin(BigDecimal x)
Parameters
Returns
Asinh(BigDecimal)
Declaration
public static BigDecimal Asinh(BigDecimal x)
Parameters
Returns
AsinPi(BigDecimal)
Declaration
public static BigDecimal AsinPi(BigDecimal x)
Parameters
Returns
Atan(BigDecimal)
Declaration
public static BigDecimal Atan(BigDecimal x)
Parameters
Returns
Atanh(BigDecimal)
Declaration
public static BigDecimal Atanh(BigDecimal x)
Parameters
Returns
AtanPi(BigDecimal)
Declaration
public static BigDecimal AtanPi(BigDecimal x)
Parameters
Returns
Average(BigDecimal[])
Compute the arithmetic mean (average) of the given values.
If you have a collection, you can use the extension method directly instead.
Declaration
public static BigDecimal Average(params BigDecimal[] nums)
Parameters
Returns
Cbrt(BigDecimal)
Calculate the cube root of a real number.
Declaration
public static BigDecimal Cbrt(BigDecimal x)
Parameters
Returns
| Type |
Description |
| BigDecimal |
The cube root of the number.
|
Ceiling(BigDecimal)
Declaration
public static BigDecimal Ceiling(BigDecimal x)
Parameters
Returns
Clone()
Declaration
Returns
| Type |
Description |
| System.Object |
|
CompareTo(BigDecimal)
Declaration
public int CompareTo(BigDecimal other)
Parameters
Returns
| Type |
Description |
| System.Int32 |
|
CompareTo(Nullable<Object>)
Declaration
public int CompareTo(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Int32 |
|
ComputePhi()
Compute the value of phi (φ), the golden ration.
Declaration
public static BigDecimal ComputePhi()
Returns
| Type |
Description |
| BigDecimal |
The value of φ to the current number of significant figures.
|
ComputePi()
Declaration
public static BigDecimal ComputePi()
Returns
ComputeTau()
Compute the value of tau (τ), equal to 2 * pi (2π).
Declaration
public static BigDecimal ComputeTau()
Returns
| Type |
Description |
| BigDecimal |
The value of τ to the current number of significant figures.
|
Cos(BigDecimal)
Declaration
public static BigDecimal Cos(BigDecimal x)
Parameters
Returns
Cosh(BigDecimal)
Declaration
public static BigDecimal Cosh(BigDecimal x)
Parameters
Returns
CosPi(BigDecimal)
Declaration
public static BigDecimal CosPi(BigDecimal x)
Parameters
Returns
Cube(BigDecimal)
Calculate the cube of a number.
Declaration
public static BigDecimal Cube(BigDecimal x)
Parameters
Returns
| Type |
Description |
| BigDecimal |
The cube of the argument.
|
Equals(BigDecimal)
Declaration
public bool Equals(BigDecimal other)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Equals(Nullable<Object>)
Declaration
public override bool Equals(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
Exp(BigDecimal)
Declaration
public static BigDecimal Exp(BigDecimal x)
Parameters
Returns
Exp10(BigDecimal)
Declaration
public static BigDecimal Exp10(BigDecimal x)
Parameters
Returns
Exp2(BigDecimal)
Declaration
public static BigDecimal Exp2(BigDecimal x)
Parameters
Returns
Floor(BigDecimal)
Declaration
public static BigDecimal Floor(BigDecimal x)
Parameters
Returns
Frac(BigDecimal)
Return the fractional part of the value.
There are multiple ways to define the frac() function for negative numbers.
(Refer to the Wikipedia link below.)
The definition used in this implementation simply takes the digits to the right of the
decimal point, with the sign matching the argument.
e.g.
Frac(12.345) => 0.345
Frac(-12.345) => -0.345
The following expression will be true for both positive and negative numbers:
x == Truncate(x) + Frac(x)
Declaration
public static BigDecimal Frac(BigDecimal x)
Parameters
Returns
GeometricMean(BigDecimal[])
Compute the geometric mean of the given values.
If you have a collection, you can use the extension method directly instead.
Declaration
public static BigDecimal GeometricMean(params BigDecimal[] nums)
Parameters
Returns
GetExponentByteCount()
Declaration
public int GetExponentByteCount()
Returns
| Type |
Description |
| System.Int32 |
|
GetExponentShortestBitLength()
Declaration
public int GetExponentShortestBitLength()
Returns
| Type |
Description |
| System.Int32 |
|
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type |
Description |
| System.Int32 |
|
GetSignificandBitLength()
Declaration
public int GetSignificandBitLength()
Returns
| Type |
Description |
| System.Int32 |
|
GetSignificandByteCount()
Declaration
public int GetSignificandByteCount()
Returns
| Type |
Description |
| System.Int32 |
|
GetTypeCode()
Declaration
public TypeCode GetTypeCode()
Returns
| Type |
Description |
| TypeCode |
|
Hypot(BigDecimal, BigDecimal)
Calculate the length of the hypotenuse of a right triangle.
Declaration
public static BigDecimal Hypot(BigDecimal x, BigDecimal y)
Parameters
| Type |
Name |
Description |
| BigDecimal |
x |
The length of one of the short sides of the triangle.
|
| BigDecimal |
y |
The length of the other short side of the triangle.
|
Returns
| Type |
Description |
| BigDecimal |
The length of the hypotenuse.
|
IsCanonical(BigDecimal)
Checks if the value is in its canonical state.
In this case, the value should not be evenly divisible by 10. In canonical form, a
multiple of 10 should be shortened and the exponent increased.
Declaration
public static bool IsCanonical(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsComplexNumber(BigDecimal)
Check if the value is a complex number.
Declaration
public static bool IsComplexNumber(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsEvenInteger(BigDecimal)
Declaration
public static bool IsEvenInteger(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsFinite(BigDecimal)
Declaration
public static bool IsFinite(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsImaginaryNumber(BigDecimal)
Declaration
public static bool IsImaginaryNumber(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsInfinity(BigDecimal)
Declaration
public static bool IsInfinity(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsInteger(BigDecimal)
The value will be an integer if in canonical form and the exponent is >= 0.
Declaration
public static bool IsInteger(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsNaN(BigDecimal)
Declaration
public static bool IsNaN(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsNegative(BigDecimal)
Declaration
public static bool IsNegative(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsNegativeInfinity(BigDecimal)
Declaration
public static bool IsNegativeInfinity(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsNormal(BigDecimal)
Declaration
public static bool IsNormal(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsOddInteger(BigDecimal)
Declaration
public static bool IsOddInteger(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsPositive(BigDecimal)
Declaration
public static bool IsPositive(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsPositiveInfinity(BigDecimal)
Declaration
public static bool IsPositiveInfinity(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsRealNumber(BigDecimal)
Declaration
public static bool IsRealNumber(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsSubnormal(BigDecimal)
Declaration
public static bool IsSubnormal(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
IsZero(BigDecimal)
Declaration
public static bool IsZero(BigDecimal value)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Log(BigDecimal)
Declaration
public static BigDecimal Log(BigDecimal x)
Parameters
Returns
Log(BigDecimal, BigDecimal)
Declaration
public static BigDecimal Log(BigDecimal x, BigDecimal b)
Parameters
Returns
Log10(BigDecimal)
Declaration
public static BigDecimal Log10(BigDecimal x)
Parameters
Returns
Log2(BigDecimal)
Declaration
public static BigDecimal Log2(BigDecimal x)
Parameters
Returns
MaxMagnitude(BigDecimal, BigDecimal)
Declaration
public static BigDecimal MaxMagnitude(BigDecimal x, BigDecimal y)
Parameters
Returns
MaxMagnitudeNumber(BigDecimal, BigDecimal)
Declaration
public static BigDecimal MaxMagnitudeNumber(BigDecimal x, BigDecimal y)
Parameters
Returns
MinMagnitude(BigDecimal, BigDecimal)
Declaration
public static BigDecimal MinMagnitude(BigDecimal x, BigDecimal y)
Parameters
Returns
MinMagnitudeNumber(BigDecimal, BigDecimal)
Declaration
public static BigDecimal MinMagnitudeNumber(BigDecimal x, BigDecimal y)
Parameters
Returns
NormalizeAngle(in BigDecimal)
Shift given angle to the equivalent angle in the interval [-π, π).
Declaration
public static BigDecimal NormalizeAngle(in BigDecimal radians)
Parameters
Returns
Declaration
public static BigDecimal Parse(ReadOnlySpan<char> span, NumberStyles style, IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| ReadOnlySpan<System.Char> |
span |
|
| NumberStyles |
style |
|
| System.Nullable<IFormatProvider> |
provider |
|
Returns
Declaration
public static BigDecimal Parse(ReadOnlySpan<char> span, IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| ReadOnlySpan<System.Char> |
span |
|
| System.Nullable<IFormatProvider> |
provider |
|
Returns
Parse(String)
More convenient version of Parse().
Declaration
public static BigDecimal Parse(string str)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
Returns
Declaration
public static BigDecimal Parse(string str, NumberStyles style, IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
| NumberStyles |
style |
|
| System.Nullable<IFormatProvider> |
provider |
|
Returns
Declaration
public static BigDecimal Parse(string strBigDecimal, IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.String |
strBigDecimal |
|
| System.Nullable<IFormatProvider> |
provider |
|
Returns
Pow(BigDecimal, BigDecimal)
Calculate the value of x^y where x and y are both BigDecimal values.
Declaration
public static BigDecimal Pow(BigDecimal x, BigDecimal y)
Parameters
Returns
| Type |
Description |
| BigDecimal |
The result of the calculation, rounded off to the current value of
MaxSigFigs.
|
RootN(BigDecimal, Int32)
Declaration
public static BigDecimal RootN(BigDecimal x, int n)
Parameters
Returns
Round(BigDecimal, MidpointRounding)
Declaration
public static BigDecimal Round(BigDecimal x, MidpointRounding mode)
Parameters
| Type |
Name |
Description |
| BigDecimal |
x |
|
| MidpointRounding |
mode |
|
Returns
Round(BigDecimal, Int32, MidpointRounding)
Declaration
public static BigDecimal Round(BigDecimal x, int digits = 0, MidpointRounding mode = null)
Parameters
| Type |
Name |
Description |
| BigDecimal |
x |
|
| System.Int32 |
digits |
|
| MidpointRounding |
mode |
|
Returns
RoundSigFigs(BigDecimal, Nullable<Int32>, MidpointRounding)
Round off a value to a certain number of significant figures.
Declaration
public static BigDecimal RoundSigFigs(BigDecimal x, int? maxSigFigs = null, MidpointRounding mode = null)
Parameters
| Type |
Name |
Description |
| BigDecimal |
x |
|
| System.Nullable<System.Int32> |
maxSigFigs |
|
| MidpointRounding |
mode |
|
Returns
Sin(BigDecimal)
Declaration
public static BigDecimal Sin(BigDecimal x)
Parameters
Returns
SinCos(BigDecimal)
Declaration
public static (BigDecimal Sin, BigDecimal Cos) SinCos(BigDecimal x)
Parameters
Returns
SinCosPi(BigDecimal)
Declaration
public static (BigDecimal SinPi, BigDecimal CosPi) SinCosPi(BigDecimal x)
Parameters
Returns
Sinh(BigDecimal)
Declaration
public static BigDecimal Sinh(BigDecimal x)
Parameters
Returns
SinPi(BigDecimal)
Declaration
public static BigDecimal SinPi(BigDecimal x)
Parameters
Returns
Sqr(BigDecimal)
Calculate the square of a number.
Declaration
public static BigDecimal Sqr(BigDecimal x)
Parameters
Returns
| Type |
Description |
| BigDecimal |
The square of the argument.
|
Sqrt(BigDecimal)
Calculate the square root of a real number.
Declaration
public static BigDecimal Sqrt(BigDecimal x)
Parameters
Returns
| Type |
Description |
| BigDecimal |
The square root of the number.
|
Tan(BigDecimal)
Declaration
public static BigDecimal Tan(BigDecimal x)
Parameters
Returns
Tanh(BigDecimal)
Declaration
public static BigDecimal Tanh(BigDecimal x)
Parameters
Returns
TanPi(BigDecimal)
Declaration
public static BigDecimal TanPi(BigDecimal x)
Parameters
Returns
Declaration
public bool ToBoolean(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Boolean |
|
Declaration
public byte ToByte(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Byte |
|
Declaration
public char ToChar(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Char |
|
Declaration
public DateTime ToDateTime(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| DateTime |
|
Declaration
public decimal ToDecimal(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Decimal |
|
Declaration
public double ToDouble(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Double |
|
Declaration
public short ToInt16(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Int16 |
|
Declaration
public int ToInt32(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Int32 |
|
Declaration
public long ToInt64(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Int64 |
|
Declaration
public sbyte ToSByte(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.SByte |
|
Declaration
public float ToSingle(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Single |
|
ToString()
Declaration
public override string ToString()
Returns
| Type |
Description |
| System.String |
|
Declaration
public string ToString(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.String |
|
Format the BigDecimal as a string.
Supported formats are the usual: D, E, F, G, N, P, and R.
https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
Although "D" is normally only used by integral types, in this case both the significand and
exponent will be formatted as integers.
An secondary code "U" is provided, which follows the precision (if given).
- If omitted, the exponent (if present) will be formatted with the usual E[-+]999 format.
- If present, the exponent is formatted with "×10" instead of "E" and the exponent digits
will be rendered as superscript. Also, a "+" sign is not used for positive exponents,
and the exponent digits are not zero-padded.
Example: "E7U" will format as per usual (E with 7 decimal digits), except using Unicode
characters for the exponent part.
Codes "R" and "D" will produce the same output. However, the Unicode flag is undefined with
"R", because Parse() doesn't support superscript exponents.
Declaration
public string ToString(string? specifier, IFormatProvider? provider = null)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.String> |
specifier |
The format specifier (default "G").
|
| System.Nullable<IFormatProvider> |
provider |
The format provider (default null).
|
Returns
| Type |
Description |
| System.String |
The formatted string.
|
Declaration
public object ToType(Type conversionType, IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| Type |
conversionType |
|
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Object |
|
Declaration
public ushort ToUInt16(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.UInt16 |
|
Declaration
public uint ToUInt32(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.UInt32 |
|
Declaration
public ulong ToUInt64(IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.UInt64 |
|
Truncate(BigDecimal)
Declaration
public static BigDecimal Truncate(BigDecimal x)
Parameters
Returns
TryConvertFromChecked<TOther>(TOther, out BigDecimal)
Declaration
public static bool TryConvertFromChecked<TOther>(TOther value, out BigDecimal result)
where TOther : INumberBase<TOther>
Parameters
| Type |
Name |
Description |
| TOther |
value |
|
| BigDecimal |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Type Parameters
TryConvertFromSaturating<TOther>(TOther, out BigDecimal)
Declaration
public static bool TryConvertFromSaturating<TOther>(TOther value, out BigDecimal result)
where TOther : INumberBase<TOther>
Parameters
| Type |
Name |
Description |
| TOther |
value |
|
| BigDecimal |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Type Parameters
TryConvertFromTruncating<TOther>(TOther, out BigDecimal)
Declaration
public static bool TryConvertFromTruncating<TOther>(TOther value, out BigDecimal result)
where TOther : INumberBase<TOther>
Parameters
| Type |
Name |
Description |
| TOther |
value |
|
| BigDecimal |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Type Parameters
TryConvertToChecked<TOther>(BigDecimal, out TOther)
Declaration
public static bool TryConvertToChecked<TOther>(BigDecimal value, out TOther result)
where TOther : INumberBase<TOther>
Parameters
| Type |
Name |
Description |
| BigDecimal |
value |
|
| TOther |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Type Parameters
TryConvertToSaturating<TOther>(BigDecimal, out TOther)
Declaration
public static bool TryConvertToSaturating<TOther>(BigDecimal value, out TOther result)
where TOther : INumberBase<TOther>
Parameters
| Type |
Name |
Description |
| BigDecimal |
value |
|
| TOther |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Type Parameters
TryConvertToTruncating<TOther>(BigDecimal, out TOther)
Declaration
public static bool TryConvertToTruncating<TOther>(BigDecimal value, out TOther result)
where TOther : INumberBase<TOther>
Parameters
| Type |
Name |
Description |
| BigDecimal |
value |
|
| TOther |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Type Parameters
Declaration
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
| Type |
Name |
Description |
| Span<System.Char> |
destination |
|
| System.Int32 |
charsWritten |
|
| ReadOnlySpan<System.Char> |
format |
|
| System.Nullable<IFormatProvider> |
provider |
|
Returns
| Type |
Description |
| System.Boolean |
|
Declaration
public static bool TryParse(ReadOnlySpan<char> span, NumberStyles style, IFormatProvider? provider, out BigDecimal result)
Parameters
| Type |
Name |
Description |
| ReadOnlySpan<System.Char> |
span |
|
| NumberStyles |
style |
|
| System.Nullable<IFormatProvider> |
provider |
|
| BigDecimal |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Declaration
public static bool TryParse(ReadOnlySpan<char> span, IFormatProvider? provider, out BigDecimal result)
Parameters
| Type |
Name |
Description |
| ReadOnlySpan<System.Char> |
span |
|
| System.Nullable<IFormatProvider> |
provider |
|
| BigDecimal |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
TryParse(Nullable<String>, out BigDecimal)
More convenient version of TryParse().
Declaration
public static bool TryParse(string? str, out BigDecimal result)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.String> |
str |
|
| BigDecimal |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Declaration
public static bool TryParse(string? str, NumberStyles style, IFormatProvider? provider, out BigDecimal result)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.String> |
str |
|
| NumberStyles |
style |
|
| System.Nullable<IFormatProvider> |
provider |
|
| BigDecimal |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
Declaration
public static bool TryParse(string? str, IFormatProvider? provider, out BigDecimal result)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.String> |
str |
|
| System.Nullable<IFormatProvider> |
provider |
|
| BigDecimal |
result |
|
Returns
| Type |
Description |
| System.Boolean |
|
TryWriteExponentBigEndian(Span<Byte>, out Int32)
Declaration
public bool TryWriteExponentBigEndian(Span<byte> destination, out int bytesWritten)
Parameters
| Type |
Name |
Description |
| Span<System.Byte> |
destination |
|
| System.Int32 |
bytesWritten |
|
Returns
| Type |
Description |
| System.Boolean |
|
TryWriteExponentLittleEndian(Span<Byte>, out Int32)
Declaration
public bool TryWriteExponentLittleEndian(Span<byte> destination, out int bytesWritten)
Parameters
| Type |
Name |
Description |
| Span<System.Byte> |
destination |
|
| System.Int32 |
bytesWritten |
|
Returns
| Type |
Description |
| System.Boolean |
|
TryWriteSignificandBigEndian(Span<Byte>, out Int32)
Declaration
public bool TryWriteSignificandBigEndian(Span<byte> destination, out int bytesWritten)
Parameters
| Type |
Name |
Description |
| Span<System.Byte> |
destination |
|
| System.Int32 |
bytesWritten |
|
Returns
| Type |
Description |
| System.Boolean |
|
TryWriteSignificandLittleEndian(Span<Byte>, out Int32)
Declaration
public bool TryWriteSignificandLittleEndian(Span<byte> destination, out int bytesWritten)
Parameters
| Type |
Name |
Description |
| Span<System.Byte> |
destination |
|
| System.Int32 |
bytesWritten |
|
Returns
| Type |
Description |
| System.Boolean |
|
Operators
Addition(BigDecimal, BigDecimal)
Declaration
public static BigDecimal operator +(BigDecimal a, BigDecimal b)
Parameters
Returns
Decrement(BigDecimal)
Declaration
public static BigDecimal operator --(BigDecimal bd)
Parameters
Returns
Division(BigDecimal, BigDecimal)
Declaration
public static BigDecimal operator /(BigDecimal a, BigDecimal b)
Parameters
Returns
Equality(BigDecimal, BigDecimal)
Declaration
public static bool operator ==(BigDecimal x, BigDecimal y)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Explicit(BigRational to BigDecimal)
Explicit cast from BigRational to BigDecimal.
This cast operation has to be explicit as there could be loss of information due to the
limit on the number of significant figures in the result of the division.
Declaration
public static explicit operator BigDecimal(BigRational n)
Parameters
| Type |
Name |
Description |
| BigRational |
n |
|
Returns
Explicit(BigDecimal to BigInteger)
Explicit cast from BigDecimal to BigInteger.
Declaration
public static explicit operator BigInteger(BigDecimal bd)
Parameters
Returns
| Type |
Description |
| BigInteger |
|
Explicit(BigDecimal to Half)
Explicit cast from BigDecimal to Half.
BigDecimal doesn't use a default precision for the "E" format specifier, so all digits will
be rendered in the call to ToString(). This will produce the closest matching Half possible.
This method will not throw an OverflowException, but will return ±∞ for a value outside the
valid range for Half.
Declaration
public static explicit operator Half(BigDecimal bd)
Parameters
Returns
Explicit(BigDecimal to Int128)
Explicit cast from BigDecimal to Int128.
Declaration
public static explicit operator Int128(BigDecimal bd)
Parameters
Returns
Explicit(BigDecimal to Byte)
Explicit cast from BigDecimal to byte.
Declaration
public static explicit operator byte (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.Byte |
|
Explicit(BigDecimal to Decimal)
Explicit cast from BigDecimal to decimal.
Declaration
public static explicit operator decimal (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.Decimal |
|
Explicit(BigDecimal to Double)
Explicit cast from BigDecimal to double.
BigDecimal doesn't use a default precision for the "E" format specifier, so all digits will
be rendered in the call to ToString(). This will produce the closest matching double
possible.
This method will not throw an OverflowException, but will return ±∞ for a value outside the
valid range for double.
Declaration
public static explicit operator double (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.Double |
|
Explicit(BigDecimal to Int16)
Explicit cast from BigDecimal to short.
Declaration
public static explicit operator short (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.Int16 |
|
Explicit(BigDecimal to Int32)
Explicit cast from BigDecimal to int.
Declaration
public static explicit operator int (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.Int32 |
|
Explicit(BigDecimal to Int64)
Explicit cast from BigDecimal to long.
Declaration
public static explicit operator long (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.Int64 |
|
Explicit(BigDecimal to SByte)
Explicit cast from BigDecimal to sbyte.
Declaration
public static explicit operator sbyte (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.SByte |
|
Explicit(BigDecimal to Single)
Explicit cast from BigDecimal to float.
(I implemented a method to do this using maths and bits, but it takes much longer.)
BigDecimal doesn't use a default precision for the "E" format specifier, so all digits will
be rendered in the call to ToString(). This will produce the closest matching float
possible.
This method will not throw an OverflowException, but will return ±∞ for a value outside the
valid range for float.
Declaration
public static explicit operator float (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.Single |
|
Explicit(BigDecimal to UInt16)
Explicit cast from BigDecimal to ushort.
Declaration
public static explicit operator ushort (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.UInt16 |
|
Explicit(BigDecimal to UInt32)
Explicit cast from BigDecimal to uint.
Declaration
public static explicit operator uint (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.UInt32 |
|
Explicit(BigDecimal to UInt64)
Explicit cast from BigDecimal to ulong.
Declaration
public static explicit operator ulong (BigDecimal bd)
Parameters
Returns
| Type |
Description |
| System.UInt64 |
|
Explicit(BigDecimal to UInt128)
Explicit cast from BigDecimal to UInt128.
Declaration
public static explicit operator UInt128(BigDecimal bd)
Parameters
Returns
GreaterThan(BigDecimal, BigDecimal)
Declaration
public static bool operator>(BigDecimal x, BigDecimal y)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
GreaterThanOrEqual(BigDecimal, BigDecimal)
Declaration
public static bool operator >=(BigDecimal x, BigDecimal y)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Implicit(BigInteger to BigDecimal)
Implicit cast from BigInteger to BigDecimal.
Declaration
public static implicit operator BigDecimal(BigInteger n)
Parameters
| Type |
Name |
Description |
| BigInteger |
n |
The BigInteger value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(BigDecimal to BigRational)
Implicit cast from BigDecimal to BigRational.
This cast operation can be implicit because it can be done exactly, without loss of
information, due to the use of BigIntegers inside BigRational.
Declaration
public static implicit operator BigRational(BigDecimal n)
Parameters
Returns
| Type |
Description |
| BigRational |
|
Implicit(Half to BigDecimal)
Implicit cast from Half to BigDecimal.
NB: The resulting BigDecimal value is exactly the value encoded by the Half.
However, since Halfs only approximate decimal values, it's possible that only the first few
digits are valid in terms of the intended value.
Therefore, you may need to use RoundSigFigs() to get the value you really want.
Declaration
public static implicit operator BigDecimal(Half n)
Parameters
| Type |
Name |
Description |
| Half |
n |
|
Returns
Implicit(Int128 to BigDecimal)
Implicit cast from Int128 to BigDecimal.
Declaration
public static implicit operator BigDecimal(Int128 n)
Parameters
| Type |
Name |
Description |
| Int128 |
n |
The Int128 value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(Byte to BigDecimal)
Implicit cast from byte to BigDecimal.
Declaration
public static implicit operator BigDecimal(byte n)
Parameters
| Type |
Name |
Description |
| System.Byte |
n |
The byte value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(Decimal to BigDecimal)
Implicit cast from decimal to BigDecimal.
The cast is implicit because any decimal value can be cast to a BigDecimal exactly, without
loss of information. However, rounding off using Round() or RoundSigFigs() can cause
information loss.
We don't need to use Parse() or division operations here, because the base is decimal.
We can just extract the parts of the decimal from the bits and construct a BigDecimal from
those. This method should be faster than using ToString() and Parse().
Declaration
public static implicit operator BigDecimal(decimal n)
Parameters
| Type |
Name |
Description |
| System.Decimal |
n |
|
Returns
Implicit(Double to BigDecimal)
Implicit cast from double to BigDecimal.
NB: The resulting BigDecimal value is exactly the value encoded by the double.
However, since doubles only approximate decimal values, it's possible that only the first
15-17 digits are valid in terms of the intended value.
Therefore, you may need to use RoundSigFigs() to get the value you really want, e.g.
BigDecimal bd = BigDecimal.RoundSigFigs(1.2345, DoubleMaxSigFigs);
Declaration
public static implicit operator BigDecimal(double n)
Parameters
| Type |
Name |
Description |
| System.Double |
n |
|
Returns
Implicit(Int16 to BigDecimal)
Implicit cast from short to BigDecimal.
Declaration
public static implicit operator BigDecimal(short n)
Parameters
| Type |
Name |
Description |
| System.Int16 |
n |
The short value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(Int32 to BigDecimal)
Implicit cast from int to BigDecimal.
Declaration
public static implicit operator BigDecimal(int n)
Parameters
| Type |
Name |
Description |
| System.Int32 |
n |
The int value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(Int64 to BigDecimal)
Implicit cast from long to BigDecimal.
Declaration
public static implicit operator BigDecimal(long n)
Parameters
| Type |
Name |
Description |
| System.Int64 |
n |
The long value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(SByte to BigDecimal)
Implicit cast from sbyte to BigDecimal.
Declaration
public static implicit operator BigDecimal(sbyte n)
Parameters
| Type |
Name |
Description |
| System.SByte |
n |
The sbyte value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(Single to BigDecimal)
Implicit cast from float to BigDecimal.
NB: The resulting BigDecimal value is exactly the value encoded by the float.
However, since floats only approximate decimal values, it's possible that only the first 6-9
digits are valid in terms of the intended value.
Therefore, you may need to use RoundSigFigs() to get the value you really want, e.g.
BigDecimal bd = BigDecimal.RoundSigFigs(1.2345f, FloatMaxSigFigs);
Declaration
public static implicit operator BigDecimal(float n)
Parameters
| Type |
Name |
Description |
| System.Single |
n |
|
Returns
Implicit(UInt16 to BigDecimal)
Implicit cast from ushort to BigDecimal.
Declaration
public static implicit operator BigDecimal(ushort n)
Parameters
| Type |
Name |
Description |
| System.UInt16 |
n |
The ushort value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(UInt32 to BigDecimal)
Implicit cast from uint to BigDecimal.
Declaration
public static implicit operator BigDecimal(uint n)
Parameters
| Type |
Name |
Description |
| System.UInt32 |
n |
The uint value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(UInt64 to BigDecimal)
Implicit cast from ulong to BigDecimal.
Declaration
public static implicit operator BigDecimal(ulong n)
Parameters
| Type |
Name |
Description |
| System.UInt64 |
n |
The ulong value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Implicit(UInt128 to BigDecimal)
Implicit cast from UInt128 to BigDecimal.
Declaration
public static implicit operator BigDecimal(UInt128 n)
Parameters
| Type |
Name |
Description |
| UInt128 |
n |
The UInt128 value.
|
Returns
| Type |
Description |
| BigDecimal |
The equivalent BigDecimal value.
|
Increment(BigDecimal)
Declaration
public static BigDecimal operator ++(BigDecimal bd)
Parameters
Returns
Inequality(BigDecimal, BigDecimal)
Declaration
public static bool operator !=(BigDecimal x, BigDecimal y)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
LessThan(BigDecimal, BigDecimal)
Declaration
public static bool operator <(BigDecimal x, BigDecimal y)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
LessThanOrEqual(BigDecimal, BigDecimal)
Declaration
public static bool operator <=(BigDecimal x, BigDecimal y)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Modulus(BigDecimal, BigDecimal)
Declaration
public static BigDecimal operator %(BigDecimal a, BigDecimal b)
Parameters
Returns
Multiply(BigDecimal, BigDecimal)
Declaration
public static BigDecimal operator *(BigDecimal a, BigDecimal b)
Parameters
Returns
Subtraction(BigDecimal, BigDecimal)
Declaration
public static BigDecimal operator -(BigDecimal a, BigDecimal b)
Parameters
Returns
UnaryNegation(BigDecimal)
Declaration
public static BigDecimal operator -(BigDecimal bd)
Parameters
Returns
UnaryPlus(BigDecimal)
Declaration
public static BigDecimal operator +(BigDecimal bd)
Parameters
Returns
Implements
IConvertible
IFloatingPoint<>
IPowerFunctions<>
IRootFunctions<>
IExponentialFunctions<>
ILogarithmicFunctions<>
ICloneable
ITrigonometricFunctions<>
IHyperbolicFunctions<>