BigNumber
Definition
Namespace: Corvus.Numerics
Assembly: Corvus.Text.Json.dll
Source: BigNumber.cs
Represents an arbitrary-precision decimal number using a significand and exponent.
public readonly struct BigNumber : IEquatable<BigNumber>, IComparable<BigNumber>, IComparable, IFormattable, ISpanFormattable, IUtf8SpanFormattable, INumber<BigNumber>, IParsable<BigNumber>, ISpanParsable<BigNumber>, IAdditionOperators<BigNumber, BigNumber, BigNumber>, IAdditiveIdentity<BigNumber, BigNumber>, IComparisonOperators<BigNumber, BigNumber, bool>, IEqualityOperators<BigNumber, BigNumber, bool>, IDecrementOperators<BigNumber>, IDivisionOperators<BigNumber, BigNumber, BigNumber>, IIncrementOperators<BigNumber>, IModulusOperators<BigNumber, BigNumber, BigNumber>, IMultiplicativeIdentity<BigNumber, BigNumber>, IMultiplyOperators<BigNumber, BigNumber, BigNumber>, INumberBase<BigNumber>, IUtf8SpanParsable<BigNumber>, ISubtractionOperators<BigNumber, BigNumber, BigNumber>, IUnaryNegationOperators<BigNumber, BigNumber>, IUnaryPlusOperators<BigNumber, BigNumber>, ISignedNumber<BigNumber>
Remarks
Internally represented as: value = significand × 10^exponent where significand is a BigInteger and exponent is a Int32. This type provides equivalent functionality to Decimal but with arbitrary precision, similar to how BigInteger extends integer arithmetic beyond fixed sizes.
Implements
IEquatable<BigNumber>, IComparable<BigNumber>, IComparable, IFormattable, ISpanFormattable, IUtf8SpanFormattable, INumber<BigNumber>, IParsable<BigNumber>, ISpanParsable<BigNumber>, IAdditionOperators<BigNumber, BigNumber, BigNumber>, IAdditiveIdentity<BigNumber, BigNumber>, IComparisonOperators<BigNumber, BigNumber, bool>, IEqualityOperators<BigNumber, BigNumber, bool>, IDecrementOperators<BigNumber>, IDivisionOperators<BigNumber, BigNumber, BigNumber>, IIncrementOperators<BigNumber>, IModulusOperators<BigNumber, BigNumber, BigNumber>, IMultiplicativeIdentity<BigNumber, BigNumber>, IMultiplyOperators<BigNumber, BigNumber, BigNumber>, INumberBase<BigNumber>, IUtf8SpanParsable<BigNumber>, ISubtractionOperators<BigNumber, BigNumber, BigNumber>, IUnaryNegationOperators<BigNumber, BigNumber>, IUnaryPlusOperators<BigNumber, BigNumber>, ISignedNumber<BigNumber>
Constructors
| Constructor | Description |
|---|---|
| BigNumber(BigInteger, int) | Initializes a new instance of the BigNumber struct. |
Properties
| Property | Type | Description |
|---|---|---|
| Exponent | int |
Gets the exponent (power of 10) of the number. |
MinusOne static |
BigNumber |
Gets a value representing minus one. |
One static |
BigNumber |
Gets a value representing one. |
Radix static |
int |
Gets the radix (base) of the number system. |
| Significand | BigInteger |
Gets the significand of the number. |
Zero static |
BigNumber |
Gets a value representing zero. |
Methods
| Method | Description |
|---|---|
Abs(BigNumber) static |
Returns the absolute value. |
Ceiling(BigNumber) static |
Returns the smallest integer greater than or equal to the specified number. |
| CompareTo | Compares this instance with another BigNumber value. |
Divide(BigNumber, BigNumber, int) static |
Divides one BigNumber by another with specified precision. |
| Equals | Determines whether the specified BigNumber is equal to this instance. |
Floor(BigNumber) static |
Returns the largest integer less than or equal to the specified number. |
| GetHashCode() | Returns a hash code for this instance. |
| IsInteger() | Determines whether this instance represents an integer value. |
| Normalize() | Returns a normalized copy of this number with trailing zeros removed from the significand. |
Parse static |
Parses a string into a BigNumber. |
Pow(BigNumber, int) static |
Raises a BigNumber to an integer power. |
Round(BigNumber, int, MidpointRounding) static |
Rounds a value to a specified number of decimal places. |
Sign(BigNumber) static |
Returns the sign of the number. |
Sqrt(BigNumber, int) static |
Computes the square root of a BigNumber using Newton's method. |
| ToString | Returns the string representation of this BigNumber value. |
Truncate(BigNumber) static |
Truncates a value to an integer by removing the fractional part. |
| TryFormat | Tries to format this BigNumber value into the provided character span. |
| TryFormatOptimized(Span<char>, ref int, ReadOnlySpan<char>, IFormatProvider) | Tries to format this instance into the provided UTF-16 span with zero allocations. |
| TryFormatUtf8Optimized(Span<byte>, ref int, ReadOnlySpan<char>, IFormatProvider) | Tries to format this instance into the provided UTF-8 span with zero allocations. |
| TryGetMinimumFormatBufferLength(ref int) | Gets the minimum format buffer length. |
TryParse static |
Attempts to parse a string into a BigNumber. |
TryParseJsonUtf8(ReadOnlySpan<byte>, ref BigNumber) static |
Tries to parse a BigNumber from UTF-8 bytes in JSON format with zero allocations. |
Operators
| Operator | Description |
|---|---|
| operator +(BigNumber, BigNumber) | Adds two BigNumber values. |
| operator --(BigNumber) | Decrements a value by one. |
| operator /(BigNumber, BigNumber) | Divides one BigNumber by another with default precision. |
| operator ==(BigNumber, BigNumber) | Determines whether two BigNumber values are equal. |
| Explicit | Explicitly converts a BigNumber to a Decimal. |
| operator >(BigNumber, BigNumber) | Determines whether one value is greater than another. |
| operator >=(BigNumber, BigNumber) | Determines whether one value is greater than or equal to another. |
| Implicit | Converts an Int32 to a BigNumber. |
| operator ++(BigNumber) | Increments a value by one. |
| operator !=(BigNumber, BigNumber) | Determines whether two BigNumber values are not equal. |
| operator <(BigNumber, BigNumber) | Determines whether one value is less than another. |
| operator <=(BigNumber, BigNumber) | Determines whether one value is less than or equal to another. |
| operator %(BigNumber, BigNumber) | Computes the remainder of division. |
| operator *(BigNumber, BigNumber) | Multiplies two BigNumber values. |
| operator -(BigNumber, BigNumber) | Subtracts one BigNumber from another. |
| operator -(BigNumber) | Negates a value. |
| operator +(BigNumber) | Returns the value unchanged (unary plus). |
Applies To
| Product | Versions |
|---|---|
| .NET | 9, 10 |
| .NET Standard | 2.0, 2.1 |
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests.
Open an issue