Precision Type

Utilities for working with floating point numbers.

Useful links:

  • http://docs.sun.com/source/806-3568/ncg_goldberg.html#689 - What every computer scientist should know about floating-point arithmetic
  • http://en.wikipedia.org/wiki/Machine_epsilon - Gives the definition of machine epsilon

Static members

Static member Description

Precision.AlmostEqual(a, b, maximumAbsoluteError)

Full Usage: Precision.AlmostEqual(a, b, maximumAbsoluteError)

Parameters:
    a : 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.

a : float

The first value.

b : float

The second value.

maximumAbsoluteError : float

The accuracy required for being almost equal.

Returns: bool

Precision.AlmostEqual(a, b, maximumAbsoluteError)

Full Usage: Precision.AlmostEqual(a, b, maximumAbsoluteError)

Parameters:
    a : 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.

a : float32

The first value.

b : float32

The second value.

maximumAbsoluteError : float

The accuracy required for being almost equal.

Returns: bool

Precision.AlmostEqual(a, b)

Full Usage: Precision.AlmostEqual(a, b)

Parameters:
    a : 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.

a : 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.

Precision.AlmostEqual(a, b)

Full Usage: Precision.AlmostEqual(a, b)

Parameters:
    a : 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.

a : 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.

Precision.AlmostEqual(a, b, decimalPlaces)

Full Usage: Precision.AlmostEqual(a, b, decimalPlaces)

Parameters:
    a : 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.

a : float

The first value.

b : float

The second value.

decimalPlaces : int

The number of decimal places.

Returns: bool

Precision.AlmostEqual(a, b, decimalPlaces)

Full Usage: Precision.AlmostEqual(a, b, decimalPlaces)

Parameters:
    a : 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.

a : float32

The first value.

b : float32

The second value.

decimalPlaces : int

The number of decimal places.

Returns: bool

Precision.AlmostEqualNorm(a, b, diff, maximumAbsoluteError)

Full Usage: Precision.AlmostEqualNorm(a, b, diff, maximumAbsoluteError)

Parameters:
    a : 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.

a : 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.

Precision.AlmostEqualNorm(a, b, diff, decimalPlaces)

Full Usage: Precision.AlmostEqualNorm(a, b, diff, decimalPlaces)

Parameters:
    a : 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

a : 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

Precision.AlmostEqualNorm(a, b, decimalPlaces)

Full Usage: Precision.AlmostEqualNorm(a, b, decimalPlaces)

Parameters:
    a : '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

a : 'T

The first value.

b : 'T

The second value.

decimalPlaces : int

The number of decimal places.

Returns: bool

Precision.AlmostEqualNormRelative(a, b, diff, maximumError)

Full Usage: Precision.AlmostEqualNormRelative(a, b, diff, maximumError)

Parameters:
    a : 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.

a : 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.

Precision.AlmostEqualNormRelative(a, b, diff, decimalPlaces)

Full Usage: Precision.AlmostEqualNormRelative(a, b, diff, decimalPlaces)

Parameters:
    a : 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

a : 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
ArgumentOutOfRangeException Thrown if decimalPlaces is smaller than zero.

Precision.AlmostEqualNormRelative(a, b, decimalPlaces)

Full Usage: Precision.AlmostEqualNormRelative(a, b, decimalPlaces)

Parameters:
    a : '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

a : 'T

The first value.

b : 'T

The second value.

decimalPlaces : int

The number of decimal places.

Returns: bool

Precision.AlmostEqualNumbersBetween(a, b, maxNumbersBetween)

Full Usage: Precision.AlmostEqualNumbersBetween(a, b, maxNumbersBetween)

Parameters:
    a : 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.

a : 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
ArgumentOutOfRangeException Thrown if maxNumbersBetween is smaller than one.

Precision.AlmostEqualNumbersBetween(a, b, maxNumbersBetween)

Full Usage: Precision.AlmostEqualNumbersBetween(a, b, maxNumbersBetween)

