MathLib Docs MathLib Docs
MathLib Docs MathLib Docs

Search Results for

    Edit this page

    Class BaseInt

    Represents an immutable base-specific integer of a fixed length, that supports zero-padding.

    Inheritance
    object
    BaseInt
    Implements
    IEquatable<BaseInt>
    IComparable<BaseInt>
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    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 Source

    BaseInt(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 intValue in the given base.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    Thrown when the integer value is negative or the base is less than 2.

    ArgumentOutOfRangeException

    Thrown when an explicit length is specified that is less than minimum required length of intValue (in the given base).

    Properties

    | Edit this page View Source

    Base

    Gets the base of the BaseInt.

    Declaration
    public int Base { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    First

    Gets the first (most significant) coefficient.

    Declaration
    public int First { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    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.

    | Edit this page View Source

    IsZero

    Indicates whether the BaseInt is zero.

    Declaration
    public bool IsZero { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    Last

    Gets the last (least significant) coefficient.

    Declaration
    public int Last { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    Length

    Gets the length of the BaseInt.

    Declaration
    public int Length { get; }
    Property Value
    Type Description
    int

    Methods

    | Edit this page View Source

    Append(BaseInt)

    Declaration
    public BaseInt Append(BaseInt right)
    Parameters
    Type Name Description
    BaseInt right
    Returns
    Type Description
    BaseInt
    | Edit this page View Source

    AssertSameBaseAs(BaseInt)

    Asserts that the current BaseInt has the same base as the specified 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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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:

    Value Meaning
    Less than zero This instance precedes other in the sort order.
    Zero This instance occurs in the same position in the sort order as other.
    Greater than zero This instance follows other in the sort order.
    | Edit this page View Source

    Concatenation(BaseInt, BaseInt)

    Declaration
    public static BaseInt Concatenation(BaseInt left, BaseInt right)
    Parameters
    Type Name Description
    BaseInt left
    BaseInt right
    Returns
    Type Description
    BaseInt
    | Edit this page View Source

    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 other parameter; otherwise, false.

    | Edit this page View Source

    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
    object.Equals(object)
    | Edit this page View Source

    GetHashCode()

    Serves as the default hash function.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    A hash code for the current object.

    Overrides
    object.GetHashCode()
    | Edit this page View Source

    PadLeftExtra(int)

    Declaration
    public BaseInt PadLeftExtra(int zeros)
    Parameters
    Type Name Description
    int zeros
    Returns
    Type Description
    BaseInt
    | Edit this page View Source

    PadRightExtra(int)

    Declaration
    public BaseInt PadRightExtra(int zeros)
    Parameters
    Type Name Description
    int zeros
    Returns
    Type Description
    BaseInt
    | Edit this page View Source

    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.

    | Edit this page View Source

    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
    | Edit this page View Source

    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
    object.ToString()
    | Edit this page View Source

    ToStringCoefficient()

    Declaration
    public string ToStringCoefficient()
    Returns
    Type Description
    string
    | Edit this page View Source

    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 Source

    operator +(BaseInt, BaseInt)

    Declaration
    public static BaseInt operator +(BaseInt left, BaseInt right)
    Parameters
    Type Name Description
    BaseInt left
    BaseInt right
    Returns
    Type Description
    BaseInt
    | Edit this page View Source

    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

    true iff the two BaseInt objects are equal.

    | Edit this page View Source

    operator >(BaseInt, BaseInt)

    Indicates whether the first BaseInt object is greater than the second BaseInt object.

    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 iff the first BaseInt object is greater than the second BaseInt object.

    | Edit this page View Source

    operator >=(BaseInt, BaseInt)

    Indicates whether the first BaseInt object is greater than or equal to the second BaseInt object.

    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 iff the first BaseInt object is greater than or equal to the second BaseInt object.

    | Edit this page View Source

    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

    true iff the two BaseInt objects are not equal.

    | Edit this page View Source

    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 shift positions.

    Remarks

    The length of the BaseInt is preserved.

    Positions vacated on the right are zero-padded.

    Coefficients truncated on the left are discarded.

    | Edit this page View Source

    operator <(BaseInt, BaseInt)

    Indicates whether the first BaseInt object is less than the second BaseInt object.

    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 iff the first BaseInt object is less than the second BaseInt object.

    | Edit this page View Source

    operator <=(BaseInt, BaseInt)

    Indicates whether the first BaseInt object is less than or equal to the second BaseInt object.

    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 iff the first BaseInt object is less than or equal to the second BaseInt object.

    | Edit this page View Source

    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 shift positions.

    Remarks

    The length of the BaseInt is preserved.

    Positions vacated on the left are zero-padded.

    Coefficients truncated on the right are discarded.

    | Edit this page View Source

    operator -(BaseInt, BaseInt)

    Declaration
    public static BaseInt operator -(BaseInt minuend, BaseInt subtrahend)
    Parameters
    Type Name Description
    BaseInt minuend
    BaseInt subtrahend
    Returns
    Type Description
    BaseInt

    Implements

    IEquatable<T>
    IComparable<T>