dart_numerics library

dart-numerics

dart-numerics is an ultimate mathematical package inspired by .NET analogue, aiming to provide methods and algorithms for numerical computations in science, engineering and every day use.

Usage

A simple usage example:

import 'package:dart_numerics/dart_numerics.dart' as numerics;

main() {
  print(numerics.acosh(numerics.pi / 2));
}

Classes

Permutation
Class to represent a permutation for a subset of the natural numbers.
Polynomial
A single-variable polynomial with real-valued coefficients and non-negative exponents.

Constants

catalan → const double
The Catalan constant
degree → const double
The number (pi)/180 - factor to convert from Degree (deg) to Radians (rad).
doubleWidth → const int
The number of binary digits used to represent the binary number for a double precision floating point value. i.e. there are this many digits used to represent the actual number, where in a number as: 0.134556 * 10^5 the digits are 0.134556 and the exponent is 5.
e → const double
The number e
epsilon → const double
The smallest positive double value that is greater than zero.
eulerMascheroni → const double
The Euler-Mascheroni constant
factorialMaxArgument → const int
glaisher → const double
The Glaisher constant
goldenRatio → const double
The number (1+sqrt(5))/2, also known as the golden ratio
grad → const double
The number (pi)/200 - factor to convert from NewGrad (grad) to Radians (rad).
halfSqrt3 → const double
The number sqrt(3)/2
int64MaxValue → const int
The biggest possible value of an int within 64 bits.
int64MinValue → const int
The smallest possible value of an int within 64 bits.
invE → const double
The number 1/e
invPi → const double
The number 1/pi
invSqrt2Pi → const double
The number 1/sqrt(2pi)
invSqrtPi → const double
The number 1/sqrt(pi)
khinchin → const double
The Khinchin constant
ln10 → const double
The number loge
ln2 → const double
The number loge
ln2PiOver2 → const double
The number loge/2
lnPi → const double
The number loge
log10E → const double
The number log10
log2E → const double
The number log2
logSqrt2PiE → const double
The number log(sqrt(2pie))
logTwoSqrtEOverPi → const double
The number log(2 * sqrt(e / pi))
neutralDecibel → const double
The number ln(10)/10 - factor to convert from Neutral Decibel (dB) to Neper (Np). Use this version when either both or neither of the Decibel and the compared values represent powers.
pi → const double
The number pi
pi2 → const double
The number pi*2
pi3Over2 → const double
The number pi*3/2
piOver2 → const double
The number pi/2
piOver4 → const double
The number pi/4
powerDecibel → const double
The number ln(10)/20 - factor to convert from Power Decibel (dB) to Neper (Np). Use this version when the Decibel represent a power gain but the compared values are not powers (e.g. amplitude, current, voltage).
sogSqrt2Pi → const double
The number log(sqrt(2*pi))
sqrt1Over2 → const double
The number sqrt(1/2) = 1/sqrt(2) = sqrt(2)/2
sqrt2 → const double
The number sqrt(2)
sqrt2Pi → const double
The number sqrt(2pi)
sqrt2PiE → const double
The number sqrt(2pie)
sqrt3 → const double
The number sqrt(3)
sqrtE → const double
The number sqrt(e)
sqrtPi → const double
The number sqrt(pi)
twoInvPi → const double
The number 2/pi
twoInvSqrtPi → const double
The number 2/sqrt(pi)
twoSqrtEOverPi → const double
The number 2 * sqrt(e / pi)

Properties

doubleDecimalPlaces int
The number of significant decimal places of double-precision floating numbers (64 bit).
final
doublePrecision double
Standard epsilon, the maximum relative precision of IEEE 754 double-precision floating numbers (64 bit).
final
machineEpsilon double
Actual double precision machine epsilon, the smallest number that can be subtracted from 1, yielding a results different than 1.
final
multiplyDeBruijnBitPosition List<int>
getter/setter pair
positiveDoublePrecision double
Standard epsilon, the maximum relative precision of IEEE 754 double-precision floating numbers (64 bit).
final
positiveMachineEpsilon double
Actual double precision machine epsilon, the smallest number that can be added to 1, yielding a results different than 1.
final

Functions

