Class BaseInt
Represents an immutable base-specific integer of a fixed length, that supports zero-padding.
Inherited Members
Namespace: MathLib
Assembly: MathLib.dll
Syntax
public class BaseInt : IEquatable<BaseInt>, IComparable<BaseInt>
Remarks
A BaseInt is fully defined by its integer value, base and length. Shifting and other operations are applied with respect to the specified base, and the length is preserved.
Constructors
| Edit this page View SourceBaseInt(int, BigInteger, int)
Initializes a new instance of the BaseInt struct.
Declaration
public BaseInt(int base_, BigInteger intValue, int length = -1)
Parameters
Type | Name | Description |
---|---|---|
int | base_ | The base of the BaseInt. |
BigInteger | intValue | The integer value. |
int | length | An optional length of the BaseInt. Default is the minimum required length of |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the integer value is negative or the base is less than 2. |
ArgumentOutOfRangeException | Thrown when an explicit |
Properties
| Edit this page View SourceBase
Gets the base of the BaseInt.
Declaration
public int Base { get; }
Property Value
Type | Description |
---|---|
int |
First
Gets the first (most significant) coefficient.
Declaration
public int First { get; }
Property Value
Type | Description |
---|---|
int |
IntValue
Integer value of the BaseInt in descending order.
Declaration
public BigInteger IntValue { get; }
Property Value
Type | Description |
---|---|
BigInteger |
Remarks
This value is always stored descending order, regardless of the base's natural order. This makes it compliant with arithmetic operations of the BigInteger type.
For ascending order, the value is reversed when the BaseInt is created.
IsZero
Indicates whether the BaseInt is zero.
Declaration
public bool IsZero { get; }
Property Value
Type | Description |
---|---|
bool |
Last
Gets the last (least significant) coefficient.
Declaration
public int Last { get; }
Property Value
Type | Description |
---|---|
int |
Length
Gets the length of the BaseInt.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceAppend(BaseInt)
Declaration
public BaseInt Append(BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | right |
Returns
Type | Description |
---|---|
BaseInt |
AssertSameBaseAs(BaseInt)
Declaration
public BaseInt AssertSameBaseAs(BaseInt other)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | other | The BaseInt to compare the base with. |
Returns
Type | Description |
---|---|
BaseInt | The current BaseInt if the bases are equal. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the bases are not equal. |
Coefficients()
Returns the coefficients in current base in descending order of significance.
Declaration
public IEnumerable<int> Coefficients()
Returns
Type | Description |
---|---|
IEnumerable<int> | An enumerable sequence of coefficients from most to least significant. |
CompareTo(BaseInt?)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
Declaration
public int CompareTo(BaseInt? other)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | other | An object to compare with this instance. |
Returns
Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
int | A value that indicates the relative order of the objects being compared. The return value has these meanings:
|
Concatenation(BaseInt, BaseInt)
Declaration
public static BaseInt Concatenation(BaseInt left, BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | left | |
BaseInt | right |
Returns
Type | Description |
---|---|
BaseInt |
Equals(BaseInt?)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(BaseInt? other)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
bool | true if the current object is equal to the |
Equals(object?)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
| Edit this page View SourceGetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
| Edit this page View SourcePadLeftExtra(int)
Declaration
public BaseInt PadLeftExtra(int zeros)
Parameters
Type | Name | Description |
---|---|---|
int | zeros |
Returns
Type | Description |
---|---|
BaseInt |
PadRightExtra(int)
Declaration
public BaseInt PadRightExtra(int zeros)
Parameters
Type | Name | Description |
---|---|---|
int | zeros |
Returns
Type | Description |
---|---|
BaseInt |
Reverse()
Returns a new BaseInt where the coefficients are reversed.
Declaration
public BaseInt Reverse()
Returns
Type | Description |
---|---|
BaseInt | A new BaseInt with reversed coefficients. |
Remarks
The coefficients are reversed such that the most significant becomes the least significant, and vice versa. As a result, the outputs of Coefficients() is reversed, compared to the original instance.
ReverseInt(int, BigInteger, int)
Declaration
public static BigInteger ReverseInt(int base_, BigInteger integer, int length)
Parameters
Type | Name | Description |
---|---|---|
int | base_ | |
BigInteger | integer | |
int | length |
Returns
Type | Description |
---|---|
BigInteger |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents the current object. |
Overrides
| Edit this page View SourceToStringCoefficient()
Declaration
public string ToStringCoefficient()
Returns
Type | Description |
---|---|
string |
Zero(int, int)
Declaration
public static BaseInt Zero(int base_, int zeroCount = 0)
Parameters
Type | Name | Description |
---|---|---|
int | base_ | |
int | zeroCount |
Returns
Type | Description |
---|---|
BaseInt |
Operators
| Edit this page View Sourceoperator +(BaseInt, BaseInt)
Declaration
public static BaseInt operator +(BaseInt left, BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | left | |
BaseInt | right |
Returns
Type | Description |
---|---|
BaseInt |
operator ==(BaseInt, BaseInt)
Indicates whether two BaseInt objects are equal.
Declaration
public static bool operator ==(BaseInt left, BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | left | The first BaseInt to compare. |
BaseInt | right | The second BaseInt to compare. |
Returns
Type | Description |
---|---|
bool |
operator >(BaseInt, BaseInt)
Declaration
public static bool operator >(BaseInt left, BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | left | The first BaseInt to compare. |
BaseInt | right | The second BaseInt to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator >=(BaseInt, BaseInt)
Declaration
public static bool operator >=(BaseInt left, BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | left | The first BaseInt to compare. |
BaseInt | right | The second BaseInt to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator !=(BaseInt, BaseInt)
Indicates whether two BaseInt objects are not equal.
Declaration
public static bool operator !=(BaseInt left, BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | left | The first BaseInt to compare. |
BaseInt | right | The second BaseInt to compare. |
Returns
Type | Description |
---|---|
bool |
operator <<(BaseInt, int)
Shifts the BaseInt left by the specified number of positions.
Declaration
public static BaseInt operator <<(BaseInt baseInt, int shift)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | baseInt | The BaseInt to shift. |
int | shift | The number of positions to shift. |
Returns
Type | Description |
---|---|
BaseInt | A new BaseInt shifted left by |
Remarks
The length of the BaseInt is preserved.
Positions vacated on the right are zero-padded.Coefficients truncated on the left are discarded.
operator <(BaseInt, BaseInt)
Declaration
public static bool operator <(BaseInt left, BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | left | The first BaseInt to compare. |
BaseInt | right | The second BaseInt to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator <=(BaseInt, BaseInt)
Declaration
public static bool operator <=(BaseInt left, BaseInt right)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | left | The first BaseInt to compare. |
BaseInt | right | The second BaseInt to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator >>(BaseInt, int)
Shifts the BaseInt right by the specified number of positions.
Declaration
public static BaseInt operator >>(BaseInt baseInt, int shift)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | baseInt | The BaseInt to shift. |
int | shift | The number of positions to shift. |
Returns
Type | Description |
---|---|
BaseInt | A new BaseInt shifted right by |
Remarks
The length of the BaseInt is preserved.
Positions vacated on the left are zero-padded.
Coefficients truncated on the right are discarded.
operator -(BaseInt, BaseInt)
Declaration
public static BaseInt operator -(BaseInt minuend, BaseInt subtrahend)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | minuend | |
BaseInt | subtrahend |
Returns
Type | Description |
---|---|
BaseInt |