IntegerExtensionMethods
Extension methods for various integer types.
Methods
Create an array from this integer to another.
Parameters:
| index0 (BigInteger) | Inclusive starting number. |
| index1 (BigInteger) | Exclusive ending number. |
| stepSize (BigInteger) | Step size between entries. |
Returns: Array from a to b, as the stepsize allows.
Create an array from this integer to another.
Create an array from this integer to another.
Create an array from this integer to another.
Create an array from this integer to another.
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.
Parameters:
| integers (IEnumerable<int>) | Integer collection. |
Returns: Average of all integers.
Limit an integer to a range.
Limit an integer to a range.
Limit an integer to a range.
Limit an integer to a range.
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.
Parameters:
| integer (BigInteger) |
Count the number of base-10 digits required to represent this number. Note that this does not include the sign.
Parameters:
| integer (int) |
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.
Parameters:
| numerator (BigInteger) | |
| denominator (BigInteger) |
Attempt to continue an array of integers.
Parameters:
| array (int[]) | Sequence to extend. |
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.
Determine whether an array of integers contains repeating elements. the last iteration of the cycle may be incomplete.
Parameters:
| array (int[]) | Array to examine. |
Returns: Length of cycle or 0 if no cycle could be found.
Halves the value and rounds to the nearest whole number.
Parameters:
| integer (int) | Integer. |
Returns: Half the integer.
Gets the highest number in an array.
Parameters:
| integers (IEnumerable<int>) | Collection of integers. |
Returns: Highest integer in the set.
Interpolate between two BigInteger instances.
Parameters:
| from (BigInteger) | |
| to (BigInteger) | |
| factor (double) |
Gets the lowest number in an array.
Parameters:
| integers (IEnumerable<int>) | Collection of integers. |
Returns: Lowest integer in the set.
Apply an indexing map.
Parameters:
| map (IndexModifier) | Map to query. |
| index (int) | Index to modify. |
| length (int) | Length of collection. |
Returns: Mapped index, or original index if a mapping is not possible.
Enumerate from the current integer to a target integer.
Enumerate from the current integer to a target integer.
Enumerate from the current integer to a target integer.
Enumerate from the current integer to a target integer.
Get the ordinal suffix ("st", "nd", "rd", or "th") for an integer.
Parameters:
| integer (int) |
Same as Simplify(BigInteger), except it returns success and output the 32-bit integer.
Parameters:
| integer (BigInteger) | |
| thirtytwobit (out int) |
Either returns the integer itself, or an System.Int32 instance if the conversion is possible. This method is handy for storing BigIntegers into NumberLikeParameter.
Parameters:
| integer (BigInteger) |
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.
Parameters:
| array (int[]) | Array to operate on. |
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.
Parameters:
| integer (int) | Integer to convert. |
Returns: Ordinal numeral.
Format a 128-bit Guid using Grasshopper code replacements.
Parameters:
| id (Guid) |
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.
Parameters:
| integer (int) | Number to convert. |
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.Parameters:
| value (BigInteger) | Value to format. |
| fullDigits (int = 20) | Length up to which the value is written out in full. |
| headDigits (int = 10) | Leading digits to keep once it is not. |
public static string ToStringCancellable(this BigInteger value, CancellationToken cancellationToken)
Converts a BigInteger to its decimal string representation, checking
cancellationToken between chunks so very large values can be aborted without waiting for completion.Parameters:
| value (BigInteger) | |
| cancellationToken (CancellationToken) |
public static T With<T>(this T flags, T flag)
Add an enum flag.
Parameters:
| flags (T) | |
| flag (T) |