Namespaces

Types in MathNet.Numerics

Type Precision

Namespace MathNet.Numerics

Utilities for working with floating point numbers.

Useful links:

Static Functions

Fields

Public Static Functions

bool AlmostEqual(this double a, double b)

Checks whether two real numbers are almost equal.
Parameters
double a

The first number

double b

The second number

Return
bool

true if the two values differ by no more than 10 * 2^(-52); false otherwise.

bool AlmostEqual(this Complex a, Complex b)

Checks whether two Complex numbers are almost equal.
Parameters
Complex a

The first number

Complex b

The second number

Return
bool

true if the two values differ by no more than 10 * 2^(-52); false otherwise.

bool AlmostEqual(this double a, double b, double maximumAbsoluteError)

Compares two doubles and determines if they are equal within the specified maximum error.
Parameters
double a

The first value.

double b

The second value.

double maximumAbsoluteError

The accuracy required for being almost equal.

bool AlmostEqual(this double a, double b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the number of decimal places as an absolute measure.
Parameters
double a

The first value.

double b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqual(this float a, float b, double maximumAbsoluteError)

Compares two complex and determines if they are equal within the specified maximum error.
Parameters
float a

The first value.

float b

The second value.

double maximumAbsoluteError

The accuracy required for being almost equal.

bool AlmostEqual(this float a, float b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the number of decimal places as an absolute measure.
Parameters
float a

The first value.

float b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqual(this Complex a, Complex b, double maximumAbsoluteError)

Compares two complex and determines if they are equal within the specified maximum error.
Parameters
Complex a

The first value.

Complex b

The second value.

double maximumAbsoluteError

The accuracy required for being almost equal.

bool AlmostEqual(this Complex32 a, Complex32 b, double maximumAbsoluteError)

Compares two complex and determines if they are equal within the specified maximum error.
Parameters
Complex32 a

The first value.

Complex32 b

The second value.

double maximumAbsoluteError

The accuracy required for being almost equal.

bool AlmostEqual(this Complex32 a, Complex32 b)

Checks whether two Complex numbers are almost equal.
Parameters
Complex32 a

The first number

Complex32 b

The second number

Return
bool

true if the two values differ by no more than 10 * 2^(-52); false otherwise.

bool AlmostEqual(this float a, float b)

Checks whether two real numbers are almost equal.
Parameters
float a

The first number

float b

The second number

Return
bool

true if the two values differ by no more than 10 * 2^(-52); false otherwise.

bool AlmostEqual(this Complex32 a, Complex32 b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the number of decimal places as an absolute measure.
Parameters
Complex32 a

The first value.

Complex32 b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqual(this Complex a, Complex b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the number of decimal places as an absolute measure.
Parameters
Complex a

The first value.

Complex b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqual<T>(this Vector<T> a, Vector<T> b, double maximumAbsoluteError)

Compares two vectors and determines if they are equal within the specified maximum error.
Parameters
Vector<T> a

The first value.

Vector<T> b

The second value.

double maximumAbsoluteError

The accuracy required for being almost equal.

bool AlmostEqual<T>(this Matrix<T> a, Matrix<T> b, double maximumAbsoluteError)

Compares two matrices and determines if they are equal within the specified maximum error.
Parameters
Matrix<T> a

The first value.

Matrix<T> b

The second value.

double maximumAbsoluteError

The accuracy required for being almost equal.

bool AlmostEqual<T>(this Vector<T> a, Vector<T> b, int decimalPlaces)

Compares two vectors and determines if they are equal to within the specified number of decimal places or not, using the number of decimal places as an absolute measure.
Parameters
Vector<T> a

The first value.

Vector<T> b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqual<T>(this Matrix<T> a, Matrix<T> b, int decimalPlaces)

Compares two matrices and determines if they are equal to within the specified number of decimal places or not, using the number of decimal places as an absolute measure.
Parameters
Matrix<T> a

The first value.

Matrix<T> b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqualNorm(this double a, double b, double diff, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the number of decimal places as an absolute measure.

The values are equal if the difference between the two numbers is smaller than 0.5e-decimalPlaces. We divide by two so that we have half the range on each side of the numbers, e.g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
double a

The norm of the first value (can be negative).

double b

The norm of the second value (can be negative).

double diff

The norm of the difference of the two values (can be negative).

int decimalPlaces

The number of decimal places.

bool AlmostEqualNorm(this double a, double b, double diff, double maximumAbsoluteError)

Compares two doubles and determines if they are equal within the specified maximum absolute error.
Parameters
double a

The norm of the first value (can be negative).

double b

The norm of the second value (can be negative).

double diff

The norm of the difference of the two values (can be negative).

double maximumAbsoluteError

The absolute accuracy required for being almost equal.

Return
bool

True if both doubles are almost equal up to the specified maximum absolute error, false otherwise.

bool AlmostEqualNorm<T>(this T a, T b, double maximumAbsoluteError)

Compares two doubles and determines if they are equal within the specified maximum absolute error.
Parameters
T a

The first value.

T b

The second value.

double maximumAbsoluteError

The absolute accuracy required for being almost equal.

Return
bool

True if both doubles are almost equal up to the specified maximum absolute error, false otherwise.

bool AlmostEqualNorm<T>(this T a, T b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the number of decimal places as an absolute measure.

The values are equal if the difference between the two numbers is smaller than 0.5e-decimalPlaces. We divide by two so that we have half the range on each side of the numbers, e.g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
T a

The first value.

T b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqualNormRelative(this double a, double b, double diff, double maximumError)

Compares two doubles and determines if they are equal within the specified maximum error.
Parameters
double a

The norm of the first value (can be negative).

double b

The norm of the second value (can be negative).

double diff

The norm of the difference of the two values (can be negative).

double maximumError

The accuracy required for being almost equal.

Return
bool

True if both doubles are almost equal up to the specified maximum error, false otherwise.

bool AlmostEqualNormRelative(this double a, double b, double diff, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers are very close to zero an absolute difference is compared, otherwise the relative difference is compared.

The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range on each side of the numbers, e.g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
double a

The norm of the first value (can be negative).

double b

The norm of the second value (can be negative).

double diff

The norm of the difference of the two values (can be negative).

int decimalPlaces

The number of decimal places.

bool AlmostEqualNormRelative<T>(this T a, T b, double maximumError)

Compares two doubles and determines if they are equal within the specified maximum error.
Parameters
T a

The first value.

T b

The second value.

double maximumError

The accuracy required for being almost equal.

Return
bool

True if both doubles are almost equal up to the specified maximum error, false otherwise.

bool AlmostEqualNormRelative<T>(this T a, T b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers are very close to zero an absolute difference is compared, otherwise the relative difference is compared.

The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range on each side of the numbers, e.g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
T a

The first value.

T b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqualNumbersBetween(this float a, float b, int maxNumbersBetween)

Compares two floats and determines if they are equal to within the tolerance or not. Equality comparison is based on the binary representation.
Parameters
float a

The first value.

float b

The second value.

int maxNumbersBetween

The maximum number of floating point values between the two values. Must be 1 or larger.

bool AlmostEqualNumbersBetween(this double a, double b, long maxNumbersBetween)

Compares two doubles and determines if they are equal to within the tolerance or not. Equality comparison is based on the binary representation.

Determines the 'number' of floating point numbers between two values (i.e. the number of discrete steps between the two numbers) and then checks if that is within the specified tolerance. So if a tolerance of 1 is passed then the result will be true only if the two numbers have the same binary representation OR if they are two adjacent numbers that only differ by one step.

The comparison method used is explained in http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm. The article at http://www.extremeoptimization.com/resources/Articles/FPDotNetConceptsAndFormats.aspx explains how to transform the C code to .NET enabled code without using pointers and unsafe code.

Parameters
double a

The first value.

double b

The second value.

long maxNumbersBetween

The maximum number of floating point values between the two values. Must be 1 or larger.

bool AlmostEqualRelative(this Complex32 a, Complex32 b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
Parameters
Complex32 a

The first value.

Complex32 b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqualRelative(this Complex a, Complex b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
Parameters
Complex a

The first value.

Complex b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqualRelative(this double a, double b, double maximumError)

Compares two doubles and determines if they are equal within the specified maximum error.
Parameters
double a

The first value.

double b

The second value.

double maximumError

The accuracy required for being almost equal.

bool AlmostEqualRelative(this Complex a, Complex b, double maximumError)

Compares two complex and determines if they are equal within the specified maximum error.
Parameters
Complex a

The first value.

Complex b

The second value.

double maximumError

The accuracy required for being almost equal.

bool AlmostEqualRelative(this Complex32 a, Complex32 b, double maximumError)

Compares two complex and determines if they are equal within the specified maximum error.
Parameters
Complex32 a

The first value.

Complex32 b

The second value.

double maximumError

The accuracy required for being almost equal.

bool AlmostEqualRelative(this float a, float b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
Parameters
float a

The first value.

float b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqualRelative(this double a, double b, int decimalPlaces)

Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
Parameters
double a

The first value.

double b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqualRelative(this double a, double b)

Checks whether two real numbers are almost equal.
Parameters
double a

The first number

double b

The second number

Return
bool

true if the two values differ by no more than 10 * 2^(-52); false otherwise.

bool AlmostEqualRelative(this float a, float b)

Checks whether two real numbers are almost equal.
Parameters
float a

The first number

float b

The second number

Return
bool

true if the two values differ by no more than 10 * 2^(-52); false otherwise.

bool AlmostEqualRelative(this Complex a, Complex b)

Checks whether two Complex numbers are almost equal.
Parameters
Complex a

The first number

Complex b

The second number

Return
bool

true if the two values differ by no more than 10 * 2^(-52); false otherwise.

bool AlmostEqualRelative(this float a, float b, double maximumError)

Compares two complex and determines if they are equal within the specified maximum error.
Parameters
float a

The first value.

float b

The second value.

double maximumError

The accuracy required for being almost equal.

bool AlmostEqualRelative(this Complex32 a, Complex32 b)

Checks whether two Complex numbers are almost equal.
Parameters
Complex32 a

The first number

Complex32 b

The second number

Return
bool

true if the two values differ by no more than 10 * 2^(-52); false otherwise.

bool AlmostEqualRelative<T>(this Vector<T> a, Vector<T> b, double maximumError)

Compares two vectors and determines if they are equal within the specified maximum error.
Parameters
Vector<T> a

The first value.

Vector<T> b

The second value.

double maximumError

The accuracy required for being almost equal.

bool AlmostEqualRelative<T>(this Matrix<T> a, Matrix<T> b, int decimalPlaces)

Compares two matrices and determines if they are equal to within the specified number of decimal places or not. If the numbers are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
Parameters
Matrix<T> a

The first value.

Matrix<T> b

The second value.

int decimalPlaces

The number of decimal places.

bool AlmostEqualRelative<T>(this Matrix<T> a, Matrix<T> b, double maximumError)

Compares two matrices and determines if they are equal within the specified maximum error.
Parameters
Matrix<T> a

The first value.

Matrix<T> b

The second value.

double maximumError

The accuracy required for being almost equal.

bool AlmostEqualRelative<T>(this Vector<T> a, Vector<T> b, int decimalPlaces)

Compares two vectors and determines if they are equal to within the specified number of decimal places or not. If the numbers are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
Parameters
Vector<T> a

The first value.

Vector<T> b

The second value.

int decimalPlaces

The number of decimal places.

double CoerceZero(this double a, long maxNumbersBetween)

Forces small numbers near zero to zero, according to the specified absolute accuracy.
Parameters
double a

The real number to coerce to zero, if it is almost zero.

long maxNumbersBetween

The maximum count of numbers between the zero and the number a.

Return
double

Zero if | a | is fewer than maxNumbersBetween numbers from zero, a otherwise.

double CoerceZero(this double a, int maxNumbersBetween)

Forces small numbers near zero to zero, according to the specified absolute accuracy.
Parameters
double a

The real number to coerce to zero, if it is almost zero.

int maxNumbersBetween

The maximum count of numbers between the zero and the number a.

Return
double

Zero if | a | is fewer than maxNumbersBetween numbers from zero, a otherwise.

double CoerceZero(this double a, double maximumAbsoluteError)

Forces small numbers near zero to zero, according to the specified absolute accuracy.
Parameters
double a

The real number to coerce to zero, if it is almost zero.

double maximumAbsoluteError

The absolute threshold for a to consider it as zero.

Return
double

Zero if | a | is smaller than maximumAbsoluteError , a otherwise.

double CoerceZero(this double a)

Forces small numbers near zero to zero.
Parameters
double a

The real number to coerce to zero, if it is almost zero.

Return
double

Zero if | a | is smaller than 2^(-53) = 1.11e-16, a otherwise.

int CompareTo(this double a, double b, double maximumAbsoluteError)

Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
Parameters
double a

The first value.

double b

The second value.

double maximumAbsoluteError

The absolute accuracy required for being almost equal.

int CompareTo(this double a, double b, int decimalPlaces)

Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
Parameters
double a

The first value.

double b

The second value.

int decimalPlaces

The number of decimal places on which the values must be compared. Must be 1 or larger.

int CompareToNumbersBetween(this double a, double b, long maxNumbersBetween)

Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
Parameters
double a

The first value.

double b

The second value.

long maxNumbersBetween

The maximum error in terms of Units in Last Place ( ulps ), i.e. the maximum number of decimals that may be different. Must be 1 or larger.

int CompareToRelative(this double a, double b, double maximumError)

Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
Parameters
double a

The first value.

double b

The second value.

double maximumError

The relative accuracy required for being almost equal.

int CompareToRelative(this double a, double b, int decimalPlaces)

Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
Parameters
double a

The first value.

double b

The second value.

int decimalPlaces

The number of decimal places on which the values must be compared. Must be 1 or larger.

double Decrement(this double value, int count)

Decrements a floating point number to the next smaller number representable by the data type.
The decrementation step length depends on the provided value. Decrement(double.MinValue) will return negative infinity.
Parameters
double value

The value which should be decremented.

int count

How many times the number should be decremented.

Return
double

The next smaller floating point value.

double EpsilonOf(this double value)

Evaluates the minimum distance to the next distinguishable number near the argument value.
Evaluates the epsilon. The more common positive epsilon is equal to two times this negative epsilon.
Parameters
double value

The value used to determine the minimum distance.

Return
double

Relative Epsilon (positive double or NaN).

float EpsilonOf(this float value)

Evaluates the minimum distance to the next distinguishable number near the argument value.
Evaluates the epsilon. The more common positive epsilon is equal to two times this negative epsilon.
Parameters
float value

The value used to determine the minimum distance.

Return
float

Relative Epsilon (positive float or NaN).

double Increment(this double value, int count)

Increments a floating point number to the next bigger number representable by the data type.
The incrementation step length depends on the provided value. Increment(double.MaxValue) will return positive infinity.
Parameters
double value

The value which needs to be incremented.

int count

How many times the number should be incremented.

Return
double

The next larger floating point value.

bool IsFinite(this double value)

Checks if a given double values is finite, i.e. neither NaN nor inifnity
Parameters
double value

The value to be checked fo finitenes.

bool IsLarger(this float a, float b, double maximumAbsoluteError)

Compares two doubles and determines if the first value is larger than the second value to within the specified number of decimal places or not.
Parameters
float a

The first value.

float b

The second value.

double maximumAbsoluteError

The absolute accuracy required for being almost equal.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLarger(this float a, float b, int decimalPlaces)

Compares two doubles and determines if the first value is larger than the second value to within the specified number of decimal places or not.

The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range on each side of the numbers, e.g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
float a

The first value.

float b

The second value.

int decimalPlaces

The number of decimal places.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLarger(this double a, double b, int decimalPlaces)

Compares two doubles and determines if the first value is larger than the second value to within the specified number of decimal places or not.

The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range on each side of the numbers, e.g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
double a

The first value.

double b

The second value.

int decimalPlaces

The number of decimal places.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLarger(this double a, double b, double maximumAbsoluteError)

Compares two doubles and determines if the first value is larger than the second value to within the specified number of decimal places or not.
Parameters
double a

The first value.

double b

The second value.

double maximumAbsoluteError

The absolute accuracy required for being almost equal.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLargerNumbersBetween(this double a, double b, long maxNumbersBetween)

Compares two doubles and determines if the first value is larger than the second value to within the tolerance or not. Equality comparison is based on the binary representation.
Parameters
double a

The first value.

double b

The second value.

long maxNumbersBetween

The maximum number of floating point values for which the two values are considered equal. Must be 1 or larger.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLargerNumbersBetween(this float a, float b, long maxNumbersBetween)

Compares two doubles and determines if the first value is larger than the second value to within the tolerance or not. Equality comparison is based on the binary representation.
Parameters
float a

The first value.

float b

The second value.

long maxNumbersBetween

The maximum number of floating point values for which the two values are considered equal. Must be 1 or larger.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLargerRelative(this float a, float b, int decimalPlaces)

Compares two doubles and determines if the first value is larger than the second value to within the specified number of decimal places or not.

The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range on each side of the numbers, e.g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
float a

The first value.

float b

The second value.

int decimalPlaces

The number of decimal places.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLargerRelative(this double a, double b, double maximumError)

Compares two doubles and determines if the first value is larger than the second value to within the specified number of decimal places or not.
Parameters
double a

The first value.

double b

The second value.

double maximumError

The relative accuracy required for being almost equal.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLargerRelative(this float a, float b, double maximumError)

Compares two doubles and determines if the first value is larger than the second value to within the specified number of decimal places or not.
Parameters
float a

The first value.

float b

The second value.

double maximumError

The relative accuracy required for being almost equal.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsLargerRelative(this double a, double b, int decimalPlaces)

Compares two doubles and determines if the first value is larger than the second value to within the specified number of decimal places or not.

The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range on each side of the numbers, e.g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
double a

The first value.

double b

The second value.

int decimalPlaces

The number of decimal places.

Return
bool

true if the first value is larger than the second value; otherwise false.

bool IsSmaller(this double a, double b, int decimalPlaces)

Compares two doubles and determines if the first value is smaller than the second value to within the specified number of decimal places or not.

The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range on each side of th decimalPlaces g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
double a

The first value.

double b

The second value.

int decimalPlaces

The number of decimal places.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmaller(this float a, float b, int decimalPlaces)

Compares two doubles and determines if the first value is smaller than the second value to within the specified number of decimal places or not.

The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range on each side of th decimalPlaces g. if decimalPlaces == 2, then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00

Parameters
float a

The first value.

float b

The second value.

int decimalPlaces

The number of decimal places.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmaller(this double a, double b, double maximumAbsoluteError)

Compares two doubles and determines if the first value is smaller than the second value to within the specified number of decimal places or not.
Parameters
double a

The first value.

double b

The second value.

double maximumAbsoluteError

The absolute accuracy required for being almost equal.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmaller(this float a, float b, double maximumAbsoluteError)

Compares two doubles and determines if the first value is smaller than the second value to within the specified number of decimal places or not.
Parameters
float a

The first value.

float b

The second value.

double maximumAbsoluteError

The absolute accuracy required for being almost equal.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmallerNumbersBetween(this float a, float b, long maxNumbersBetween)

Compares two doubles and determines if the first value is smaller than the second value to within the tolerance or not. Equality comparison is based on the binary representation.
Parameters
float a

The first value.

float b

The second value.

long maxNumbersBetween

The maximum number of floating point values for which the two values are considered equal. Must be 1 or larger.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmallerNumbersBetween(this double a, double b, long maxNumbersBetween)

Compares two doubles and determines if the first value is smaller than the second value to within the tolerance or not. Equality comparison is based on the binary representation.
Parameters
double a

The first value.

double b

The second value.

long maxNumbersBetween

The maximum number of floating point values for which the two values are considered equal. Must be 1 or larger.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmallerRelative(this float a, float b, double maximumError)

Compares two doubles and determines if the first value is smaller than the second value to within the specified number of decimal places or not.
Parameters
float a

The first value.

float b

The second value.

double maximumError

The relative accuracy required for being almost equal.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmallerRelative(this double a, double b, double maximumError)

Compares two doubles and determines if the first value is smaller than the second value to within the specified number of decimal places or not.
Parameters
double a

The first value.

double b

The second value.

double maximumError

The relative accuracy required for being almost equal.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmallerRelative(this float a, float b, int decimalPlaces)

Compares two doubles and determines if the first value is smaller than the second value to within the specified number of decimal places or not.
Parameters
float a

The first value.

float b

The second value.

int decimalPlaces

The number of decimal places.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool IsSmallerRelative(this double a, double b, int decimalPlaces)

Compares two doubles and determines if the first value is smaller than the second value to within the specified number of decimal places or not.
Parameters
double a

The first value.

double b

The second value.

int decimalPlaces

The number of decimal places.

Return
bool

true if the first value is smaller than the second value; otherwise false.

bool ListAlmostEqual(this IList<double> a, IList<double> b, int decimalPlaces)

Compares two lists of doubles and determines if they are equal within the specified maximum error.
Parameters
IList<double> a

The first value list.

IList<double> b

The second value list.

int decimalPlaces

The number of decimal places.

bool ListAlmostEqual(this IList<double> a, IList<double> b, double maximumAbsoluteError)

Compares two lists of doubles and determines if they are equal within the specified maximum error.
Parameters
IList<double> a

The first value list.

IList<double> b

The second value list.

double maximumAbsoluteError

The accuracy required for being almost equal.

bool ListAlmostEqualNorm<T>(this IList<T> a, IList<T> b, double maximumAbsoluteError)

Compares two lists of doubles and determines if they are equal within the specified maximum error.
Parameters
IList<T> a

The first value list.

IList<T> b

The second value list.

double maximumAbsoluteError

The accuracy required for being almost equal.

bool ListAlmostEqualNormRelative<T>(this IList<T> a, IList<T> b, double maximumError)

Compares two lists of doubles and determines if they are equal within the specified maximum error.
Parameters
IList<T> a

The first value list.

IList<T> b

The second value list.

double maximumError

The accuracy required for being almost equal.

bool ListAlmostEqualRelative(this IList<double> a, IList<double> b, int decimalPlaces)

Compares two lists of doubles and determines if they are equal within the specified maximum error.
Parameters
IList<double> a

The first value list.

IList<double> b

The second value list.

int decimalPlaces

The number of decimal places.

bool ListAlmostEqualRelative(this IList<double> a, IList<double> b, double maximumError)

Compares two lists of doubles and determines if they are equal within the specified maximum error.
Parameters
IList<double> a

The first value list.

IList<double> b

The second value list.

double maximumError

The accuracy required for being almost equal.

int Magnitude(this double value)

Returns the magnitude of the number.
Parameters
double value

The value.

Return
int

The magnitude of the number.

int Magnitude(this float value)

Returns the magnitude of the number.
Parameters
float value

The value.

Return
int

The magnitude of the number.

double MaximumMatchingFloatingPointNumber(this double value, long maxNumbersBetween)

Returns the floating point number that will match the value with the tolerance on the maximum size (i.e. the result is always bigger than the value)
Parameters
double value

The value.

long maxNumbersBetween

The ulps difference.

Return
double

The maximum floating point number which is maxNumbersBetween larger than the given value.

double MinimumMatchingFloatingPointNumber(this double value, long maxNumbersBetween)

Returns the floating point number that will match the value with the tolerance on the minimum size (i.e. the result is always smaller than the value)
Parameters
double value

The value.

long maxNumbersBetween

The ulps difference.

Return
double

The minimum floating point number which is maxNumbersBetween smaller than the given value.

ulong NumbersBetween(this double a, double b)

Evaluates the count of numbers between two double numbers
The second number is included in the number, thus two equal numbers evaluate to zero and two neighbor numbers evaluate to one. Therefore, what is returned is actually the count of numbers between plus 1.
Parameters
double a

The first parameter.

double b

The second parameter.

Return
ulong

The number of floating point values between a and b.

double PositiveEpsilonOf(this double value)

Evaluates the minimum distance to the next distinguishable number near the argument value.
Evaluates the epsilon. See also EpsilonOf
Parameters
double value

The value used to determine the minimum distance.

Return
double

Relative Epsilon (positive double or NaN)

float PositiveEpsilonOf(this float value)

Evaluates the minimum distance to the next distinguishable number near the argument value.
Evaluates the epsilon. See also EpsilonOf
Parameters
float value

The value used to determine the minimum distance.

Return
float

Relative Epsilon (positive float or NaN)

ValueTuple<double, double> RangeOfMatchingFloatingPointNumbers(this double value, long maxNumbersBetween)

Determines the range of floating point numbers that will match the specified value with the given tolerance.
Parameters
double value

The value.

long maxNumbersBetween

The ulps difference.

Return
ValueTuple<double, double>

Tuple of the bottom and top range ends.

ValueTuple<long, long> RangeOfMatchingNumbers(this double value, double relativeDifference)

Determines the range of ulps that will match the specified value with the given tolerance.
Parameters
double value

The value.

double relativeDifference

The relative difference.

Return
ValueTuple<long, long>

Tuple with the number of ULPS between the value and the value - relativeDifference as first, and the number of ULPS between the value and the value + relativeDifference as second value.

BigInteger Round(this BigInteger number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
BigInteger number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
BigInteger

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

ulong Round(this ulong number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
ulong number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
ulong

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

ushort Round(this ushort number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
ushort number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
ushort

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

double Round(this double number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
double number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
double

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

float Round(this float number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
float number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
float

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

decimal Round(this decimal number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
decimal number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
decimal

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

int Round(this int number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
int number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
int

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

uint Round(this uint number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
uint number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
uint

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

long Round(this long number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
long number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
long

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

short Round(this short number, int digits)

Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
Parameters
short number

Number to be rounded

int digits

If positive the number of decimals to round to. If negative the number of digits within the integer part to round, e.g. -3 will wound to the closes 1000.

Return
short

Rounded number

Show Example
To round 123456789 to hundreds Round(123456789, -2) = 123456800  

double RoundToMultiple(this double number, double basis)

Round to a multiple of the provided positive basis.
Parameters
double number

Number to be rounded.

double basis

The basis to whose multiples to round to. Must be positive.

float RoundToMultiple(this float number, float basis)

Round to a multiple of the provided positive basis.
Parameters
float number

Number to be rounded.

float basis

The basis to whose multiples to round to. Must be positive.

decimal RoundToMultiple(this decimal number, decimal basis)

Round to a multiple of the provided positive basis.
Parameters
decimal number

Number to be rounded.

decimal basis

The basis to whose multiples to round to. Must be positive.

float RoundToPower(this float number, float basis)

Round to a multiple of the provided positive basis.
Parameters
float number

Number to be rounded.

float basis

The basis to whose powers to round to. Must be positive.

double RoundToPower(this double number, double basis)

Round to a multiple of the provided positive basis.
Parameters
double number

Number to be rounded.

double basis

The basis to whose powers to round to. Must be positive.

double ScaleUnitMagnitude(this double value)

Returns the number divided by it's magnitude, effectively returning a number between -10 and 10.
Parameters
double value

The value.

Return
double

The value of the number.

Public fields

double DoublePrecision

Standard epsilon, the maximum relative precision of IEEE 754 double-precision floating numbers (64 bit). According to the definition of Prof. Demmel and used in LAPACK and Scilab.
return double

double PositiveDoublePrecision

Standard epsilon, the maximum relative precision of IEEE 754 double-precision floating numbers (64 bit). According to the definition of Prof. Higham and used in the ISO C standard and MATLAB.
return double

double SinglePrecision

Standard epsilon, the maximum relative precision of IEEE 754 single-precision floating numbers (32 bit). According to the definition of Prof. Demmel and used in LAPACK and Scilab.
return double

double PositiveSinglePrecision

Standard epsilon, the maximum relative precision of IEEE 754 single-precision floating numbers (32 bit). According to the definition of Prof. Higham and used in the ISO C standard and MATLAB.
return double

double MachineEpsilon

Actual double precision machine epsilon, the smallest number that can be subtracted from 1, yielding a results different than 1. This is also known as unit roundoff error. According to the definition of Prof. Demmel. On a standard machine this is equivalent to `DoublePrecision`.
return double

double PositiveMachineEpsilon

Actual double precision machine epsilon, the smallest number that can be added to 1, yielding a results different than 1. This is also known as unit roundoff error. According to the definition of Prof. Higham. On a standard machine this is equivalent to `PositiveDoublePrecision`.
return double

int DoubleDecimalPlaces

The number of significant decimal places of double-precision floating numbers (64 bit).
return int

int SingleDecimalPlaces

The number of significant decimal places of single-precision floating numbers (32 bit).
return int