acos(double adjacent) double
Trigonometric principal Arc Cosine in radian.
acosh(double value) double
Hyperbolic Area Cosine.
acot(double adjacent) double
Trigonometric principal Arc Cotangent in radian.
acoth(double value) double
Hyperbolic Area Cotangent.
acsc(double hypotenuse) double
Trigonometric principal Arc Cosecant in radian.
acsch(double value) double
Hyperbolic Area Cosecant.
almostEqual(double a, double b) bool
Checks whether two double numbers are almost equal.
almostEqualD(double a, double b, double maximumAbsoluteError) bool
Compares two doubles and determines if they are equal within the specified maximum error.
almostEqualI(double a, double b, int decimals) bool
Compares two doubles and determines if they are equal within the specified maximum error.
almostEqualNormD(double a, double b, double diff, double maximumAbsoluteError) bool
Compares two doubles and determines if they are equal within the specified maximum absolute error.
almostEqualNormI(double a, double b, double diff, int decimalPlaces) 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.
almostEqualNormRelativeD(double a, double b, double diff, double maximumError) bool
Compares two doubles and determines if they are equal within the specified maximum error.
almostEqualNormRelativeI(double a, double b, double diff, int decimalPlaces) 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.
almostEqualNumbersBetween(double a, double b, int maxNumbersBetween) bool
Compares two doubles and determines if they are equal to within the tolerance or not. Equality comparison is based on the binary representation.
almostEqualRelativeD(double a, double b, double maximumError) bool
Compares two doubles and determines if they are equal within the specified maximum error.
almostEqualRelativeI(double a, double b, int decimalPlaces) 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.
asec(double hypotenuse) double
Trigonometric principal Arc Secant in radian.
asech(double value) double
Hyperbolic Area Secant.
asin(double opposite) double
Trigonometric principal Arc Sine in radian.
asinh(double value) double
Hyperbolic Area Sine.
atan(double opposite) double
Trigonometric principal Arc Tangent in radian
atanh(double value) double
Hyperbolic Area Tangent.
beta(double z, double w) double
Computes the Euler Beta function.
betaIncomplete(double a, double b, double x) double
Returns the lower incomplete (unregularized) beta function B(a,b,x) = int(t^(a-1)*(1-t)^(b-1),t=0..x) for real a > 0, b > 0, 1 >= x >= 0.
betaLn(double z, double w) double
Computes the logarithm of the Euler Beta function.
betaRegularized(double a, double b, double x) double
Returns the regularized lower incomplete beta function I_x(a,b) = 1/Beta(a,b) * int(t^(a-1)*(1-t)^(b-1),t=0..x) for real a > 0, b > 0, 1 >= x >= 0.
binomial(int n, int k) double
Computes the binomial coefficient: n choose k.
binomialLn(int n, int k) double
Computes the natural logarithm of the binomial coefficient: ln(n choose k).
ceilingToPowerOfTwo(int number) int
Find the closest perfect power of two that is larger or equal to the provided integer.
coerceZero(double a) double
Forces small numbers near zero to zero.
coerceZeroD(double a, double maximumAbsoluteError) double
Forces small numbers near zero to zero, according to the specified absolute accuracy.
coerceZeroI(double a, int maxNumbersBetween) double
Forces small numbers near zero to zero, according to the specified absolute accuracy.
compareToD(double a, double b, double maximumAbsoluteError) int
Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
compareToI(double a, double b, int decimalPlaces) int
Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
compareToNumbersBetween(double a, double b, int maxNumbersBetween) int
Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
compareToRelativeD(double a, double b, double maximumError) int
Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
compareToRelativeI(double a, double b, int decimalPlaces) int
Compares two doubles and determines which double is bigger. a < b -> -1; a ~= b (almost equal according to parameter) -> 0; a > b -> +1.
cos(double radian) double
Trigonometric Cosine of an angle in radian, or adjacent / hypotenuse.
cosh(double angle) double
Hyperbolic Cosine.
cot(double radian) double
Trigonometric Cotangent of an angle in radian, or adjacent / opposite. Reciprocal of the tangent.
coth(double angle) double
Hyperbolic Cotangent.
csc(double radian) double
Trigonometric Cosecant of an angle in radian, or hypotenuse / opposite. Reciprocal of the sine.
csch(double angle) double
Hyperbolic Cosecant.
decrement(double value, [int count = 1]) double
Decrements a floating point number to the next smaller number representable by the data type.
degreeToGrad(double degree) double
Converts a degree (360-periodic) angle to a grad (400-periodic) angle.
degreeToRadian(double degree) double
Converts a degree (360-periodic) angle to a radian (2*Pi-periodic) angle.
diGamma(double x) double
Computes the Digamma function which is mathematically defined as the derivative of the logarithm of the gamma function.
diGammaInv(double p) double
Computes the inverse Digamma function: this is the inverse of the logarithm of the gamma function. This function will only return solutions that are positive.
epsilonOf(double value) double
Evaluates the minimum distance to the next distinguishable number near the argument value.
erf(double x) double
Calculates the error function.
erfc(double x) double
Calculates the complementary error function.
erfcInv(double z) double
Calculates the complementary inverse error function evaluated at z.
erfInv(double z) double
Calculates the inverse error function evaluated at z.
exponentialIntegral(double x, int n) double
Computes the generalized Exponential Integral function (En).
factorialBig(BigInt x) BigInt
Computes the factorial of an integer.
factorialD(int x) double
Computes the factorial function x -> x! of an integer number > 0. The function can represent all number up to 22! exactly, all numbers up to 170! using a double representation. All larger values will overflow.
factorialLn(int x) double
Computes the logarithmic factorial function x -> ln(x!) of an integer number > 0.
fit(List<double> x, List<double> y) → Tuple2<double, double>
Least-Squares fitting the points (x,y) to a line y : x -> a+b*x, returning its best fitting parameters as (a, b) tuple, where a is the intercept and b the slope.
fitFromMany(Iterable<Tuple2<double, double>> samples) → Tuple2<double, double>
Least-Squares fitting the points (x,y) to a line y : x -> a+b*x, returning its best fitting parameters as (a, b) tuple, where a is the intercept and b the slope.
fitThroughOrigin(List<double> x, List<double> y) double
Least-Squares fitting the points (x,y) to a line y : x -> b*x, returning its best fitting parameter b, where the intercept is zero and b the slope.
fitThroughOriginFromMany(Iterable<Tuple2<double, double>> samples) double
Least-Squares fitting the points (x,y) to a line y : x -> b*x, returning its best fitting parameter b, where the intercept is zero and b the slope.
gamma(double z) double
Computes the Gamma function.
gammaLn(double z) double
Computes the logarithm of the Gamma function.
gammaLowerIncomplete(double a, double x) double
Returns the lower incomplete gamma function gamma(a,x) = int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.
gammaLowerRegularized(double a, double x) double
Returns the lower incomplete regularized gamma function P(a,x) = 1/Gamma(a) * int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.
gammaLowerRegularizedInv(double a, double y0) double
Returns the inverse P^(-1) of the regularized lower incomplete gamma function P(a,x) = 1/Gamma(a) * int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0, such that P^(-1)(a,P(a,x)) == x.
gammaUpperIncomplete(double a, double x) double
Returns the upper incomplete gamma function Gamma(a,x) = int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.
gammaUpperRegularized(double a, double x) double
Returns the upper incomplete regularized gamma function Q(a,x) = 1/Gamma(a) * int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.
gradToDegree(double grad) double
Converts a grad (400-periodic) angle to a degree (360-periodic) angle.
gradToRadian(double grad) double
Converts a grad (400-periodic) angle to a radian (2*Pi-periodic) angle.
greatestCommonDivisor(int a, int b) int
Returns the greatest common divisor (gcd) of two integers using Euclid's algorithm.
greatestCommonDivisorBig(BigInt a, BigInt b) BigInt
Returns the greatest common divisor (gcd) of two BigInt using Euclid's algorithm.
greatestCommonDivisorOfMany(List<int> integers) int
Returns the greatest common divisor (gcd) of two integers using Euclid's algorithm.
greatestCommonDivisorOfManyBig(List<BigInt> integers) BigInt
Returns the greatest common divisor (gcd) of many BigInt using Euclid's algorithm.
increment(double value, [int count = 1]) double
Increments a floating point number to the next bigger number representable by the data type.
isEven(int number) bool
Find out whether the provided integer is an even number.
isLargerD(double a, double b, double maximumAbsoluteError) bool
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.
isLargerI(double a, double b, int decimalPlaces) bool
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.
isLargerNumbersBetween(double a, double b, int maxNumbersBetween) bool
Compares two doubles and determines if the a value is larger than the b value to within the tolerance or not. Equality comparison is based on the binary representation.
isLargerRelativeD(double a, double b, double maximumError) bool
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.
isLargerRelativeI(double a, double b, int decimalPlaces) bool
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.
isOdd(int number) bool
Find out whether the provided integer is an odd number.
isPerfectSquare(int number) bool
Find out whether the provided integer is a perfect square, i.e. a square of an integer.
isPowerOfTwo(int number) bool
Find out whether the provided integer is a perfect power of two.
isSmallerD(double a, double b, double maximumAbsoluteError) bool
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.
isSmallerI(double a, double b, int decimalPlaces) bool
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.
isSmallerNumbersBetween(double a, double b, int maxNumbersBetween) bool
Compares two doubles and determines if the a value is smaller than the b value to within the tolerance or not. Equality comparison is based on the binary representation.
isSmallerRelativeD(double a, double b, double maximumError) bool
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.
isSmallerRelativeI(double a, double b, int decimalPlaces) bool
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.
leastCommonMultiple(int a, int b) int
Returns the least common multiple (lcm) of two integers using Euclid's algorithm.
leastCommonMultipleBig(BigInt a, BigInt b) BigInt
Returns the least common multiple (lcm) of two BigInt using Euclid's algorithm.
leastCommonMultipleOfMany(List<int> integers) int
Returns the least common multiple (lcm) of many BigInt using Euclid's algorithm.
leastCommonMultipleOfManyBig(List<BigInt> integers) BigInt
Returns the least common multiple (lcm) of many BigInt using Euclid's algorithm.
line(List<double> x, List<double> y) → Tuple2<double, double>
Least-Squares fitting the points (x,y) to a line y : x -> a+b*x, returning its best fitting parameters as a, b array, where a is the intercept and b the slope.
lineFunc(List<double> x, List<double> y) double Function(double)
Least-Squares fitting the points (x,y) to a line y : x -> a+b*x, returning a function y' for the best fitting line.
lineThroughOrigin(List<double> x, List<double> y) double
Least-Squares fitting the points (x,y) to a line through origin y : x -> b*x, returning its best fitting parameter b, where the intercept is zero and b the slope.
lineThroughOriginFunc(List<double> x, List<double> y) double Function(double)
Least-Squares fitting the points (x,y) to a line through origin y : x -> b*x, returning a function y' for the best fitting line.
log10(num x) double
Converts x to a double and returns the common logarithm of the value.
log2(int number) int
Evaluate the binary logarithm of an integer number.
logistic(double p) double
Computes the logistic function. see: http://en.wikipedia.org/wiki/Logistic
logit(double p) double
Computes the logit function, the inverse of the sigmoid logistic function. see: http://en.wikipedia.org/wiki/Logit
magnitude(double value) int
Returns the magnitude of the number.
maximumMatchingFloatingPointNumber(double value, int maxNumbersBetween) double
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)
minimumMatchingFloatingPointNumber(double value, int maxNumbersBetween) double
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)
modulusBig(BigInt dividend, BigInt divisor) BigInt
Canonical Modulus. The result has the sign of the divisor.
modulusD(double dividend, double divisor) double
Canonical Modulus. The result has the sign of the divisor.
modulusI(int dividend, int divisor) int
Canonical Modulus. The result has the sign of the divisor.
multinomial(int n, List<int> ni) double
Computes the multinomial coefficient: n choose n1, n2, n3, ...
numbersBetween(double a, double b) int
Evaluates the count of numbers between two double numbers
positiveEpsilonOf(double value) double
Evaluates the minimum distance to the next distinguishable number near the argument value.
powerOfTwo(int exponent) int
Raises 2 to the provided integer exponent (0 < exponent).
radianToDegree(double radian) double
Converts a radian (2*Pi-periodic) angle to a degree (360-periodic) angle.
radianToGrad(double radian) double
Converts a radian (2*Pi-periodic) angle to a grad (400-periodic) angle.
rangeOfMatchingFloatingPointNumbers(double value, int maxNumbersBetween) → Tuple2<double, double>
Determines the range of floating point numbers that will match the specified value with the given tolerance.
rangeOfMatchingNumbers(double value, double relativeDifference) → Tuple2<int, int>
Determines the range of that will match the specified value with the given tolerance.
remainder(BigInt dividend, BigInt divisor) BigInt
Remainder (% operator). The result has the sign of the dividend.
remainderD(double dividend, double divisor) double
Remainder (% operator). The result has the sign of the dividend.
remainderI(int dividend, int divisor) int
Remainder (% operator). The result has the sign of the dividend.
scaleUnitMagnitude(double value) double
Returns the number divided by it's magnitude, effectively returning a number between -10 and 10.
sec(double radian) double
Trigonometric Secant of an angle in radian, or hypotenuse / adjacent. Reciprocal of the cosine.
sech(double angle) double
Hyperbolic Secant.
sin(double radian) double
Trigonometric Sine of an angle in radian, or opposite / hypotenuse.
sinc(double x) double
Normalized Sinc function. sinc(x) = sin(pi*x)/(pi*x).
sinh(double angle) double
Hyperbolic Sine.
tan(double radian) double
Trigonometric Tangent of an angle in radian, or opposite / adjacent.
tanh(double angle) double
Hyperbolic Tangent in radian.