Parameters:
    a : 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.

a : 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
ArgumentOutOfRangeException Thrown if maxNumbersBetween is smaller than one.

Precision.AlmostEqualRelative(a, b, maximumError)

Full Usage: Precision.AlmostEqualRelative(a, b, maximumError)

Parameters:
    a : 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.

a : float

The first value.

b : float

The second value.

maximumError : float

The accuracy required for being almost equal.

Returns: bool

Precision.AlmostEqualRelative(a, b, maximumError)

Full Usage: Precision.AlmostEqualRelative(a, b, maximumError)

Parameters:
    a : 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.

a : float32

The first value.

b : float32

The second value.

maximumError : float

The accuracy required for being almost equal.

Returns: bool

Precision.AlmostEqualRelative(a, b)

Full Usage: Precision.AlmostEqualRelative(a, b)

Parameters:
    a : 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.

a : 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.

Precision.AlmostEqualRelative(a, b)

Full Usage: Precision.AlmostEqualRelative(a, b)

Parameters:
    a : 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.

a : 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.

Precision.AlmostEqualRelative(a, b, decimalPlaces)

Full Usage: Precision.AlmostEqualRelative(a, b, decimalPlaces)

Parameters:
    a : 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.

a : float

The first value.

b : float

The second value.

decimalPlaces : int

The number of decimal places.

Returns: bool

Precision.AlmostEqualRelative(a, b, decimalPlaces)

Full Usage: Precision.AlmostEqualRelative(a, b, decimalPlaces)

Parameters:
    a : 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.

a : float32

The first value.

b : float32

The second value.

decimalPlaces : int

The number of decimal places.

Returns: bool

Precision.CoerceZero(a, maxNumbersBetween)

Full Usage: Precision.CoerceZero(a, maxNumbersBetween)

Parameters:
    a : 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.

a : 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.

Precision.CoerceZero(a, maxNumbersBetween)

Full Usage: Precision.CoerceZero(a, maxNumbersBetween)

Parameters:
    a : 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.

a : 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.

ArgumentOutOfRangeException Thrown if maxNumbersBetween is smaller than zero.

Precision.CoerceZero(a, maximumAbsoluteError)

Full Usage: Precision.CoerceZero(a, maximumAbsoluteError)

Parameters:
    a : 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.

a : 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.

ArgumentOutOfRangeException Thrown if maximumAbsoluteError is smaller than zero.

Precision.CoerceZero(a)

Full Usage: Precision.CoerceZero(a)

Parameters:
    a : 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.

a : 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.

Precision.Decrement(value, ?count)

Full Usage: Precision.Decrement(value, ?count)

Parameters:
    value : 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.

value : 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.

Precision.EpsilonOf(value)

Full Usage: Precision.EpsilonOf(value)

Parameters:
    value : 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.

value : float

The value used to determine the minimum distance.

Returns: float

Relative Epsilon (positive double or NaN).

Precision.EpsilonOf(value)

Full Usage: Precision.EpsilonOf(value)

Parameters:
    value : 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.

value : float32

The value used to determine the minimum distance.

Returns: float32

Relative Epsilon (positive float or NaN).

Precision.Increment(value, ?count)

Full Usage: Precision.Increment(value, ?count)

Parameters:
    value : 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.

value : 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.

Precision.Magnitude(value)

Full Usage: Precision.Magnitude(value)

Parameters:
    value : float - The value.

Returns: int The magnitude of the number.

Returns the magnitude of the number.

value : float

The value.

Returns: int

The magnitude of the number.

Precision.Magnitude(value)

Full Usage: Precision.Magnitude(value)

Parameters:
    value : float32 - The value.

Returns: int The magnitude of the number.

Returns the magnitude of the number.

value : float32

The value.

Returns: int

The magnitude of the number.

Precision.MaximumMatchingFloatingPointNumber(value, maxNumbersBetween)

Full Usage: Precision.MaximumMatchingFloatingPointNumber(value, maxNumbersBetween)

