Class Number
Represents Generic Math extensions.
Inherited Members
Namespace: DotNext.Numerics
Assembly: DotNext.dll
Syntax
public static class Number
Methods
View SourceFromBits<T>(ReadOnlySpan<bool>)
Converts bit vector to a value of type T.
Declaration
public static T FromBits<T>(ReadOnlySpan<bool> bits) where T : unmanaged, IBinaryInteger<T>
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<bool> | bits | A vector of bits. |
Returns
| Type | Description |
|---|---|
| T | A value of type |
Type Parameters
| Name | Description |
|---|---|
| T |
GetBits<T>(T, Span<bool>)
Converts a value to a set of bits.
Declaration
public static void GetBits<T>(this T number, Span<bool> bits) where T : unmanaged, IBinaryInteger<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | number | |
| Span<bool> | bits | A buffer to be modified. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
IsBitSet<T>(T, int)
Gets a value indicating that the specified bit is set.
Declaration
public static bool IsBitSet<T>(this T number, int position) where T : unmanaged, IBinaryInteger<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | number | |
| int | position | The position of the bit within the receiver. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
Normalize(int)
Normalizes 32-bit signed integer to interval [0..1).
Declaration
public static float Normalize(this int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to be normalized. |
Returns
| Type | Description |
|---|---|
| float | The normalized value in range [0..1). |
Normalize(long)
Normalizes 64-bit signed integer to interval [0..1).
Declaration
public static double Normalize(this long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The value to be normalized. |
Returns
| Type | Description |
|---|---|
| double | The normalized value in range [0..1). |
Normalize(uint)
Normalizes 32-bit unsigned integer to interval [0..1).
Declaration
[CLSCompliant(false)]
public static float Normalize(this uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to be normalized. |
Returns
| Type | Description |
|---|---|
| float | The normalized value in range [0..1). |
Normalize(ulong)
Normalizes 64-bit unsigned integer to interval [0..1).
Declaration
[CLSCompliant(false)]
public static double Normalize(this ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to be normalized. |
Returns
| Type | Description |
|---|---|
| double | The normalized value in range [0..1). |
Normalize<TInput, TOutput>(TInput, TInput, TInput)
Normalizes value in the specified range.
Declaration
public static TOutput Normalize<TInput, TOutput>(this TInput value, TInput min, TInput max) where TInput : struct, INumberBase<TInput>, IComparisonOperators<TInput, TInput, bool> where TOutput : struct, IFloatingPoint<TOutput>
Parameters
| Type | Name | Description |
|---|---|---|
| TInput | value | The value to be normalized. Must be in range [min..max]. |
| TInput | min | The lower bound of the value. |
| TInput | max | The upper bound of the value. |
Returns
| Type | Description |
|---|---|
| TOutput | The normalized value in range [-1..1] for signed value and [0..1] for unsigned value. |
Type Parameters
| Name | Description |
|---|---|
| TInput | The type of the input value and bounds. |
| TOutput | The type of normalized value. |
RoundDown<T>(T, T)
Rounds down the value to the multiple of the specified multiplier.
Declaration
public static T RoundDown<T>(this T value, T multiplier) where T : struct, IUnsignedNumber<T>, IModulusOperators<T, T, T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to round down. |
| T | multiplier | The multiplier. |
Returns
| Type | Description |
|---|---|
| T |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the number. |
RoundUp<T>(T, T)
Rounds up the value to the multiple of the specified multiplier.
Declaration
public static T RoundUp<T>(this T value, T multiplier) where T : struct, IUnsignedNumber<T>, IModulusOperators<T, T, T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to round up. |
| T | multiplier | The multiplier. |
Returns
| Type | Description |
|---|---|
| T |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the number. |
SetBit<T>(T, int, bool)
Sets the bit at the specified position.
Declaration
public static T SetBit<T>(this T number, int position, bool value) where T : unmanaged, IBinaryInteger<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | number | |
| int | position | The position of the bit to set. |
| bool | value | The bit value. |
Returns
| Type | Description |
|---|---|
| T | A modified number. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
get_IsPrime<T>(T)
Determines whether the specified value is a prime number.
Declaration
public static bool get_IsPrime<T>(T value) where T : struct, IBinaryNumber<T>, ISignedNumber<T>, IShiftOperators<T, int, T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | value |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
get_IsSigned<T>()
Determines whether the specified numeric type is signed.
Declaration
public static bool get_IsSigned<T>() where T : INumberBase<T>
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
get_MaxByteCount<T>()
Gets maximum number of bytes that can be used by T type
when encoded in little-endian or big-endian format.
Declaration
public static int get_MaxByteCount<T>() where T : IBinaryInteger<T>
Returns
| Type | Description |
|---|---|
| int | The maximum numbers bytes that can be occupied by the value of |
Type Parameters
| Name | Description |
|---|---|
| T |