KSLMath

object KSLMath

This class implements additional mathematical functions and determines the parameters of the floating point representation.

This is based on the DhbMath class of Didier Besset in "Object-Oriented Implementation of Numerical Methods", Morgan-Kaufmann

Properties

Link copied to clipboard

The default numerical precision. This represents an estimate of the precision expected for a general numerical computation. For example, two numbers x and y can be considered equal if the relative difference between them is less than the default numerical precision. This value has been defined as the square root of the machine precision

Link copied to clipboard

Largest argument for an exponential

Link copied to clipboard

Largest possible number

Link copied to clipboard
val logger: KLogger

Use for general logging

Link copied to clipboard

Largest positive value which, when added to 1.0, yields 0.

Link copied to clipboard

A variable that can be used in algorithms to specify the maximum number of iterations. This is an object property and thus a change will change it for any algorithm that depends on this variable. Must be greater than 0

Link copied to clipboard

Largest positive value which, when subtracted to 1.0, yields 0.

Link copied to clipboard
val radix: Int

Radix used by floating-point numbers.

Link copied to clipboard

Smallest argument for the exponential

Link copied to clipboard

Smallest number different from zero.

Link copied to clipboard

Typical meaningful small number for numerical calculations. A number that can be added to some value without noticeably changing the result of the computation

Functions

Link copied to clipboard

Computes the binomial coefficient. Computes the number of combinations of size k that can be formed from n distinct objects.

Computes the binomial coefficient. Computes the number of combinations of size k that can be formed from n distinct objects.

Link copied to clipboard
fun equal(a: Double, b: Double, precision: Double = defaultNumericalPrecision): Boolean

Compares two numbers a and b and checks if they are within the supplied precision of each other.

Link copied to clipboard

Returns the factorial (n!) of the number

Link copied to clipboard
fun kthRoot(x: Double, k: Int): Double

Computes the kth root of x

Link copied to clipboard

Computes the natural logarithm of the factorial operator. ln(n!)

Link copied to clipboard
fun roundTo(value: Double, scale: Double): Double

This method returns the specified value rounded to the nearest integer multiple of the specified scale.

Link copied to clipboard
fun roundToScale(value: Double, integerValued: Boolean): Double

Round the specified value upward to the next scale value.

Link copied to clipboard

If x <= 0.0, then return ln(Double.MIN_VALUE). Since Double.MIN_VALUE is the smallest possible value that is closest to 0.0 without being 0.0. This prevents, ln(0.0) = -Infinity from appearing in calculations.

Link copied to clipboard
fun sign(x: Double): Double

Get the sign of the number based on the equal() method Equal is 0.0, positive is 1.0, negative is -1.0

Link copied to clipboard

Converts a double to a boolean. 1.0 is true. Double.NEGATIVE_INFINITY is mapped to false, Double.POSITIVE_INFINITY is mapped to true, any other double values other are mapped to false.

Link copied to clipboard
fun toByteValue(value: Double): Byte

Converts a double to a byte. If the double is outside the natural range, then the value is set to the minimum or maximum of the range. If within the range, the value is rounded to the nearest value. For example, 4.9999 is rounded to 5.0.

Link copied to clipboard

Converts a double to a float. Standard loss of precision as noted by the Java Language Specification will occur as per Double.floatValue()

Link copied to clipboard
fun toIntValue(value: Double): Int

Converts a double to an int. If the double is outside the natural range, then the value is set to the minimum or maximum of the range. If within the range, the value is rounded to the nearest value. For example, 4.9999 is rounded to 5.0.

Link copied to clipboard
fun toLongValue(value: Double): Long

Converts a double to a long. If the double is outside the natural range, then the value is set to the minimum or maximum of the range. If within the range, the value is rounded to the nearest value. For example, 4.9999 is rounded to 5.0.

Link copied to clipboard

Converts a double to a short. If the double is outside the natural range, then the value is set to the minimum or maximum of the range. If within the range, the value is rounded to the nearest value. For example, 4.9999 is rounded to 5.0.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun within(a: Double, b: Double, precision: Double = defaultNumericalPrecision): Boolean

Returns true if Math.abs(a-b) < precision