FloatingPointExtensionMethods

public static class FloatingPointExtensionMethods
Extension methods for System.Double

Methods

ArrayTo

#Example
public static double[] ArrayTo(this double number0, double number1, int steps)
Create an array from this number to another.
number0 (double)First number in array.
number1 (double)Inclusive last number in array.
steps (int)Number of steps. Array will contain steps+1 elements.
Array from a to b.

ArrayTo

#Example
public static double[] ArrayTo(this double start, double limit, double stepSize)
Create an array of doubles from a value to a limit.
start (double)First value in array.
limit (double)Inclusive limit in array.
stepSize (double)Distance between elements.
Array.

ArrayTo

#Example
public static float[] ArrayTo(this float number0, float number1, int steps)
Create an array from this number to another.
number0 (float)First number in array.
number1 (float)Inclusive last number in array.
steps (int)Number of steps. Array will contain steps+1 elements.
Array from a to b.

AsColour

#Example
public static Color AsColour(this float luminance)
Create a greyscale colour.
luminance (float)

Average

#Example
public static double Average(this IEnumerable<double> numbers)
Compute the mean (average) of a collection of numbers. This method is designed to work with many numbers as well as very large numbers. Essentially, if you're certain that the sum of all values doesn't exceed 1e128, there are faster ways to compute the average.
numbers (IEnumerable<double>)Number collection.
Average of all numbers.

Average

#Example
public static float Average(this IEnumerable<float> numbers)
Compute the mean (average) of a collection of numbers. This method is designed to work with many numbers as well as very large numbers. Essentially, if you're certain that the sum of all values doesn't exceed 1e128, there are faster ways to compute the average.
numbers (IEnumerable<float>)Number collection.
Average of all numbers.
public static decimal Clip(this decimal number, decimal lowerLimit, decimal upperLimit)
Limit a number to a range.
number (decimal)Integer.
lowerLimit (decimal)Inclusive lower limit.
upperLimit (decimal)Inclusive upper limit.
Clipped number.
public static decimal Clip(this decimal number, decimal upperLimit)
Limit a number to a range.
number (decimal)Integer.
upperLimit (decimal)Inclusive upper limit.
Clipped number.
public static double Clip(this double number, double lowerLimit, double upperLimit)
Limit a number to a range.
number (double)Integer.
lowerLimit (double)Inclusive lower limit.
upperLimit (double)Inclusive upper limit.
Clipped number.
public static double Clip(this double number, double upperLimit)
Limit a number to a range.
number (double)Integer.
upperLimit (double)Inclusive upper limit.
Clipped number.
public static float Clip(this float number, float lowerLimit, float upperLimit)
Limit a number to a range.
number (float)Integer.
lowerLimit (float)Inclusive lower limit.
upperLimit (float)Inclusive upper limit.
Clipped number.
public static float Clip(this float number, float upperLimit)
Limit a number to a range.
number (float)Integer.
upperLimit (float)Inclusive upper limit.
Clipped number.

DecimalPrecision

#Example
public static int DecimalPrecision(this decimal value)
Gets the number of significant decimal places of a decimal number.
value (decimal)Value to test.
Number of decimal places.

EnumerateTo

#Example
public static IEnumerable<double> EnumerateTo(this double number0, double number1, int steps)
Create an enumeration from one value to another.
number0 (double)First number in enumeration.
number1 (double)Inclusive last number in enumeration.
steps (int)Number of steps. Enumeration will contain steps+1 elements.
Enumeration from a to b.

FormatHonest

#Example
public static string FormatHonest(this double value, int minimumDigits, int maximumDigits)
Format a double using a limited number of decimal places, appending an ellipsis whenever the displayed digits do not capture the exact value. The displayed digits are rounded, so 5.99999999993 formats as "6.0…" rather than "5.99999…".
value (double)Number to format.
minimumDigits (int)Minimum decimal places.
maximumDigits (int)Maximum decimal places, including the ellipsis if it's needed.

FormatScientific

#Example
public static string FormatScientific(this BigInteger value, int minimumDigits, int maximumDigits, bool superscript)
Format a bigInteger value using scientific base-10 notation.
value (BigInteger)Value to format.
minimumDigits (int)Minimum number of digits to use in the decimal.
maximumDigits (int)Maximum number of digits to use in the decimal.
superscript (bool)True if superscript exponents ought to be used.
Scientific format.

FormatScientific

