Table of Contents

Class NumericExtensions

Namespace
Garyon.Extensions
Assembly
Garyon.dll

Contains extension methods for numeric structures.

public static class NumericExtensions
Inheritance
NumericExtensions
Inherited Members

Methods

IsPowerOfTwo(byte)

Determines whether the value is a power of 2, using popcnt if supported, otherwise counting whether there only is 1 bit equal to 1.

public static bool IsPowerOfTwo(this byte value)

Parameters

value byte

The value to determine whether it is a power of 2.

Returns

bool

IsPowerOfTwo(short)

Determines whether the value is a power of 2, using popcnt if supported, otherwise counting whether there only is 1 bit equal to 1. Negative values are ignored.

public static bool IsPowerOfTwo(this short value)

Parameters

value short

The value to determine whether it is a power of 2.

Returns

bool

IsPowerOfTwo(int)

Determines whether the value is a power of 2, using popcnt if supported, otherwise counting whether there only is 1 bit equal to 1. Negative values are ignored.

public static bool IsPowerOfTwo(this int value)

Parameters

value int

The value to determine whether it is a power of 2.

Returns

bool

IsPowerOfTwo(long)

Determines whether the value is a power of 2, using popcnt if supported, otherwise counting whether there only is 1 bit equal to 1. Negative values are ignored.

public static bool IsPowerOfTwo(this long value)

Parameters

value long

The value to determine whether it is a power of 2.

Returns

bool

IsPowerOfTwo(sbyte)

Determines whether the value is a power of 2, using popcnt if supported, otherwise counting whether there only is 1 bit equal to 1. Negative values are ignored.

public static bool IsPowerOfTwo(this sbyte value)

Parameters

value sbyte

The value to determine whether it is a power of 2.

Returns

bool

IsPowerOfTwo(ushort)

Determines whether the value is a power of 2, using popcnt if supported, otherwise counting whether there only is 1 bit equal to 1.

public static bool IsPowerOfTwo(this ushort value)

Parameters

value ushort

The value to determine whether it is a power of 2.

Returns

bool

IsPowerOfTwo(uint)

Determines whether the value is a power of 2, using popcnt if supported, otherwise counting whether there only is 1 bit equal to 1.

public static bool IsPowerOfTwo(this uint value)

Parameters

value uint

The value to determine whether it is a power of 2.

Returns

bool

IsPowerOfTwo(ulong)

Determines whether the value is a power of 2, using popcnt if supported, otherwise counting whether there only is 1 bit equal to 1.

public static bool IsPowerOfTwo(this ulong value)

Parameters

value ulong

The value to determine whether it is a power of 2.

Returns

bool

OneOrGreater(byte)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static byte OneOrGreater(this byte value)

Parameters

value byte

The value to determine whether it is ≥1.

Returns

byte

OneOrGreater(decimal)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static decimal OneOrGreater(this decimal value)

Parameters

value decimal

The value to determine whether it is ≥1.

Returns

decimal

OneOrGreater(double)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static double OneOrGreater(this double value)

Parameters

value double

The value to determine whether it is ≥1.

Returns

double

OneOrGreater(short)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static short OneOrGreater(this short value)

Parameters

value short

The value to determine whether it is ≥1.

Returns

short

OneOrGreater(int)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static int OneOrGreater(this int value)

Parameters

value int

The value to determine whether it is ≥1.

Returns

int

OneOrGreater(long)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static long OneOrGreater(this long value)

Parameters

value long

The value to determine whether it is ≥1.

Returns

long

OneOrGreater(sbyte)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static sbyte OneOrGreater(this sbyte value)

Parameters

value sbyte

The value to determine whether it is ≥1.

Returns

sbyte

OneOrGreater(float)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static float OneOrGreater(this float value)

Parameters

value float

The value to determine whether it is ≥1.

Returns

float

OneOrGreater(ushort)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static ushort OneOrGreater(this ushort value)

Parameters

value ushort

The value to determine whether it is ≥1.

Returns

ushort

OneOrGreater(uint)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static uint OneOrGreater(this uint value)

Parameters

value uint

The value to determine whether it is ≥1.

Returns

uint

OneOrGreater(ulong)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static ulong OneOrGreater(this ulong value)

Parameters

value ulong

The value to determine whether it is ≥1.

Returns

ulong

OneOrGreater<T>(T)

Determines whether the value is ≥1 and returns the value if ≥1, otherwise returns 1.

public static INumber<T> OneOrGreater<T>(this T value) where T : INumber<T>

Parameters

value T

The value to determine whether it is ≥1.

Returns

INumber<T>

Type Parameters

T

ZeroOrGreater(byte)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static byte ZeroOrGreater(this byte value)

Parameters

value byte

The value to determine whether it is ≥0.

Returns

byte

ZeroOrGreater(decimal)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static decimal ZeroOrGreater(this decimal value)

Parameters

value decimal

The value to determine whether it is ≥0.

Returns

decimal

ZeroOrGreater(double)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static double ZeroOrGreater(this double value)

Parameters

value double

The value to determine whether it is ≥0.

Returns

double

ZeroOrGreater(short)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static short ZeroOrGreater(this short value)

Parameters

value short

The value to determine whether it is ≥0.

Returns

short

ZeroOrGreater(int)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static int ZeroOrGreater(this int value)

Parameters

value int

The value to determine whether it is ≥0.

Returns

int

ZeroOrGreater(long)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static long ZeroOrGreater(this long value)

Parameters

value long

The value to determine whether it is ≥0.

Returns

long

ZeroOrGreater(sbyte)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static sbyte ZeroOrGreater(this sbyte value)

Parameters

value sbyte

The value to determine whether it is ≥0.

Returns

sbyte

ZeroOrGreater(float)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static float ZeroOrGreater(this float value)

Parameters

value float

The value to determine whether it is ≥0.

Returns

float

ZeroOrGreater(ushort)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static ushort ZeroOrGreater(this ushort value)

Parameters

value ushort

The value to determine whether it is ≥0.

Returns

ushort

ZeroOrGreater(uint)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static uint ZeroOrGreater(this uint value)

Parameters

value uint

The value to determine whether it is ≥0.

Returns

uint

ZeroOrGreater(ulong)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static ulong ZeroOrGreater(this ulong value)

Parameters

value ulong

The value to determine whether it is ≥0.

Returns

ulong

ZeroOrGreater<T>(T)

Determines whether the value is ≥0 and returns the value if ≥0, otherwise returns 0.

public static INumber<T> ZeroOrGreater<T>(this T value) where T : INumber<T>

Parameters

value T

The value to determine whether it is ≥0.

Returns

INumber<T>

Type Parameters

T