Show / Hide Table of Contents

Class Number

Represents Generic Math extensions.

Inheritance
object
Number
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Numerics
Assembly: DotNext.dll
Syntax
public static class Number

Methods

View Source

FromBits<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 T restored from the vector of bits.

Type Parameters
Name Description
T
View Source

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

bits has not enough length.

View Source

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

true if the bit at position is set; otherwise, false.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentOutOfRangeException

position is negative.

View Source

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).

View Source

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).

View Source

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).

View Source

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).

View Source

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.

View Source

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

value rounded down to the multiple of multiplier.

Type Parameters
Name Description
T

The type of the number.

View Source

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

value rounded up to the multiple of multiplier.

Type Parameters
Name Description
T

The type of the number.

View Source

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

position is negative.

View Source

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

true if value is a prime number; otherwise, false.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentOutOfRangeException

value is negative or zero.

View Source

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

true if T is a signed numeric type; otherwise, false.

Type Parameters
Name Description
T
View Source

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 T.

Type Parameters
Name Description
T
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