#Example
public static string FormatScientific(this double value, int minimumDigits, int maximumDigits, bool superscript)
Format a double value using scientific base-10 notation.
value (double)Value to format.
minimumDigits (int)Minimum number of digits to use in the decimal.
maximumDigits (int)Maximum number of digits to use in the decimal.
superscript (bool)True if superscript exponents ought to be used.
Scientific format.

FractionalPart

#Example
public static double FractionalPart(this double value)
Return the fractional portion of a double. This method does not suffer from the same rounding issues as f = x % 1 or f = x - floor(x). For example try taking an arithmetical approach to finding the fractional part of 100000000000000.1 and you'll get 0.09375 instead of 0.1
value (double)Value to strip.
Fractional part between -1 and +1. Negative input values yield negative fractional parts.

GetMagnitude

#Example
public static void GetMagnitude(this double number, out int magnitude, out double scaledValue)
Gets both the magnitude of a number and the scaled value.
number (double)Number to measure.
magnitude (out int)Magnitude of number (power of ten).
scaledValue (out double)Scaled value (a number in between -10 and +10).

GetMagnitude

#Example
public static void GetMagnitude(this double number, out int magnitude)
Gets both the magnitude of a number.
number (double)Number to measure.
magnitude (out int)Magnitude of number (power of ten).

Highest

#Example
public static double Highest(this IEnumerable<double> numbers)
Gets the highest number in an array.
numbers (IEnumerable<double>)Collection of numbers.
Highest number in the set.

Highest

#Example
public static float Highest(this IEnumerable<float> numbers)
Gets the highest number in an array.
numbers (IEnumerable<float>)Collection of numbers.
Highest number in the set.

IntegralPart

#Example
public static double IntegralPart(this double value)
Return the integral portion of a double. This is equivalent to Math.Truncate().
value (double)Value to strip.
Integral part. Negative input values yield negative parts that are either equal to or larger than the input.

IsBetween

#Example
public static bool IsBetween(this double number, double limitA, double limitB)
Gets whether the number is in between both limits. This method returns true even if the number is coincident with the limits.
number (double)Number to test.
limitA (double)First limit.
limitB (double)Second limit.

IsBetween

#Example
public static bool IsBetween(this int number, int limitA, int limitB)
Gets whether the number is in between both limits. This method returns true even if the number is coincident with the limits.
number (int)Number to test.
limitA (int)First limit.
limitB (int)Second limit.

IsInteger32

#Example
public static bool IsInteger32(this double number)
Gets whether a double precision value is an exact integer in the 32-bit range.
number (double)Number to test.
True if number is expressible as a 32-bit integer without loss of information.

IsInteger64

#Example
public static bool IsInteger64(this double number)
Gets whether a double precision value is an exact integer in the 64-bit range.
number (double)Number to test.
True if number is expressible as a 64-bit integer without loss of information.

Lowest

#Example
public static double Lowest(this IEnumerable<double> numbers)
Gets the lowest number in an array.
numbers (IEnumerable<double>)Collection of numbers.
Lowest number in the set.

Lowest

#Example
public static float Lowest(this IEnumerable<float> numbers)
Gets the lowest number in an array.
numbers (IEnumerable<float>)Collection of numbers.
Lowest number in the set.
public static double Map(this double value, double sourceMinimum, double sourceMaximum, double targetMinimum, double targetMaximum)
Map a value from one numeric domain to another.
value (double)Value to map.
sourceMinimum (double)Start of source domain.
sourceMaximum (double)End of source domain.
targetMinimum (double)Start of target domain.
targetMaximum (double)End of target domain.
Mapped value.
public static double Map(this double value, double targetMinimum, double targetMaximum)
Map a normalised value to a new numeric domain.
value (double)Value to map.
targetMinimum (double)Start of target domain.
targetMaximum (double)End of target domain.
Mapped value.
public static float Map(this float value, float sourceMinimum, float sourceMaximum, float targetMinimum, float targetMaximum)
Map a value from one numeric domain to another.
value (float)Value to map.
sourceMinimum (float)Start of source domain.
sourceMaximum (float)End of source domain.
targetMinimum (float)Start of target domain.
targetMaximum (float)End of target domain.
Mapped value.
public static float Map(this float value, float targetMinimum, float targetMaximum)
Map a normalised value to a new numeric domain.
value (float)Value to map.
targetMinimum (float)Start of target domain.
targetMaximum (float)End of target domain.
Mapped value.

