IGLib
1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
|
Contains addtional basic math operations. More...
Static Public Member Functions | |
static double | Pow (double x, int n) |
Rasises an argument to an integer power. More... | |
static double | Hypot (double x, double y) |
Computes the length of a right triangle's hypotenuse. More... | |
static double | ExpMinusOne (double x) |
Computes ex-1. More... | |
static double | LogOnePlus (double x) |
Computes log(1+x). More... | |
static double | Sqr (double x) |
Computes x2. More... | |
static double | Sin (double x) |
Computes the sine of the given value to full significance over the full range of arguments. More... | |
static double | Cos (double x) |
Computes the cosine of the given value to full significance over the full range of arguments. More... | |
Contains addtional basic math operations.
The System.Math class defines many basic math operations, but a few that are important for optimal numerical practice are missing. They are defined by this class.
|
inlinestatic |
Rasises an argument to an integer power.
x | The argument. |
n | The power. |
Low integer powers can be computed by optimized algorithms much faster than the general alrogithm for an arbitrary real power employed by System.Math.Pow.
Referenced by Test.AdvancedMathTest.AiryBairyIntegral(), Test.AdvancedMathTest.AiryIntegrals(), Test.SampleTest.AnovaStudentAgreement(), FutureTest.FutureTest.ApproximateInverseBetaSeries(), Meta.Numerics.Statistics.Distributions.GammaDistribution.ApproximateInverseStandardGamma(), Test.MultiIntegrateTest.BallVolumeIntegrals(), Meta.Numerics.Functions.AdvancedIntegerMath.BellNumber(), Meta.Numerics.Functions.AdvancedMath.BesselJ_Series(), Test.AdvancedMathTest.BesselModifiedBesselRelationship(), FutureTest.FutureTest.BesselY(), FutureTest.FutureTest.BesselY_Series(), FutureTest.FutureTest.BesselY_Series2(), Test.MoreMathTest.BigTrig(), Test.AdvancedIntegerMathTest.BinomialCoefficientSums(), Test.BivariateSampleTest.BivariatePolynomialRegression(), Test.AdvancedMathTest.CarlsonLemniscaticValues(), Meta.Numerics.Functions.AdvancedMath.ClausenNearPi(), Meta.Numerics.Functions.AdvancedMath.ComputeBorweinEtaCoefficients(), FutureTest.FutureTest.ComputeChiTest(), FutureTest.FutureTest.CubicHermiteMinimum(), Meta.Numerics.Statistics.Distributions.WaldDistribution.Cumulant(), Meta.Numerics.Statistics.Distributions.ExponentialDistribution.Cumulant(), Meta.Numerics.Statistics.Distributions.ChiSquaredDistribution.Cumulant(), Meta.Numerics.Statistics.Distributions.DiscreteUniformDistribution.Cumulant(), Meta.Numerics.Statistics.Distributions.UniformDistribution.Cumulant(), Meta.Numerics.Statistics.Distributions.LogisticDistribution.Cumulant(), Meta.Numerics.Statistics.Distributions.GammaDistribution.Cumulant(), Meta.Numerics.Statistics.Distributions.GumbelDistribution.Cumulant(), Test.AdvancedMathTest.DiLogBailyIdentity(), Test.DistributionTest.DistributionCentralMomentIntegral(), Test.AdvancedMathTest.EllipticFBetaRelationship(), Test.AdvancedMathTest.EllipticFIntegral(), Meta.Numerics.Functions.AdvancedIntegerMath.FibonacciNumber(), Test.ExtremaTest.FindSpaceMinimumOfRosenbock(), Meta.Numerics.Statistics.UncertainMeasurementSample.FitToPolynomial(), Meta.Numerics.Statistics.Distributions.WaldDistribution.FitToSample(), Test.MultiIntegrateTest.GaussianIntegrals(), Test.MultiExtremumTest.GoldsteinPrice(), Test.MoreMathTest.IntegerPowerTest(), Meta.Numerics.Functions.AdvancedMath.IntegralE(), Test.AdvancedMathTest.IntegralEIncompleteGamma(), Test.AdvancedMathTest.IntegralEIntegral(), Meta.Numerics.Statistics.Distributions.BinomialDistribution.InverseLeftProbability(), Meta.Numerics.Statistics.Distributions.GeometricDistribution.LeftExclusiveProbability(), Test.OrthogonalPolynomialsTest.LegendreTuronInequality(), Test.ExtremaTest.MinimizeGoldsteinPrice(), Meta.Numerics.Statistics.Distributions.ExponentialDistribution.Moment(), Meta.Numerics.Statistics.Distributions.Distribution.Moment(), Meta.Numerics.Statistics.Distributions.BinomialDistribution.Moment(), Meta.Numerics.Statistics.Distributions.ParetoDistribution.Moment(), Meta.Numerics.Statistics.Distributions.GeometricDistribution.Moment(), Meta.Numerics.Statistics.Distributions.DiscreteDistribution.Moment(), Meta.Numerics.Statistics.MultivariateSample.Moment(), Meta.Numerics.Statistics.Sample.Moment(), Meta.Numerics.Statistics.Distributions.NormalDistribution.MomentAboutMean(), Meta.Numerics.Statistics.Distributions.ExponentialDistribution.MomentAboutMean(), Meta.Numerics.Statistics.Distributions.Distribution.MomentAboutMean(), Meta.Numerics.Statistics.Distributions.BernoulliDistribution.MomentAboutMean(), Meta.Numerics.Statistics.Distributions.DiscreteAsContinuousDistribution.MomentAboutMean(), Meta.Numerics.Statistics.Distributions.UniformDistribution.MomentAboutMean(), Meta.Numerics.Statistics.Distributions.LogisticDistribution.MomentAboutMean(), Meta.Numerics.Statistics.Distributions.DiscreteDistribution.MomentAboutMean(), Meta.Numerics.Statistics.MultivariateSample.MomentAboutMean(), Meta.Numerics.Statistics.BivariateSample.MomentAboutMean(), Meta.Numerics.Statistics.Sample.MomentAboutMean(), Test.RootsTest.MultiRootExtendedRosenbock(), Test.RootsTest.MultiRootTrigExp(), Test.MultiExtremumTest.Perm(), Test.MultiExtremumTest.PerturbedQuadratic(), Test.AdvancedMathTest.PolyGammaDuplication(), Test.AdvancedMathTest.PolyGammaIntegral(), Test.AdvancedMathTest.PolyGammaRecurrence(), Test.AdvancedMathTest.PolyGammaRiemann(), Meta.Numerics.Functions.AdvancedMath.PolyLog(), Meta.Numerics.Functions.AdvancedMath.PolyLog_BernoulliSum(), Meta.Numerics.Functions.AdvancedMath.PolyLog_Series(), Test.AdvancedMathTest.PolyLogDuplication(), Test.AdvancedMathTest.PolyLogOneHalf(), Meta.Numerics.Statistics.Distributions.PoissonDistribution.ProbabilityMass(), Meta.Numerics.Statistics.Distributions.BinomialDistribution.ProbabilityMass(), Meta.Numerics.Statistics.Distributions.GeometricDistribution.ProbabilityMass(), Meta.Numerics.Functions.AdvancedMath.Psi(), Test.MultiIntegrateTest.RambleIntegral(), Test.MultiIntegrateTest.RambleIntegrals(), Meta.Numerics.Statistics.Distributions.GeometricDistribution.RightExclusiveProbability(), Test.MultiExtremumTest.Rosenbrock(), Test.MultiIntegrateTest.SeperableIntegrals(), Meta.Numerics.Functions.AdvancedMath.SphericalBesselY_Series(), Meta.Numerics.Statistics.Distributions.UniformDistribution.SumOfPowers(), Test.MultiExtremumTest.SumOfPowers(), FutureTest.FutureTest.TestNormalOrderStatistic(), Test.AdvancedMathTest.TetraGammaReflection(), Test.MultiExtremumTest.ThreeHumpCamel(), Test.DistributionTest.TransformedBetaMoments(), Test.AdvancedMathTest.TriGammaReflection(), Test.AdvancedMathTest.TriLogSpecialCases(), and Test.MultiIntegrateTest.WatsonIntegrals().
|
inlinestatic |
Computes the length of a right triangle's hypotenuse.
x | The length of one side. |
y | The length of another side. |
The length is computed accurately, even in cases where x2 or y2 would overflow.
Referenced by Meta.Numerics.ComplexMath.Abs(), Test.MoreMathTest.BigHypotenuseTest(), Meta.Numerics.Functions.AdvancedMath.CoulombFactor(), Meta.Numerics.UncertainValue.operator*(), Meta.Numerics.UncertainValue.operator+(), Meta.Numerics.UncertainValue.operator-(), Meta.Numerics.UncertainValue.operator/(), Test.MultiExtremumTest.PackCirclesInCircle(), Test.MultiExtremumTest.PackCirclesInSquare(), Test.MoreMathTest.SmallHypotenuseTest(), and FutureTest.FutureTest.TwoByTwoSchur().
|
inlinestatic |
Computes ex-1.
x | The argument. |
If x is close to 0, then ex is close to 1, and computing ex-1 by by subtracting one from ex as computed by the Math.Exp function will be subject to severe loss of significance due to cancelation. This method maintains full precision for all values of x by switching to a series expansion for values of x near zero.
Referenced by Meta.Numerics.Statistics.Distributions.ExponentialDistribution.LeftProbability(), Meta.Numerics.Statistics.Distributions.WeibullDistribution.LeftProbability(), Test.AdvancedMathTest.PolyGammaIntegral(), and Meta.Numerics.Statistics.Distributions.GumbelDistribution.RightProbability().
|
inlinestatic |
Computes log(1+x).
x | The argument. |
If x is close to 0, computing log(1+x) by first adding one and then taking the log can result in a loss of accuracy. This function maintains full precision of all values of x by switching to a series expansion for values of x near zero.
Referenced by Meta.Numerics.Statistics.Distributions.ExponentialDistribution.InverseLeftProbability(), Meta.Numerics.Statistics.Distributions.WeibullDistribution.InverseLeftProbability(), and Meta.Numerics.Functions.AdvancedMath.PolyLog().
|
inlinestatic |
Computes x2.
x | The argument. |
There is nothing numericaly sophisticated inside this function; it exists simply for programmers' convenience. Given a complicated expression that needs to be squared, it is nice to be able to wrap it in a simple function call instead of explicitly assigning its value to a new variable and then multiplying that variable by itself.
Referenced by Test.MultiExtremumTest.Beale(), FutureTest.FutureTest.BesselExactTest(), Meta.Numerics.Statistics.Histogram.ChiSquaredTest(), Test.MultiExtremumTest.Easom(), Meta.Numerics.Matrices.AnyRectangularMatrix.FrobeniusNorm(), Test.MultiIntegrateTest.IsingIntegrals(), Test.MultiExtremumTest.McCormick(), Meta.Numerics.Statistics.Distributions.LognormalDistribution.Moment(), Meta.Numerics.Statistics.Sample.Moment(), Meta.Numerics.Statistics.Distributions.LognormalDistribution.MomentAboutMean(), Meta.Numerics.Statistics.Sample.OneWayAnovaTest(), Test.MultiExtremumTest.PackSpheresInCube(), Test.MultiExtremumTest.Perm(), Test.MultiExtremumTest.PerturbedQuadratic(), Test.AdvancedMathTest.PolyLogOneHalf(), Test.MultiExtremumTest.Quadratic(), Test.SampleTest.SamplePopulationMomentEstimateVariances(), Test.MultiExtremumTest.SmoothedEasom(), FutureTest.FutureTest.STA(), Test.MultiExtremumTest.StylblinskiTang(), FutureTest.FutureTest.TwoSampleKS2(), Test.UnivariateDistributionTest.UnivariateDistributionExcessKurtosis(), and Test.MultiExtremumTest.Vardim().
|
inlinestatic |
Computes the sine of the given value to full significance over the full range of arguments.
x | The argument. |
This method addresses several subtle shortcommings of the System.Math.Sin method. One shortcoming, quite striking but rarely encountered, is that Math.Sin returns entirely wrong results very large arguments; for x larger than about 1020, it simply returns the argument as the function value! (I have no idea why the base class library designers did not at least choose to return Double.NaN so as to signal to the user that the result should not be trusted. No floating point standard specifies this crazy behavior.) Another shortcomming, more commonly encountered but often unnoticed, is that for large but not necessarily very large arguments, values loose precision near zeros of the function.
One way to view these shortcommings is that they are justified by the uncertainty inherent in floating point representations. In this view, any System.Double should be seen as an uncertain value with a relative error of ~10-16. If the absolute value of the number is very large then the absolute value of this error can be as large or larger than 2π in this circumstance we should not expect to be able to say anything about the value. (Except, of course, that it is between -1 and +1, which is violated by the designers' crazy choice to return the argument as the value).
A contrary view is that it is better to treat all arguments as infinitely precise and return the nearest representable System.Double to the actual function value under this assumption. Users are unlikely to complain that we returned a more accurate value and this behavior is particularly useful when the argument is an intermediate result that the programmer may not even realize has become large.
For typical arguments, say between 10-4-4 and 104, the extra cost of this function over Math.Sin is just a couple of comparisons and a single floating point operation; less than 0.1% of arguments in this range are then routed to our much slower, higher-accuracy algorithm. We therefore suggest that, for general use, you prefer this method over Math.Sin; only in very unusual situations where (i) you are guaranteed never to encounter very large arguments, (ii) full precision values are not required, and (iii) the run-time of your application is critical and dominated by trigonometric calculations, should you prefer the base class library method.
Referenced by Meta.Numerics.ComplexMath.Cos(), Meta.Numerics.Functions.AdvancedMath.EllipticE(), Meta.Numerics.Functions.AdvancedMath.EllipticF(), Meta.Numerics.ComplexMath.Exp(), Meta.Numerics.ComplexMath.Pow(), Meta.Numerics.ComplexMath.Sin(), Meta.Numerics.Functions.AdvancedMath.SphericalBesselJ_One(), Meta.Numerics.Functions.AdvancedMath.SphericalBesselJ_Zero(), Meta.Numerics.Functions.AdvancedMath.SphericalBesselY_One(), Meta.Numerics.Functions.AdvancedMath.SphericalHarmonic(), and Meta.Numerics.ComplexMath.Tan().
|
inlinestatic |
Computes the cosine of the given value to full significance over the full range of arguments.
x | The argument. |
For an explanaition of this method, see the remarks for the MoreMath.Sin method.
Referenced by Test.MoreMathTest.BigTrig(), Meta.Numerics.ComplexMath.Cos(), Meta.Numerics.Functions.AdvancedMath.EllipticF(), Meta.Numerics.ComplexMath.Exp(), Meta.Numerics.ComplexMath.Pow(), Meta.Numerics.Functions.AdvancedMath.RiemannZeta(), Meta.Numerics.ComplexMath.Sin(), Meta.Numerics.Functions.AdvancedMath.SphericalBesselJ_One(), Meta.Numerics.Functions.AdvancedMath.SphericalBesselY_One(), Meta.Numerics.Functions.AdvancedMath.SphericalBesselY_Zero(), Meta.Numerics.Functions.AdvancedMath.SphericalHarmonic(), and Meta.Numerics.ComplexMath.Tan().