Class Int32Extensions
Extension methods for
Inheritance
Namespace: X10D.Math
Assembly: X10D.dll
Syntax
public static class Int32Extensions : object
Methods
| Improve this Doc View SourceCountDigits(Int32)
Returns the number of digits in the current 32-bit signed integer.
Declaration
public static int CountDigits(this int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value whose digit count to compute. |
Returns
Type | Description |
---|---|
System.Int32 | The number of digits in |
DigitalRoot(Int32)
Computes the digital root of this 32-bit integer.
Declaration
public static int DigitalRoot(this int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value whose digital root to compute. |
Returns
Type | Description |
---|---|
System.Int32 | The digital root of |
Remarks
The digital root is defined as the recursive sum of digits until that result is a single digit.
For example, the digital root of 239 is 5: 2 + 3 + 9 = 14
, then 1 + 4 = 5
.
Factorial(Int32)
Returns the factorial of the current 32-bit signed integer.
Declaration
public static long Factorial(this int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value whose factorial to compute. |
Returns
Type | Description |
---|---|
System.Int64 | The factorial of |
GreatestCommonFactor(Int32, Int32)
Calculates the greatest common factor between the current 32-bit signed integer, and another 32-bit signed integer.
Declaration
public static int GreatestCommonFactor(this int value, int other)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The first value. |
System.Int32 | other | The second value. |
Returns
Type | Description |
---|---|
System.Int32 | The greatest common factor between |
IsEven(Int32)
Returns a value indicating whether the current value is evenly divisible by 2.
Declaration
public static bool IsEven(this int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value whose parity to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
IsOdd(Int32)
Returns a value indicating whether the current value is not evenly divisible by 2.
Declaration
public static bool IsOdd(this int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value whose parity to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
IsPrime(Int32)
Returns a value indicating whether the current value is a prime number.
Declaration
public static bool IsPrime(this int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value whose primality to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
LowestCommonMultiple(Int32, Int32)
Calculates the lowest common multiple between the current 32-bit signed integer, and another 32-bit signed integer.
Declaration
public static int LowestCommonMultiple(this int value, int other)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The first value. |
System.Int32 | other | The second value. |
Returns
Type | Description |
---|---|
System.Int32 | The lowest common multiple between |
Mod(Int32, Int32)
Performs a modulo operation which supports a negative dividend.
Declaration
public static int Mod(this int dividend, int divisor)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dividend | The dividend. |
System.Int32 | divisor | The divisor. |
Returns
Type | Description |
---|---|
System.Int32 | The result of |
Remarks
The %
operator (commonly called the modulo operator) in C# is not defined to be modulo, but is instead
remainder. This quirk inherently makes it difficult to use modulo in a negative context, as x % y
where x is
negative will return a negative value, akin to -(x % y)
, even if precedence is forced. This method provides a
modulo operation which supports negative dividends.
MultiplicativePersistence(Int32)
Returns the multiplicative persistence of a specified value.
Declaration
public static int MultiplicativePersistence(this int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value whose multiplicative persistence to calculate. |
Returns
Type | Description |
---|---|
System.Int32 | The multiplicative persistence. |
Remarks
Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
Sign(Int32)
Returns an integer that indicates the sign of this 32-bit signed integer.
Declaration
public static int Sign(this int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | A signed number. |
Returns
Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
System.Int32 | A number that indicates the sign of
|
Wrap(Int32, Int32)
Wraps the current 32-bit signed integer between 0 and a high value.
Declaration
public static int Wrap(this int value, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value to wrap. |
System.Int32 | length | The exclusive upper bound. |
Returns
Type | Description |
---|---|
System.Int32 | The wrapped value. |
Wrap(Int32, Int32, Int32)
Wraps the current 32-bit signed integer between a low and a high value.
Declaration
public static int Wrap(this int value, int low, int high)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value to wrap. |
System.Int32 | low | The inclusive lower bound. |
System.Int32 | high | The exclusive upper bound. |
Returns
Type | Description |
---|---|
System.Int32 | The wrapped value. |