Median

#Example
public static double Median(this IEnumerable<double> values)
Compute the median of a collection of numbers. This method uses the QuickMedian algorithm.
values (IEnumerable<double>)Value to take into consideration.
Median of values.

Median

#Example
public static float Median(this IEnumerable<float> values)
Compute the median of a collection of numbers. This method uses the QuickMedian algorithm.
values (IEnumerable<float>)Value to take into consideration.
Median of values.
public static double Next(this double number, int count)
Gets the first double value that is larger than the current one.
number (double)Number to increment.
count (int)Number of steps to take.
Next double value.
public static double Next(this double number)
Gets the first double value that is larger than the current one.
number (double)Number to increment.
Next double value.

NextEpsilon

#Example
public static double NextEpsilon(this double number)
Gets the distance from this number to the next possible number.
number (double)Number to measure from.
Epsilon to next value.

NextOrderOfMagnitude

#Example
public static BigInteger NextOrderOfMagnitude(this BigInteger number)
Gets the order of magnitude bigger than or equal to the given number. The value returned is equal to or bigger than number, where "bigger" means further away from zero. Ie. negative values will result in larger negative values.
number (BigInteger)Number.
Order of magnitude.

NextOrderOfMagnitude

#Example
public static decimal NextOrderOfMagnitude(this decimal number)
Gets the order of magnitude bigger than or equal to the given number. The value returned is equal to or bigger than number, where "bigger" means further away from zero. Ie. negative values will result in larger negative values.
number (decimal)Number.
Order of magnitude.

NextOrderOfMagnitude

#Example
public static double NextOrderOfMagnitude(this double number)
Gets the order of magnitude bigger than or equal to the given number. The value returned is equal to or bigger than number, where "bigger" means further away from zero. Ie. negative values will result in larger negative values.
number (double)Number.
Order of magnitude.

NextOrderOfMagnitude

#Example
public static int NextOrderOfMagnitude(this int number)
Gets the order of magnitude bigger than or equal to the given number. The value returned is equal to or bigger than number, where "bigger" means further away from zero. Ie. negative values will result in larger negative values.
number (int)Number.
Order of magnitude.

NumbersBetween

#Example
public static ulong NumbersBetween(this double number, double other)
Gets the number of steps between two values. This is one more than the amount of unique numbers in between a and b.
number (double)First number.
other (double)Second number.
Number of steps between values.
public static double Prev(this double number, int count)
Gets the first double value that is smaller than the current one.
number (double)Number to decrement.
count (int)Number of steps to take.
Previous double value.
public static double Prev(this double number)
Gets the first double value that is smaller than the current one.
number (double)Number to decrement.
PRevious double value.

PrevEpsilon

#Example
public static double PrevEpsilon(this double number)
Gets the distance from this number to the previous possible number.
number (double)Number to measure from.
Epsilon to prev value.

PrevOrderOfMagnitude

#Example
public static BigInteger PrevOrderOfMagnitude(this BigInteger number)
Gets the order of magnitude smaller than or equal to the given number. The value returned is equal to or smaller than number, where "smaller" means closer to zero. Ie. negative values will result in smaller negative values.
number (BigInteger)Number.
Order of magnitude.

PrevOrderOfMagnitude

#Example
public static decimal PrevOrderOfMagnitude(this decimal number)
Gets the order of magnitude smaller than or equal to the given number. The value returned is equal to or smaller than number, where "smaller" means closer to zero. Ie. negative values will result in smaller negative values.
number (decimal)Number.
Order of magnitude.

PrevOrderOfMagnitude

#Example
public static double PrevOrderOfMagnitude(this double number)
Gets the order of magnitude smaller than or equal to the given number. The value returned is equal to or smaller than number, where "smaller" means closer to zero. Ie. negative values will result in smaller negative values.
number (double)Number.
Order of magnitude.

PrevOrderOfMagnitude

#Example
public static int PrevOrderOfMagnitude(this int number)
Gets the order of magnitude smaller than or equal to the given number. The value returned is equal to or smaller than number, where "smaller" means closer to zero. Ie. negative values will result in smaller negative values.
number (int)Number.
Order of magnitude.

UniqueValuesBetween

#Example
public static ulong UniqueValuesBetween(this double number, double other)
Gets the total number of unique doubles between two values.
number (double)Initial value.
other (double)Other value.
Total number of unique doubles that span the given range.