Class XNumber
Extension methods for numbers (INumber{T} and INumberBase{T}).
Inheritance
System.Object
XNumber
Assembly: Galaxon.Core.dll
Syntax
public static class XNumber : object
Methods
Div<T>(T, T)
Corrected integer division operation.
Declaration
public static T Div<T>(T a, T b)
where T : INumberBase<T>, IModulusOperators<T, T, T>, IComparisonOperators<T, T, bool>
Parameters
| Type |
Name |
Description |
| T |
a |
|
| T |
b |
|
Returns
Type Parameters
DivMod<T>(T, T)
Integer division and modulo operation using floored division.
The modulus will always have the same sign as the divisor.
Unlike the truncated division and modulo provided by C#'s operators, floored division
produces a regular cycling pattern through both negative and positive values of the divisor.
It permits things like:
bool isOdd = Mod(num, 2) == 1;
Trying to do this using the % operator will fail for negative divisors, however. e.g.
bool isOdd = num % 2 == 1;
In this case, if num is negative 0, num % 2 == -1
Declaration
public static (T div, T mod) DivMod<T>(T a, T b)
where T : INumberBase<T>, IModulusOperators<T, T, T>, IComparisonOperators<T, T, bool>
Parameters
| Type |
Name |
Description |
| T |
a |
|
| T |
b |
|
Returns
| Type |
Description |
| System.ValueTuple<T, T> |
|
Type Parameters
Implements(Object, Type)
Check if a type implements a generic interface.
Declaration
public static bool Implements(object obj, Type genericInterface)
Parameters
| Type |
Name |
Description |
| System.Object |
obj |
|
| Type |
genericInterface |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsComplex(Nullable<Object>)
Check if an object is a complex number.
Declaration
public static bool IsComplex(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsFloatingPoint(Nullable<Object>)
Check if an object is a floating point value.
Declaration
public static bool IsFloatingPoint(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsInteger(Nullable<Object>)
Check if an object is an integer.
Declaration
public static bool IsInteger(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsNumber(Nullable<Object>)
Check if an object is a number.
Declaration
public static bool IsNumber(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsReal(Nullable<Object>)
Check if an object is a real (non-complex) number.
Declaration
public static bool IsReal(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsSignedInteger(Nullable<Object>)
Check if an object is a signed integer.
Declaration
public static bool IsSignedInteger(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsUnsignedInteger(Nullable<Object>)
Check if an object is an unsigned integer.
Declaration
public static bool IsUnsignedInteger(object? obj)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Object> |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
|
Mod<T>(T, T)
Corrected modulo operation.
Declaration
public static T Mod<T>(T a, T b)
where T : INumberBase<T>, IModulusOperators<T, T, T>, IComparisonOperators<T, T, bool>
Parameters
| Type |
Name |
Description |
| T |
a |
|
| T |
b |
|
Returns
Type Parameters
Product<T>(IEnumerable<T>)
Similar to Sum(), this extension method generates the product of all values in a collection
of numbers.
Declaration
public static T Product<T>(this IEnumerable<T> source)
where T : INumberBase<T>
Parameters
| Type |
Name |
Description |
| IEnumerable<T> |
source |
|
Returns
Type Parameters
Product<T>(IEnumerable<T>, Func<T, T>)
Similar to Sum(), get a product of all values in the collection, transformed by the supplied
function.
Declaration
public static T Product<T>(this IEnumerable<T> source, Func<T, T> func)
where T : INumberBase<T>
Parameters
| Type |
Name |
Description |
| IEnumerable<T> |
source |
|
| Func<T, T> |
func |
|
Returns
Type Parameters