Parameters:
    value : 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)

value : float

The value.

maxNumbersBetween : int64

The ulps difference.

Returns: float

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

Precision.MinimumMatchingFloatingPointNumber(value, maxNumbersBetween)

Full Usage: Precision.MinimumMatchingFloatingPointNumber(value, maxNumbersBetween)

Parameters:
    value : 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)

value : float

The value.

maxNumbersBetween : int64

The ulps difference.

Returns: float

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

Precision.NumbersBetween(a, b)

Full Usage: Precision.NumbersBetween(a, b)

Parameters:
    a : 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.

a : float

The first parameter.

b : float

The second parameter.

Returns: uint64

The number of floating point values between a and b.

ArgumentOutOfRangeException Thrown if a is double.PositiveInfinity or double.NegativeInfinity.
ArgumentOutOfRangeException Thrown if a is double.NaN.
ArgumentOutOfRangeException Thrown if b is double.PositiveInfinity or double.NegativeInfinity.
ArgumentOutOfRangeException Thrown if b is double.NaN.

Precision.PositiveEpsilonOf(value)

Full Usage: Precision.PositiveEpsilonOf(value)

Parameters:
    value : 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

value : float

The value used to determine the minimum distance.

Returns: float

Relative Epsilon (positive double or NaN)

Precision.PositiveEpsilonOf(value)

Full Usage: Precision.PositiveEpsilonOf(value)

Parameters:
    value : 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

value : float32

The value used to determine the minimum distance.

Returns: float32

Relative Epsilon (positive float or NaN)

Precision.RangeOfMatchingFloatingPointNumbers(value, maxNumbersBetween)

Full Usage: Precision.RangeOfMatchingFloatingPointNumbers(value, maxNumbersBetween)

Parameters:
    value : 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.

value : float

The value.

maxNumbersBetween : int64

The ulps difference.

Returns: float * float

Tuple of the bottom and top range ends.

ArgumentOutOfRangeException Thrown if maxNumbersBetween is smaller than zero.

Precision.RangeOfMatchingNumbers(value, relativeDifference)

Full Usage: Precision.RangeOfMatchingNumbers(value, relativeDifference)

Parameters:
    value : 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 ulps that will match the specified value with the given tolerance.

value : 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.

ArgumentOutOfRangeException Thrown if relativeDifference is smaller than zero.
ArgumentOutOfRangeException Thrown if value is double.PositiveInfinity or double.NegativeInfinity.
ArgumentOutOfRangeException Thrown if value is double.NaN.

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.Round(number, digits)

Full Usage: Precision.Round(number, digits)

Parameters:
    number : 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.

number : 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

Example

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

Precision.RoundToMultiple(number, basis)

Full Usage: Precision.RoundToMultiple(number, basis)

Parameters:
    number : 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.

number : float

Number to be rounded.

basis : float

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

Returns: float

Precision.RoundToMultiple(number, basis)

Full Usage: Precision.RoundToMultiple(number, basis)

Parameters:
    number : 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.

number : float32

Number to be rounded.

basis : float32

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

Returns: float32

Precision.RoundToMultiple(number, basis)

Full Usage: Precision.RoundToMultiple(number, basis)

Parameters:
    number : 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.

number : decimal

Number to be rounded.

basis : decimal

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

Returns: decimal

Precision.RoundToPower(number, basis)

Full Usage: Precision.RoundToPower(number, basis)

Parameters:
    number : 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.

number : float

Number to be rounded.

basis : float

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

Returns: float

Precision.RoundToPower(number, basis)

Full Usage: Precision.RoundToPower(number, basis)

Parameters:
    number : 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.

number : float32

Number to be rounded.

basis : float32

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

Returns: float32

Precision.ScaleUnitMagnitude(value)

Full Usage: Precision.ScaleUnitMagnitude(value)

Parameters:
    value : 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.

value : float

The value.

Returns: float

The value of the number.