IntegerExtensionMethods
Extension methods for various integer types.
Methods
Create an array from this integer to another.
public static BigInteger[] ArrayTo()
this BigInteger
index0,
Inclusive starting number.
index1,
Exclusive ending number.
stepSize
Step size between entries.
Returns: Array from a to b, as the stepsize allows.
Create an array from this integer to another.
Returns: Array from a to b, as the stepsize allows.
Create an array from this integer to another.
Returns: Array from a to b.
Create an array from this integer to another.
Returns: Array from a to b, as the stepsize allows.
Create an array from this integer to another.
Returns: Array from a to (but no including) b.
Compute the mean (average) of a collection of integers. This method is designed to work with a large number of integers or very large integers. Essentially, if you're certain that the sum of all values doesn't exceed Int32.MaxValue, there are faster ways to compute the average.
Returns: Average of all integers.
Limit an integer to a range.
Returns: Clipped integer.
Limit an integer to a range.
Returns: Clipped integer.
Limit an integer to a range.
Returns: Clipped integer.
Limit an integer to a range.
Returns: Clipped integer.
Returns the number of digits of a BigInteger value, ignoring any sign.
Read off the logarithm rather than from an expansion, so it costs a few microseconds no matter how large the value is. Only a logarithm which lands within rounding distance of a whole number has to be settled exactly, which is to say only a value within a hair of a power of ten.
Count the number of base-10 digits required to represent this number. Note that this does not include the sign.
Divide two big integers to yield a decimal floating point result. This method is slow but generally speaking more accurate than converting the big integer into doubles prior to division.
Attempt to continue an array of integers.
Returns: Best guess for next number in sequence.
Determine whether an array of integers contains repeating elements. the last iteration of the cycle may be incomplete.
Returns: Length of cycle or 0 if no cycle could be found.
Determine whether an array of integers contains repeating elements. the last iteration of the cycle may be incomplete.
Returns: Length of cycle or 0 if no cycle could be found.
Halves the value and rounds to the nearest whole number.
Returns: Half the integer.
Gets the highest number in an array.
Returns: Highest integer in the set.
Interpolate between two BigInteger instances.
Gets the lowest number in an array.
Returns: Lowest integer in the set.
Apply an indexing map.
Returns: Mapped index, or original index if a mapping is not possible.
Enumerate from the current integer to a target integer.
public static IEnumerable<int> MarchTo()
this int
index0,
Inclusive start integer.
index1,
Exclusive end integer.
stepSize
Size of each marching step.
Returns: Enumerator between two integers.
Enumerate from the current integer to a target integer.
Returns: Enumerator from a to (but not including) b.
Enumerate from the current integer to a target integer.
public static IEnumerable<long> MarchTo()
this long
index0,
Inclusive start integer.
index1,
Inclusive end integer.
stepSize
Size of each marching step.
Returns: Enumerator between two integers.
Enumerate from the current integer to a target integer.
Returns: Enumerator from a to b.
Get the ordinal suffix ("st", "nd", "rd", or "th") for an integer.
Same as Simplify(BigInteger), except it returns success and output the 32-bit integer.
Either returns the integer itself, or an System.Int32 instance if the conversion is possible. This method is handy for storing BigIntegers into NumberLikeParameter.
Create a difference array. This array contains all the values that need to be added to the elements in the original array in order to yield the next element. The difference array will be one element shorter.
Returns: Difference array.
Convert this integer to english words.
Convert an integer into an ordinal (first, second, third etc). Integers up to and including 12 are given full words, integers beyond that magnitude are kept as digits with trailing 'st', 'nd', 'rd', 'th' suffixes.
Returns: Ordinal numeral.
Format a 128-bit Guid using Grasshopper code replacements.
Convert an integer to a roman numeral. Only integers between 1 and 3999 are supported, integers outside of that range are returned as arabic numerals.
Returns: String representing the number as a roman numeral if possible.
Format a big integer for reading rather than for round tripping. A value of no more than
fullDigits digits is written out in full; a longer one is cut to its headDigits leading digits, followed by a count of the digits left out.public static string ToShortString()
this BigInteger
value,
Value to format.
fullDigits = 20,
Length up to which the value is written out in full.
headDigits = 10
Leading digits to keep once it is not.
Converts a BigInteger to its decimal string representation, checking
cancellationToken between chunks so very large values can be aborted without waiting for completion.