Utilities for working with floating point numbers.
Useful links:
Static member | Description | ||||||||
Full Usage:
Precision.AlmostEqual(a, b, maximumAbsoluteError)
Parameters:
float
-
The first value.
b : float
-
The second value.
maximumAbsoluteError : float
-
The accuracy required for being almost equal.
Returns: bool
|
![]() ![]() ![]() ![]() Compares two doubles and determines if they are equal within the specified maximum error.
|
||||||||
Full Usage:
Precision.AlmostEqual(a, b, maximumAbsoluteError)
Parameters:
float32
-
The first value.
b : float32
-
The second value.
maximumAbsoluteError : float
-
The accuracy required for being almost equal.
Returns: bool
|
![]() ![]() ![]() ![]() Compares two complex and determines if they are equal within the specified maximum error.
|
||||||||
Full Usage:
Precision.AlmostEqual(a, b)
Parameters:
float
-
The first number
b : float
-
The second number
Returns: bool
true if the two values differ by no more than 10 * 2^(-52); false otherwise.
|
![]() ![]() ![]() ![]() Checks whether two real numbers are almost equal.
|
||||||||
Full Usage:
Precision.AlmostEqual(a, b)
Parameters:
float32
-
The first number
b : float32
-
The second number
Returns: bool
true if the two values differ by no more than 10 * 2^(-52); false otherwise.
|
![]() ![]() ![]() ![]() Checks whether two real numbers are almost equal.
|
||||||||
Full Usage:
Precision.AlmostEqual(a, b, decimalPlaces)
Parameters:
float
-
The first value.
b : float
-
The second value.
decimalPlaces : int
-
The number of decimal places.
Returns: bool
|
![]() ![]() ![]() ![]() 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.
|
||||||||
Full Usage:
Precision.AlmostEqual(a, b, decimalPlaces)
Parameters:
float32
-
The first value.
b : float32
-
The second value.
decimalPlaces : int
-
The number of decimal places.
Returns: bool
|
![]() ![]() ![]() ![]() 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.
|
||||||||
Full Usage:
Precision.AlmostEqualNorm(a, b, diff, maximumAbsoluteError)
Parameters:
float
-
The norm of the first value (can be negative).
b : float
-
The norm of the second value (can be negative).
diff : float
-
The norm of the difference of the two values (can be negative).
maximumAbsoluteError : float
-
The absolute accuracy required for being almost equal.
Returns: bool
True if both doubles are almost equal up to the specified maximum absolute error, false otherwise.
|
![]() ![]() ![]() ![]() Compares two doubles and determines if they are equal within the specified maximum absolute error.
|
||||||||
Full Usage:
Precision.AlmostEqualNorm(a, b, diff, decimalPlaces)
Parameters:
float
-
The norm of the first value (can be negative).
b : float
-
The norm of the second value (can be negative).
diff : float
-
The norm of the difference of the two values (can be negative).
decimalPlaces : int
-
The number of decimal places.
Returns: bool
|
![]() ![]() ![]() ![]() 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
|
||||||||
Full Usage:
Precision.AlmostEqualNorm(a, b, decimalPlaces)
Parameters:
'T
-
The first value.
b : 'T
-
The second value.
decimalPlaces : int
-
The number of decimal places.
Returns: bool
|
![]() ![]() ![]() ![]() 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
|
||||||||
Full Usage:
Precision.AlmostEqualNormRelative(a, b, diff, maximumError)
Parameters:
float
-
The norm of the first value (can be negative).
b : float
-
The norm of the second value (can be negative).
diff : float
-
The norm of the difference of the two values (can be negative).
maximumError : float
-
The accuracy required for being almost equal.
Returns: bool
True if both doubles are almost equal up to the specified maximum error, false otherwise.
|
![]() ![]() ![]() ![]() Compares two doubles and determines if they are equal within the specified maximum error.
|
||||||||
Full Usage:
Precision.AlmostEqualNormRelative(a, b, diff, decimalPlaces)
Parameters:
float
-
The norm of the first value (can be negative).
b : float
-
The norm of the second value (can be negative).
diff : float
-
The norm of the difference of the two values (can be negative).
decimalPlaces : int
-
The number of decimal places.
Returns: bool
|
![]() ![]() ![]() ![]() 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
|
||||||||
Full Usage:
Precision.AlmostEqualNormRelative(a, b, decimalPlaces)
Parameters:
'T
-
The first value.
b : 'T
-
The second value.
decimalPlaces : int
-
The number of decimal places.
Returns: bool
|
![]() ![]() ![]() ![]() 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
|
||||||||
Full Usage:
Precision.AlmostEqualNumbersBetween(a, b, maxNumbersBetween)
Parameters:
float
-
The first value.
b : float
-
The second value.
maxNumbersBetween : int64
-
The maximum number of floating point values between the two values. Must be 1 or larger.
Returns: bool
|
![]() ![]() ![]() ![]() 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.
|
||||||||
Full Usage:
Precision.AlmostEqualNumbersBetween(a, b, maxNumbersBetween)
Parameters:
float32
-
The first value.
b : float32
-
The second value.
maxNumbersBetween : int
-
The maximum number of floating point values between the two values. Must be 1 or larger.
Returns: bool
|
![]() ![]() ![]() ![]() Compares two floats and determines if they are equal to within the tolerance or not. Equality comparison is based on the binary representation.
|
||||||||
Full Usage:
Precision.AlmostEqualRelative(a, b, maximumError)
Parameters:
float
-
The first value.
b : float
-
The second value.
maximumError : float
-
The accuracy required for being almost equal.
Returns: bool
|
![]() ![]() ![]() ![]() Compares two doubles and determines if they are equal within the specified maximum error.
|
||||||||
Full Usage:
Precision.AlmostEqualRelative(a, b, maximumError)
Parameters:
float32
-
The first value.
b : float32
-
The second value.
maximumError : float
-
The accuracy required for being almost equal.
Returns: bool
|
![]() ![]() ![]() ![]() Compares two complex and determines if they are equal within the specified maximum error.
|
||||||||
Full Usage:
Precision.AlmostEqualRelative(a, b)
Parameters:
float
-
The first number
b : float
-
The second number
Returns: bool
true if the two values differ by no more than 10 * 2^(-52); false otherwise.
|
![]() ![]() ![]() ![]() Checks whether two real numbers are almost equal.
|
||||||||
Full Usage:
Precision.AlmostEqualRelative(a, b)
Parameters:
float32
-
The first number
b : float32
-
The second number
Returns: bool
true if the two values differ by no more than 10 * 2^(-52); false otherwise.
|
![]() ![]() ![]() ![]() Checks whether two real numbers are almost equal.
|
||||||||
Full Usage:
Precision.AlmostEqualRelative(a, b, decimalPlaces)
Parameters:
float
-
The first value.
b : float
-
The second value.
decimalPlaces : int
-
The number of decimal places.
Returns: bool
|
![]() ![]() ![]() ![]() 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.
|
||||||||
Full Usage:
Precision.AlmostEqualRelative(a, b, decimalPlaces)
Parameters:
float32
-
The first value.
b : float32
-
The second value.
decimalPlaces : int
-
The number of decimal places.
Returns: bool
|
![]() ![]() ![]() ![]() 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.
|
||||||||
Full Usage:
Precision.CoerceZero(a, maxNumbersBetween)
Parameters:
float
-
The real number to coerce to zero, if it is almost zero.
maxNumbersBetween : int
-
The maximum count of numbers between the zero and the number a.
Returns: float
Zero if |a| is fewer than maxNumbersBetween numbers from zero, a otherwise.
|
![]() ![]() ![]() ![]() Forces small numbers near zero to zero, according to the specified absolute accuracy.
|
||||||||
Full Usage:
Precision.CoerceZero(a, maxNumbersBetween)
Parameters:
float
-
The real number to coerce to zero, if it is almost zero.
maxNumbersBetween : int64
-
The maximum count of numbers between the zero and the number a.
Returns: float
Zero if |a| is fewer than maxNumbersBetween numbers from zero, a otherwise.
|
![]() ![]() ![]() ![]() Forces small numbers near zero to zero, according to the specified absolute accuracy.
|
||||||||
Full Usage:
Precision.CoerceZero(a, maximumAbsoluteError)
Parameters:
float
-
The real number to coerce to zero, if it is almost zero.
maximumAbsoluteError : float
-
The absolute threshold for a to consider it as zero.
Returns: float
Zero if |a| is smaller than maximumAbsoluteError, a otherwise.
|
![]() ![]() ![]() ![]() Forces small numbers near zero to zero, according to the specified absolute accuracy.
|
||||||||
Full Usage:
Precision.CoerceZero(a)
Parameters:
float
-
The real number to coerce to zero, if it is almost zero.
Returns: float
Zero if |a| is smaller than 2^(-53) = 1.11e-16, a otherwise.
|
![]() ![]() ![]() ![]() Forces small numbers near zero to zero.
|
||||||||
Full Usage:
Precision.Decrement(value, ?count)
Parameters:
float
-
The value which should be decremented.
?count : int
-
How many times the number should be decremented.
Returns: float
The next smaller floating point value.
|
![]() ![]() ![]() ![]() 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.
|
||||||||
Full Usage:
Precision.EpsilonOf(value)
Parameters:
float
-
The value used to determine the minimum distance.
Returns: float
Relative Epsilon (positive double or NaN).
|
![]() ![]() ![]() ![]() Evaluates the minimum distance to the next distinguishable number near the argument value. Evaluates the negative epsilon. The more common positive epsilon is equal to two times this negative epsilon.
|
||||||||
Full Usage:
Precision.EpsilonOf(value)
Parameters:
float32
-
The value used to determine the minimum distance.
Returns: float32
Relative Epsilon (positive float or NaN).
|
![]() ![]() ![]() ![]() Evaluates the minimum distance to the next distinguishable number near the argument value. Evaluates the negative epsilon. The more common positive epsilon is equal to two times this negative epsilon.
|
||||||||
Full Usage:
Precision.Increment(value, ?count)
Parameters:
float
-
The value which needs to be incremented.
?count : int
-
How many times the number should be incremented.
Returns: float
The next larger floating point value.
|
![]() ![]() ![]() ![]() 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.
|
||||||||
Full Usage:
Precision.Magnitude(value)
Parameters:
float
-
The value.
Returns: int
The magnitude of the number.
|
![]() ![]() ![]() ![]() Returns the magnitude of the number.
|
||||||||
Full Usage:
Precision.Magnitude(value)
Parameters:
float32
-
The value.
Returns: int
The magnitude of the number.
|
![]() ![]() ![]() ![]() Returns the magnitude of the number.
|
||||||||
Full Usage:
Precision.MaximumMatchingFloatingPointNumber(value, maxNumbersBetween)
Parameters:
float
-
The value.
maxNumbersBetween : int64
-
The ulps difference.
Returns: float
The maximum floating point number which is maxNumbersBetween larger than the given value.
|
![]() ![]() ![]() ![]() 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)
|
||||||||
Full Usage:
Precision.MinimumMatchingFloatingPointNumber(value, maxNumbersBetween)
Parameters:
float
-
The value.
maxNumbersBetween : int64
-
The ulps difference.
Returns: float
The minimum floating point number which is maxNumbersBetween smaller than the given value.
|
![]() ![]() ![]() ![]() 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)
|
||||||||
Full Usage:
Precision.NumbersBetween(a, b)
Parameters:
float
-
The first parameter.
b : float
-
The second parameter.
Returns: uint64
The number of floating point values between a and 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.
|
||||||||
Full Usage:
Precision.PositiveEpsilonOf(value)
Parameters:
float
-
The value used to determine the minimum distance.
Returns: float
Relative Epsilon (positive double or NaN)
|
![]() ![]() ![]() ![]() Evaluates the minimum distance to the next distinguishable number near the argument value. Evaluates the positive epsilon. See also Precision.EpsilonOf
|
||||||||
Full Usage:
Precision.PositiveEpsilonOf(value)
Parameters:
float32
-
The value used to determine the minimum distance.
Returns: float32
Relative Epsilon (positive float or NaN)
|
![]() ![]() ![]() ![]() Evaluates the minimum distance to the next distinguishable number near the argument value. Evaluates the positive epsilon. See also Precision.EpsilonOf
|
||||||||
Full Usage:
Precision.RangeOfMatchingFloatingPointNumbers(value, maxNumbersBetween)
Parameters:
float
-
The value.
maxNumbersBetween : int64
-
The ulps difference.
Returns: float * float
Tuple of the bottom and top range ends.
|
![]() ![]() ![]() ![]() Determines the range of floating point numbers that will match the specified value with the given tolerance.
|
||||||||
Full Usage:
Precision.RangeOfMatchingNumbers(value, relativeDifference)
Parameters:
float
-
The value.
relativeDifference : float
-
The relative difference.
Returns: int64 * int64
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.
|
![]() ![]() ![]() ![]()
Determines the range of
|
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
float
-
Number to be rounded
digits : int
-
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.
Returns: float
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
float32
-
Number to be rounded
digits : int
-
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.
Returns: float32
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
decimal
-
Number to be rounded
digits : int
-
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.
Returns: decimal
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
int
-
Number to be rounded
digits : int
-
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.
Returns: int
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
uint32
-
Number to be rounded
digits : int
-
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.
Returns: uint32
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
int64
-
Number to be rounded
digits : int
-
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.
Returns: int64
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
uint64
-
Number to be rounded
digits : int
-
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.
Returns: uint64
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
int16
-
Number to be rounded
digits : int
-
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.
Returns: int16
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
uint16
-
Number to be rounded
digits : int
-
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.
Returns: uint16
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.Round(number, digits)
Parameters:
BigInteger
-
Number to be rounded
digits : int
-
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.
Returns: BigInteger
Rounded number
|
![]() ![]() ![]() ![]() Round to the number closest to 10^(-decimals). Negative decimals to round within the integer part.
ExampleTo round 123456789 to hundreds Round(123456789, -2) = 123456800 |
||||||||
Full Usage:
Precision.RoundToMultiple(number, basis)
Parameters:
float
-
Number to be rounded.
basis : float
-
The basis to whose multiples to round to. Must be positive.
Returns: float
|
![]() ![]() ![]() ![]() Round to a multiple of the provided positive basis.
|
||||||||
Full Usage:
Precision.RoundToMultiple(number, basis)
Parameters:
float32
-
Number to be rounded.
basis : float32
-
The basis to whose multiples to round to. Must be positive.
Returns: float32
|
![]() ![]() ![]() ![]() Round to a multiple of the provided positive basis.
|
||||||||
Full Usage:
Precision.RoundToMultiple(number, basis)
Parameters:
decimal
-
Number to be rounded.
basis : decimal
-
The basis to whose multiples to round to. Must be positive.
Returns: decimal
|
![]() ![]() ![]() ![]() Round to a multiple of the provided positive basis.
|
||||||||
Full Usage:
Precision.RoundToPower(number, basis)
Parameters:
float
-
Number to be rounded.
basis : float
-
The basis to whose powers to round to. Must be positive.
Returns: float
|
![]() ![]() ![]() ![]() Round to a multiple of the provided positive basis.
|
||||||||
Full Usage:
Precision.RoundToPower(number, basis)
Parameters:
float32
-
Number to be rounded.
basis : float32
-
The basis to whose powers to round to. Must be positive.
Returns: float32
|
![]() ![]() ![]() ![]() Round to a multiple of the provided positive basis.
|
||||||||
Full Usage:
Precision.ScaleUnitMagnitude(value)
Parameters:
float
-
The value.
Returns: float
The value of the number.
|
![]() ![]() ![]() ![]() Returns the number divided by it's magnitude, effectively returning a number between -10 and 10.
|