Table of Contents

Class XNumber

Extension methods for numbers (INumber{T} and INumberBase{T}).

Inheritance
System.Object
XNumber
Namespace: Galaxon.Core.Numbers
Assembly: Galaxon.Core.dll
Syntax
public static class XNumber : object
Remarks

TODO: Sort out methods to check for implementation of generic interfaces.

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 Description
T
Type Parameters
Name Description
T
| Improve this Doc View Source

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
Name Description
T
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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 Description
T
Type Parameters
Name Description
T
| Improve this Doc View Source

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 Description
T
Type Parameters
Name Description
T
| Improve this Doc View Source

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 Description
T
Type Parameters
Name Description
T
| Improve this Doc View Source
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX | Galaxy logo by Freepik