├── .asf.yaml ├── .gitattributes ├── .github ├── GH-ROBOTS.txt ├── dependabot.yml └── workflows │ ├── codeql-analysis.yml │ ├── coverage.yml │ ├── maven.yml │ └── scorecards-analysis.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── RELEASE-NOTES.txt ├── SECURITY.md ├── commons-numbers-angle ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── angle │ │ ├── Angle.java │ │ ├── CosAngle.java │ │ ├── Reduce.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── angle │ ├── AngleTest.java │ ├── CosAngleTest.java │ ├── ReduceTest.java │ └── UserGuideTest.java ├── commons-numbers-arrays ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── arrays │ │ ├── BitIndexUpdatingInterval.java │ │ ├── HashIndexSet.java │ │ ├── IndexSupport.java │ │ ├── KeyUpdatingInterval.java │ │ ├── MultidimensionalCounter.java │ │ ├── QuickSelect.java │ │ ├── Selection.java │ │ ├── SortInPlace.java │ │ ├── Sorting.java │ │ ├── UpdatingInterval.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── arrays │ ├── HashIndexSetTest.java │ ├── IndexSupportTest.java │ ├── KeyUpdatingIntervalTest.java │ ├── MultidimensionalCounterTest.java │ ├── SelectionTest.java │ ├── SortInPlaceTest.java │ ├── SortingTest.java │ ├── UpdatingIntervalTest.java │ └── UserGuideTest.java ├── commons-numbers-bom ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── resources-filtered │ │ └── bom.xml │ └── site │ ├── resources │ └── style │ │ └── module.css │ ├── site.xml │ └── xdoc │ └── index.xml ├── commons-numbers-combinatorics ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── combinatorics │ │ ├── BinomialCoefficient.java │ │ ├── BinomialCoefficientDouble.java │ │ ├── Combinations.java │ │ ├── CombinatoricsException.java │ │ ├── Factorial.java │ │ ├── FactorialDouble.java │ │ ├── LogBinomialCoefficient.java │ │ ├── LogFactorial.java │ │ ├── Stirling.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── combinatorics │ ├── BinomialCoefficientDoubleTest.java │ ├── BinomialCoefficientTest.java │ ├── CombinationsTest.java │ ├── FactorialDoubleTest.java │ ├── FactorialTest.java │ ├── LogBinomialCoefficientTest.java │ ├── LogFactorialTest.java │ ├── StirlingTest.java │ └── UserGuideTest.java ├── commons-numbers-complex-streams ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── complex │ │ └── streams │ │ ├── ComplexUtils.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ └── profile.jacoco │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── complex │ └── streams │ ├── ComplexUtilsTest.java │ └── TestUtils.java ├── commons-numbers-complex ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── complex │ │ ├── Complex.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── complex │ │ ├── CReferenceTest.java │ │ ├── CStandardTest.java │ │ ├── ComplexEdgeCaseTest.java │ │ ├── ComplexTest.java │ │ ├── TestUtils.java │ │ └── UserGuideTest.java │ └── resources │ └── data │ ├── acos.txt │ ├── acosh.txt │ ├── asinh.txt │ ├── atanh.txt │ ├── cosh.txt │ ├── divide.txt │ ├── exp.txt │ ├── log.txt │ ├── multiply.txt │ ├── pow.txt │ ├── sinh.txt │ ├── sqrt.txt │ └── tanh.txt ├── commons-numbers-core ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── core │ │ ├── Addition.java │ │ ├── ArithmeticUtils.java │ │ ├── DD.java │ │ ├── DDMath.java │ │ ├── ExtendedPrecision.java │ │ ├── Multiplication.java │ │ ├── NativeOperators.java │ │ ├── Norm.java │ │ ├── Precision.java │ │ ├── Sum.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── core │ │ ├── AdditionTest.java │ │ ├── ArithmeticUtilsTest.java │ │ ├── DDExt.java │ │ ├── DDTest.java │ │ ├── DoubleTestUtils.java │ │ ├── EpsilonDoubleEquivalenceTest.java │ │ ├── ExtendedPrecisionTest.java │ │ ├── MultiplicationTest.java │ │ ├── NormTest.java │ │ ├── PrecisionTest.java │ │ ├── SumTest.java │ │ ├── TestUtils.java │ │ └── UserGuideTest.java │ └── resources │ └── org │ └── apache │ └── commons │ └── numbers │ └── core │ ├── sqrt-512.csv │ ├── sqrt0.csv │ └── sqrt512.csv ├── commons-numbers-docs ├── README.md ├── pom.xml └── src │ └── site │ ├── site.xml │ └── xdoc │ └── index.xml ├── commons-numbers-examples ├── LICENSE ├── NOTICE ├── README.md ├── examples-jmh │ ├── LICENSE │ ├── NOTICE │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── commons │ │ │ └── numbers │ │ │ └── examples │ │ │ └── jmh │ │ │ ├── arrays │ │ │ ├── BinarySearchKeyInterval.java │ │ │ ├── BitIndexUpdatingInterval.java │ │ │ ├── CompressedIndexSet.java │ │ │ ├── CompressedIndexSet2.java │ │ │ ├── DoubleDataTransformer.java │ │ │ ├── DoubleDataTransformers.java │ │ │ ├── DoubleMath.java │ │ │ ├── DualPivotingStrategy.java │ │ │ ├── HashIndexSet.java │ │ │ ├── IndexIntervals.java │ │ │ ├── IndexIterator.java │ │ │ ├── IndexIterators.java │ │ │ ├── IndexSet.java │ │ │ ├── IndexSortingPerformance.java │ │ │ ├── IntervalAnalysis.java │ │ │ ├── KeyIndexIterator.java │ │ │ ├── KeyUpdatingInterval.java │ │ │ ├── KthSelector.java │ │ │ ├── NaNPolicy.java │ │ │ ├── Partition.java │ │ │ ├── PartitionFactory.java │ │ │ ├── PivotCache.java │ │ │ ├── PivotCaches.java │ │ │ ├── PivotStore.java │ │ │ ├── PivotingStrategy.java │ │ │ ├── ScanningKeyInterval.java │ │ │ ├── ScanningPivotCache.java │ │ │ ├── SearchableInterval.java │ │ │ ├── SearchableInterval2.java │ │ │ ├── SelectionPerformance.java │ │ │ ├── Sorting.java │ │ │ ├── SplittingInterval.java │ │ │ ├── UpdatingInterval.java │ │ │ └── package-info.java │ │ │ ├── complex │ │ │ ├── ComplexPerformance.java │ │ │ ├── SinCosPerformance.java │ │ │ └── package-info.java │ │ │ ├── core │ │ │ ├── ArithmeticPerformance.java │ │ │ ├── DDPerformance.java │ │ │ ├── DoublePrecision.java │ │ │ ├── DoubleSplitPerformance.java │ │ │ ├── DoubleUtils.java │ │ │ ├── EuclideanNormAlgorithmPerformance.java │ │ │ ├── EuclideanNormAlgorithms.java │ │ │ ├── EuclideanNormEvaluator.java │ │ │ ├── GcdPerformance.java │ │ │ ├── KolmogorovSmirnovDistribution.java │ │ │ ├── LinearCombination.java │ │ │ ├── LinearCombinationPerformance.java │ │ │ ├── LinearCombinationUtils.java │ │ │ ├── LinearCombinations.java │ │ │ ├── NormPerformance.java │ │ │ ├── SDD.java │ │ │ ├── StickySumPerformance.java │ │ │ ├── SumPerformance.java │ │ │ └── package-info.java │ │ │ ├── gamma │ │ │ ├── ErfPerformance.java │ │ │ ├── GammaContinuedFractionPerformance.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── examples │ │ └── jmh │ │ ├── arrays │ │ ├── CompressedIndexSetTest.java │ │ ├── DoubleDataTransformersTest.java │ │ ├── DoubleMathTest.java │ │ ├── DualPivotingStrategyTest.java │ │ ├── HashIndexSetTest.java │ │ ├── IndexIteratorTest.java │ │ ├── IndexSetTest.java │ │ ├── KthSelectorTest.java │ │ ├── PartitionFactoryTest.java │ │ ├── PartitionTest.java │ │ ├── PivotCacheTest.java │ │ ├── PivotingStrategyTest.java │ │ ├── QuantilePerformanceTest.java │ │ ├── SearchableIntervalTest.java │ │ ├── SortingTest.java │ │ ├── SplittingIntervalTest.java │ │ ├── TestUtils.java │ │ └── UpdatingIntervalTest.java │ │ ├── core │ │ ├── DDPerformanceTest.java │ │ ├── DoublePrecisionTest.java │ │ ├── EuclideanNormAccuracyTest.java │ │ ├── LinearCombinationAccuracyTest.java │ │ └── LinearCombinationsTest.java │ │ └── gamma │ │ └── GammaContinuedFractionTest.java └── pom.xml ├── commons-numbers-field ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── field │ │ ├── AbstractField.java │ │ ├── BigFractionField.java │ │ ├── DDField.java │ │ ├── FP64.java │ │ ├── FP64Field.java │ │ ├── Field.java │ │ ├── FractionField.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── field │ ├── FP64Test.java │ ├── FieldParametricTest.java │ ├── FieldTestData.java │ ├── FieldsList.java │ └── UserGuideTest.java ├── commons-numbers-fraction ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── fraction │ │ ├── BigFraction.java │ │ ├── ContinuedFraction.java │ │ ├── Fraction.java │ │ ├── FractionException.java │ │ ├── GeneralizedContinuedFraction.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── fraction │ ├── BigFractionTest.java │ ├── CommonTestCases.java │ ├── CommonsLangPortedFractionTest.java │ ├── ContinuedFractionTest.java │ ├── FractionTest.java │ ├── GeneralizedContinuedFractionTest.java │ └── UserGuideTest.java ├── commons-numbers-gamma ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── gamma │ │ ├── Beta.java │ │ ├── BoostBeta.java │ │ ├── BoostErf.java │ │ ├── BoostGamma.java │ │ ├── BoostMath.java │ │ ├── BoostTools.java │ │ ├── Digamma.java │ │ ├── Erf.java │ │ ├── ErfDifference.java │ │ ├── Erfc.java │ │ ├── Erfcx.java │ │ ├── Gamma.java │ │ ├── GammaException.java │ │ ├── GammaRatio.java │ │ ├── IncompleteBeta.java │ │ ├── IncompleteGamma.java │ │ ├── InvGamma1pm1.java │ │ ├── InverseErf.java │ │ ├── InverseErfc.java │ │ ├── LanczosApproximation.java │ │ ├── LogBeta.java │ │ ├── LogGamma.java │ │ ├── LogGamma1p.java │ │ ├── LogGammaSum.java │ │ ├── Policy.java │ │ ├── RegularizedBeta.java │ │ ├── RegularizedGamma.java │ │ ├── SpecialMath.java │ │ ├── Trigamma.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── gamma │ │ ├── BetaTest.java │ │ ├── BoostBetaTest.java │ │ ├── BoostErfTest.java │ │ ├── BoostGammaTest.java │ │ ├── BoostToolsTest.java │ │ ├── DataReader.java │ │ ├── DigammaTest.java │ │ ├── ErfDifferenceTest.java │ │ ├── ErfTest.java │ │ ├── ErfcTest.java │ │ ├── ErfcxTest.java │ │ ├── GammaRatioTest.java │ │ ├── GammaTest.java │ │ ├── IncompleteBetaTest.java │ │ ├── IncompleteGammaTest.java │ │ ├── InvGamma1pm1Test.java │ │ ├── InverseErfTest.java │ │ ├── InverseErfcTest.java │ │ ├── LanczosApproximationTest.java │ │ ├── LogBetaTest.java │ │ ├── LogGamma1pTest.java │ │ ├── LogGammaSumTest.java │ │ ├── LogGammaTest.java │ │ ├── RegularizedBetaTest.java │ │ ├── RegularizedGammaTest.java │ │ ├── TestUtils.java │ │ ├── TestUtilsTest.java │ │ ├── TrigammaTest.java │ │ └── UserGuideTest.java │ └── resources │ └── org │ └── apache │ └── commons │ └── numbers │ └── gamma │ ├── beta_exp_data.csv │ ├── beta_med_data.csv │ ├── beta_small_data.csv │ ├── binomial_extra_large_data.csv │ ├── binomial_huge_data.csv │ ├── binomial_large_data.csv │ ├── binomial_small_data.csv │ ├── erf_close_to_1_data.csv │ ├── erf_data.csv │ ├── erf_inv_data.csv │ ├── erf_inv_limit_data.csv │ ├── erf_large_data.csv │ ├── erf_small_data.csv │ ├── erfc_inv_big_data.csv │ ├── erfc_inv_data.csv │ ├── erfc_inv_limit_data.csv │ ├── erfcx_huge_data.csv │ ├── erfcx_large_data.csv │ ├── erfcx_medium_data.csv │ ├── erfcx_neg_data.csv │ ├── erfcx_neg_medium_data.csv │ ├── erfcx_neg_small_data.csv │ ├── erfcx_small_data.csv │ ├── gamma1pm1_data.csv │ ├── gamma_0_20_data.csv │ ├── gamma_150_171_data.csv │ ├── gamma_20_150_data.csv │ ├── gamma_delta_ratio_data.csv │ ├── gamma_delta_ratio_int2_data.csv │ ├── gamma_delta_ratio_int_data.csv │ ├── gamma_factorials_data.csv │ ├── gamma_m20_0_data.csv │ ├── gamma_near_0_data.csv │ ├── gamma_near_1_data.csv │ ├── gamma_near_2_data.csv │ ├── gamma_near_m10_data.csv │ ├── gamma_near_m55_data.csv │ ├── gamma_p_derivative.pl │ ├── gamma_ratio_data.csv │ ├── gamma_very_near_0_data.csv │ ├── ibeta_derivative_large_data.csv │ ├── ibeta_derivative_med_data.csv │ ├── ibeta_derivative_small_data.csv │ ├── ibeta_derivative_small_int_data.csv │ ├── ibeta_large_data.csv │ ├── ibeta_med_data.csv │ ├── ibeta_small_data.csv │ ├── ibeta_small_int_data.csv │ ├── igamma_asymptotic_data.csv │ ├── igamma_big_data.csv │ ├── igamma_big_data_p_derivative.csv │ ├── igamma_extra_data.csv │ ├── igamma_int_data.csv │ ├── igamma_int_data_p_derivative.csv │ ├── igamma_med_data.csv │ ├── igamma_med_data_p_derivative.csv │ ├── igamma_small_data.csv │ ├── igamma_small_data_p_derivative.csv │ ├── log1pmx_data.csv │ └── powm1_data.csv ├── commons-numbers-primes ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── primes │ │ ├── Primes.java │ │ ├── SmallPrimes.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── primes │ ├── PrimesTest.java │ ├── SmallPrimesTest.java │ └── UserGuideTest.java ├── commons-numbers-quaternion ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── quaternion │ │ ├── Quaternion.java │ │ ├── Slerp.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── quaternion │ ├── QuaternionTest.java │ ├── SlerpTest.java │ └── UserGuideTest.java ├── commons-numbers-rootfinder ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── numbers │ │ └── rootfinder │ │ ├── BrentSolver.java │ │ ├── SolverException.java │ │ └── package-info.java │ ├── site │ ├── resources │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── site.xml │ └── xdoc │ │ └── index.xml │ └── test │ └── java │ └── org │ └── apache │ └── commons │ └── numbers │ └── rootfinder │ ├── BrentSolverTest.java │ ├── MonitoredFunction.java │ ├── QuinticFunction.java │ ├── Sin.java │ ├── SolverExceptionTest.java │ └── UserGuideTest.java ├── dist-archive ├── pom.xml └── src │ └── assembly │ ├── bin.xml │ └── src.xml ├── doc ├── development │ └── development.howto.txt └── release │ ├── copyLongTermJavadoc.sh │ ├── release.howto.txt │ ├── settings-security.xml │ └── settings.xml ├── pom.xml └── src ├── assembly ├── bin.xml └── src.xml ├── changes ├── changes.xml └── release-notes.vm ├── conf ├── checkstyle │ ├── checkstyle-suppressions.xml │ ├── checkstyle.xml │ └── license-header.txt ├── pmd │ └── pmd-ruleset.xml └── spotbugs │ └── spotbugs-exclude-filter.xml ├── media └── math.xcf └── site ├── apt └── userguide │ └── index.apt ├── resources ├── download_numbers.cgi ├── images │ ├── commons_numbers.small.png │ └── userguide │ │ ├── cannonball_example.png │ │ ├── cluster_comparison.png │ │ ├── constant_voltage_example.png │ │ ├── low_discrepancy_sequences.png │ │ └── real_distribution_examples.png ├── profile.jacoco ├── release-notes │ ├── RELEASE-NOTES-1.0-beta1.txt │ ├── RELEASE-NOTES-1.0.txt │ ├── RELEASE-NOTES-1.1.txt │ └── RELEASE-NOTES-1.2.txt └── style │ └── project.css ├── site.xml └── xdoc ├── developers.xml ├── download_numbers.xml ├── index.xml ├── issue-tracking.xml ├── mail-lists.xml └── release-history.xml /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache Commons Numbers" 18 | homepage: https://commons.apache.org/numbers 19 | labels: 20 | - java 21 | - math 22 | - complex 23 | - quaternion 24 | - fraction 25 | - prime 26 | - angle 27 | - combinatorics 28 | - gamma 29 | - floating-point 30 | - precision 31 | 32 | notifications: 33 | commits: commits@commons.apache.org 34 | issues: issues@commons.apache.org 35 | pullrequests: issues@commons.apache.org 36 | jira_options: link label 37 | jobs: notifications@commons.apache.org 38 | issues_bot_dependabot: notifications@commons.apache.org 39 | pullrequests_bot_dependabot: notifications@commons.apache.org 40 | issues_bot_codecov-commenter: notifications@commons.apache.org 41 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 42 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | * text=auto 17 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | version: 2 17 | updates: 18 | - package-ecosystem: "maven" 19 | directory: "/" 20 | schedule: 21 | interval: "weekly" 22 | day: "friday" 23 | - package-ecosystem: "github-actions" 24 | directory: "/" 25 | schedule: 26 | interval: "weekly" 27 | day: "friday" 28 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: Coverage 17 | 18 | on: [push, pull_request] 19 | 20 | permissions: 21 | contents: read 22 | 23 | jobs: 24 | build: 25 | 26 | runs-on: ubuntu-latest 27 | strategy: 28 | matrix: 29 | java: [ 8 ] 30 | 31 | steps: 32 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 33 | with: 34 | persist-credentials: false 35 | - name: Set up JDK ${{ matrix.java }} 36 | uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1 37 | with: 38 | distribution: temurin 39 | java-version: ${{ matrix.java }} 40 | cache: 'maven' 41 | - name: Build with Maven 42 | run: mvn --show-version --batch-mode --no-transfer-progress test jacoco:report 43 | 44 | - name: Upload coverage to Codecov 45 | uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 46 | with: 47 | files: ./commons-numbers-angle/target/site/jacoco/jacoco.xml,./commons-numbers-arrays/target/site/jacoco/jacoco.xml,./commons-numbers-combinatorics/target/site/jacoco/jacoco.xml,./commons-numbers-complex/target/site/jacoco/jacoco.xml,./commons-numbers-complex-streams/target/site/jacoco/jacoco.xml,./commons-numbers-core/target/site/jacoco/jacoco.xml,./commons-numbers-field/target/site/jacoco/jacoco.xml,./commons-numbers-fraction/target/site/jacoco/jacoco.xml,./commons-numbers-gamma/target/site/jacoco/jacoco.xml,./commons-numbers-primes/target/site/jacoco/jacoco.xml,./commons-numbers-quaternion/target/site/jacoco/jacoco.xml,./commons-numbers-rootfinder/target/site/jacoco/jacoco.xml 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.project 3 | **/.settings/ 4 | **/.checkstyle 5 | bin 6 | **/target/ 7 | /build 8 | /lib 9 | site-content* 10 | **/.ekstazi/ 11 | *.class 12 | *.iml 13 | *.ipr 14 | *.iws 15 | .idea 16 | .DS_Store 17 | *~ 18 | /.externalToolBuilders/ 19 | /maven-eclipse.xml 20 | nb-configuration.xml 21 | *.swp 22 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2025 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | For portions of the Commons Numbers Complex component 8 | The org.apache.commons.numbers.complex package contains derivative 9 | work originating from the "Freely Distributable Math Library". 10 | https://www.netlib.org/fdlibm/ 11 | Copyright 1993 Sun Microsystems, Inc. 12 | 13 | The org.apache.commons.numbers.complex package contains derivative 14 | work originating from the "Boost C++ Libraries" . 15 | https://www.boost.org/ 16 | Copyright 2005 John Maddock 2005. 17 | 18 | For portions of the Commons Numbers Gamma component 19 | The org.apache.commons.numbers.gamma package contains derivative 20 | work originating from the "Boost C++ Libraries" . 21 | https://www.boost.org/ 22 | Copyright 2006-7 John Maddock 2006-7. 23 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /commons-numbers-angle/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /commons-numbers-angle/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | 22 | org.apache.commons 23 | commons-numbers-parent 24 | 1.3-SNAPSHOT 25 | 26 | 27 | commons-numbers-angle 28 | Apache Commons Numbers Angle 29 | 30 | Utilities related to the concept of angle. 31 | 32 | 33 | 34 | org.apache.commons.numbers.angle 35 | 36 | org.apache.commons.numbers.angle 37 | 38 | org.apache.commons.numbers.angle 39 | 40 | ${basedir}/.. 41 | 42 | ${numbers.build.outputTimestamp} 43 | angle 44 | 45 | 46 | 47 | 48 | org.apache.commons 49 | commons-numbers-core 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/CosAngle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.angle; 18 | 19 | import org.apache.commons.numbers.core.Norm; 20 | import org.apache.commons.numbers.core.Sum; 21 | 22 | /** 23 | * Computes the cosine of the angle between two vectors. 24 | */ 25 | public final class CosAngle { 26 | 27 | /** Private constructor. */ 28 | private CosAngle() { 29 | // intentionally empty. 30 | } 31 | 32 | /** 33 | * Computes the cosine of the angle between {@code v1} and {@code v2}. 34 | * 35 | * @param v1 Cartesian coordinates of the first vector. 36 | * @param v2 Cartesian coordinates of the second vector. 37 | * @return the cosine of the angle between the vectors. 38 | * @throws IllegalArgumentException if the sizes of the input arrays are different 39 | */ 40 | public static double value(double[] v1, 41 | double[] v2) { 42 | return Sum.ofProducts(v1, v2).getAsDouble() / Norm.L2.of(v1) / Norm.L2.of(v2); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/Reduce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.angle; 18 | 19 | import java.util.function.DoubleUnaryOperator; 20 | 21 | /** 22 | * Reduces {@code |a - offset|} to the primary interval {@code [0, |period|)}. 23 | * 24 | * Specifically, the {@link #applyAsDouble(double) computed value} is: 25 | * {@code a - |period| * floor((a - offset) / |period|) - offset}. 26 | */ 27 | public class Reduce implements DoubleUnaryOperator { 28 | /** Offset. */ 29 | private final double offset; 30 | /** Period. */ 31 | private final double period; 32 | 33 | /** 34 | * Create an instance. 35 | * 36 | * @param offset Value that will be mapped to {@code 0}. 37 | * @param period Period. 38 | */ 39 | public Reduce(double offset, 40 | double period) { 41 | this.offset = offset; 42 | this.period = Math.abs(period); 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | @Override 47 | public double applyAsDouble(double x) { 48 | final double xMo = x - offset; 49 | return xMo - period * Math.floor(xMo / period); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Angle-related utilities. 19 | */ 20 | package org.apache.commons.numbers.angle; 21 | -------------------------------------------------------------------------------- /commons-numbers-angle/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-angle/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-angle/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-angle/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Angle 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "angle" module contains utilities related to the concept of angle. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-arrays/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Array utilities. 19 | */ 20 | package org.apache.commons.numbers.arrays; 21 | -------------------------------------------------------------------------------- /commons-numbers-arrays/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-arrays/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-arrays/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-arrays/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Arrays 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "arrays" module contains array utilities. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-bom/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /commons-numbers-bom/src/site/resources/style/module.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* Match colour used for class declaration in prettyprint */ 19 | .prettyprint, .lang-xml, .tag { color: teal; } 20 | -------------------------------------------------------------------------------- /commons-numbers-bom/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /commons-numbers-combinatorics/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/CombinatoricsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.combinatorics; 18 | 19 | /** 20 | * Package private exception class with constants for frequently used messages. 21 | */ 22 | class CombinatoricsException extends IllegalArgumentException { 23 | /** Error message for "out of range" condition. */ 24 | static final String OUT_OF_RANGE = "Number %s is out of range [%s, %s]"; 25 | /** Error message for "out of range" condition. */ 26 | static final String NEGATIVE = "Number %s is negative"; 27 | /** Error message for "mismatch" condition. */ 28 | static final String MISMATCH = "Expected %s but was %s"; 29 | 30 | /** Serializable version identifier. */ 31 | private static final long serialVersionUID = 20170515L; 32 | 33 | /** 34 | * Create an exception where the message is constructed by applying 35 | * {@link String#format(String, Object...)}. 36 | * 37 | * @param message Exception message format string 38 | * @param formatArguments Arguments for formatting the message 39 | */ 40 | CombinatoricsException(String message, 41 | Object... formatArguments) { 42 | super(String.format(message, formatArguments)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Combinatorics. 20 | */ 21 | package org.apache.commons.numbers.combinatorics; 22 | -------------------------------------------------------------------------------- /commons-numbers-combinatorics/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-combinatorics/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-combinatorics/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-combinatorics/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Combinatorics 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "combinatorics" module contains utilities such as factorial and binomial coefficients. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-complex-streams/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-complex-streams/src/main/java/org/apache/commons/numbers/complex/streams/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Complex numbers collections. 19 | */ 20 | package org.apache.commons.numbers.complex.streams; 21 | -------------------------------------------------------------------------------- /commons-numbers-complex-streams/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-complex-streams/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /commons-numbers-complex-streams/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Complex 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides utilities such as complex numbers and fractions. 31 |

32 | 33 |

34 | The "complex-stream" module contains... 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-complex/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | For portions of the Commons Numbers Complex component 8 | The org.apache.commons.numbers.complex package contains derivative 9 | work originating from the "Freely Distributable Math Library". 10 | https://www.netlib.org/fdlibm/ 11 | Copyright 1993 Sun Microsystems, Inc. 12 | 13 | The org.apache.commons.numbers.complex package contains derivative 14 | work originating from the "Boost C++ Libraries" . 15 | https://www.boost.org/ 16 | Copyright 2005 John Maddock 2005. 17 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Complex numbers. 19 | */ 20 | package org.apache.commons.numbers.complex; 21 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Complex 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "complex" module contains utilities for working with complex numbers. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/UserGuideTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.complex; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Tests for examples contained in the user guide. 24 | */ 25 | class UserGuideTest { 26 | 27 | @Test 28 | void testComplex1() { 29 | double x = 3; 30 | double y = 4; 31 | Complex c1 = Complex.ofCartesian(x, y); 32 | // c1 == x + iy 33 | 34 | double rho = 1.23; 35 | double theta = Math.PI / 2; 36 | Complex c2 = Complex.ofPolar(rho, theta); 37 | 38 | // This is a compilation test. Objects must be valid. 39 | Assertions.assertNotNull(c1); 40 | Assertions.assertNotNull(c2); 41 | } 42 | 43 | @Test 44 | void testComplex2() { 45 | Complex c1 = Complex.ofCartesian(3, 4); 46 | Complex c2 = Complex.ofCartesian(5, 6); 47 | Complex c3 = c1.multiply(c2).sqrt(); 48 | 49 | double magnitude = c3.abs(); 50 | double argument = c3.arg(); 51 | 52 | boolean finite = c3.isFinite(); 53 | 54 | // This is a compilation test. Objects must be valid. 55 | Assertions.assertTrue(Double.isFinite(magnitude)); 56 | Assertions.assertTrue(Double.isFinite(argument)); 57 | Assertions.assertTrue(finite); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/test/resources/data/divide.txt: -------------------------------------------------------------------------------- 1 | # (a + b i) (u + v i) (a + b i).divide(u + v i) 2 | 2 3 5 4 0.53658536585365868 0.17073170731707318 3 | 5 4 2 3 1.6923076923076923 -0.53846153846153855 4 | 2 3 -5 4 0.048780487804878099 -0.56097560975609762 5 | -5 4 2 3 0.15384615384615394 1.7692307692307692 6 | 2 3 5 -4 -0.048780487804878099 0.56097560975609762 7 | 5 -4 2 3 -0.15384615384615394 -1.7692307692307692 8 | 2 3 -5 -4 -0.53658536585365868 -0.17073170731707318 9 | -5 -4 2 3 -1.6923076923076923 0.53846153846153855 10 | 2 3 -1 12 0.23448275862068965 -0.18620689655172412 11 | -1 12 2 3 2.6153846153846159 2.0769230769230771 12 | 2 3 7 -9 -0.099999999999999992 0.30000000000000004 13 | 7 -9 2 3 -1.0000000000000002 -3 14 | 2 3 0.0 5 0.59999999999999998 -0.40000000000000002 15 | 0.0 5 2 3 1.153846153846154 0.76923076923076916 16 | 2 3 5 0.0 0.40000000000000002 0.59999999999999998 17 | 5 0.0 2 3 0.76923076923076916 -1.153846153846154 18 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/test/resources/data/multiply.txt: -------------------------------------------------------------------------------- 1 | # (a + b i) (u + v i) (a + b i).multiply(u + v i) 2 | 2 3 5 4 -2 23 3 | 5 4 2 3 -2 23 4 | 2 3 -5 4 -22 -7 5 | -5 4 2 3 -22 -7 6 | 2 3 5 -4 22 7 7 | 5 -4 2 3 22 7 8 | 2 3 -5 -4 2 -23 9 | -5 -4 2 3 2 -23 10 | 2 3 -1 12 -38 21 11 | -1 12 2 3 -38 21 12 | 2 3 7 -9 41 3 13 | 7 -9 2 3 41 3 14 | 2 3 0.0 5 -15 10 15 | 0.0 5 2 3 -15 10 16 | 2 3 5 0.0 10 15 17 | 5 0.0 2 3 10 15 18 | -------------------------------------------------------------------------------- /commons-numbers-complex/src/test/resources/data/pow.txt: -------------------------------------------------------------------------------- 1 | # (a + b i) (u + v i) (a + b i).pow(u + v i) 2 | 2 3 5 4 -9.7367145095888414 -6.9377513609299868 3 | 5 4 2 3 4.3549103166315382 3.2198331430252156 4 | 2 3 -5 4 3.1452105198427317e-05 6.8990150088148226e-06 5 | -5 4 2 3 -0.011821399482548253 -0.022082334539521097 6 | 2 3 5 -4 30334.832969842264 -6653.9414970320349 7 | 5 -4 2 3 -146.48661898442663 -273.63651239033993 8 | 2 3 -5 -4 -0.068119398044204305 0.048537465694561729 9 | -5 -4 2 3 53964.514878760994 39899.038308625939 10 | 2 3 -1 12 -5.5824460482771003e-07 2.0191622518316361e-06 11 | -1 12 2 3 -0.22408355253971607 -0.98998910763799719 12 | 2 3 7 -9 -2729857.3750238167 54911428.403424568 13 | 7 -9 2 3 1385.7129369399393 -1430.7571582002552 14 | 2 3 0.0 5 0.0072820947869755249 0.00094602869084606884 15 | 0.0 5 2 3 -0.025976373555576252 0.22307493471553799 16 | 2 3 5 0.0 122 -597 17 | 5 0.0 2 3 2.8916321974293986 -24.83220616930339 18 | -------------------------------------------------------------------------------- /commons-numbers-core/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Addition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.core; 18 | 19 | /** 20 | * Addition. 21 | * 22 | * @param Type of elements. 23 | */ 24 | public interface Addition { 25 | /** 26 | * Binary addition. 27 | * 28 | * @param a Element. 29 | * @return {@code this + a}. 30 | */ 31 | T add(T a); 32 | 33 | /** 34 | * Identity element. 35 | * 36 | * @return the field element such that for all {@code a}, 37 | * {@code zero().add(a).equals(a)} is {@code true}. 38 | */ 39 | T zero(); 40 | 41 | /** 42 | * Additive inverse. 43 | * 44 | * @return {@code -this}. 45 | */ 46 | T negate(); 47 | 48 | /** 49 | * Check if this is a neutral element of addition, i.e. {@code this.add(a)} returns 50 | * {@code a} or an element representing the same value as {@code a}. 51 | * 52 | *

The default implementation calls {@link Object#equals(Object) equals(zero())}. 53 | * Implementations may want to employ more a efficient method. This may even 54 | * be required if an implementation has multiple representations of {@code zero} and its 55 | * {@code equals} method differentiates between them. 56 | * 57 | * @return {@code true} if {@code this} is a neutral element of addition. 58 | * @see #zero() 59 | * @since 1.2 60 | */ 61 | default boolean isZero() { 62 | return this.equals(zero()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Multiplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.core; 18 | 19 | /** 20 | * Multiplication. 21 | * 22 | * @param Type of elements. 23 | */ 24 | public interface Multiplication { 25 | /** 26 | * Binary multiplication. 27 | * 28 | * @param a Element. 29 | * @return {@code this * a}. 30 | */ 31 | T multiply(T a); 32 | 33 | /** 34 | * Identity element. 35 | * 36 | * @return the field element such that for all {@code a}, 37 | * {@code one().multiply(a).equals(a)} is {@code true}. 38 | */ 39 | T one(); 40 | 41 | /** 42 | * Multiplicative inverse. 43 | * 44 | * @return this-1. 45 | */ 46 | T reciprocal(); 47 | 48 | /** 49 | * Check if this is a neutral element of multiplication, i.e. {@code this.multiply(a)} returns 50 | * {@code a} or an element representing the same value as {@code a}. 51 | * 52 | *

The default implementation calls {@link Object#equals(Object) equals(one())}. 53 | * Implementations may want to employ more a efficient method. This may even 54 | * be required if an implementation has multiple representations of {@code one} and its 55 | * {@code equals} method differentiates between them. 56 | * 57 | * @return {@code true} if {@code this} is a neutral element of multiplication. 58 | * @see #one() 59 | * @since 1.2 60 | */ 61 | default boolean isOne() { 62 | return this.equals(one()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NativeOperators.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.core; 18 | 19 | /** 20 | * Operators that can be implemented in a more performant way 21 | * using the language constructs. 22 | * 23 | * @param Type of elements. 24 | */ 25 | public interface NativeOperators 26 | extends Addition, 27 | Multiplication { 28 | /** 29 | * Binary subtraction. 30 | * 31 | * @param a Element. 32 | * @return {@code this - a}. 33 | */ 34 | T subtract(T a); 35 | 36 | /** 37 | * Binary division. 38 | * 39 | * @param a Element. 40 | * @return {@code this / a}. 41 | */ 42 | T divide(T a); 43 | 44 | /** 45 | * Repeated addition. 46 | * 47 | * @param n Number of times to add {@code this} to itself. 48 | * @return {@code n * this}. 49 | */ 50 | T multiply(int n); 51 | 52 | /** 53 | * Repeated multiplication. 54 | * 55 | * @param n Number of times to multiply {@code this} with itself. 56 | * @return {@code this^n}. 57 | */ 58 | T pow(int n); 59 | } 60 | -------------------------------------------------------------------------------- /commons-numbers-core/src/main/java/org/apache/commons/numbers/core/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Basic utilities. 19 | */ 20 | package org.apache.commons.numbers.core; 21 | -------------------------------------------------------------------------------- /commons-numbers-core/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-core/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-core/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |

26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-core/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Core 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "core" module contains basic utilities. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-docs/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /commons-numbers-docs/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Documentation 24 | 25 | 26 | 27 | 28 |
29 |

30 | Apache Commons Numbers provides implementations of number types and utilities. 31 | Features include: 32 |

33 |
    34 |
  • angles
  • 35 |
  • arrays
  • 36 |
  • combinatorics
  • 37 |
  • complex numbers
  • 38 |
  • core arithmetic
  • 39 |
  • fields
  • 40 |
  • fractions
  • 41 |
  • gamma functions
  • 42 |
  • primes
  • 43 |
  • quaternions
  • 44 |
  • root finding
  • 45 |
46 |

47 | Browse the Javadoc for more information. 48 |

49 |
50 | 51 | 52 | 53 |
54 | -------------------------------------------------------------------------------- /commons-numbers-examples/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/arrays/IntervalAnalysis.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.examples.jmh.arrays; 18 | 19 | /** 20 | * An interval that provides analysis of indices within the range. 21 | * 22 | * @since 1.2 23 | */ 24 | interface IntervalAnalysis { 25 | /** 26 | * Test if the interval is saturated at the specified {@code separation}. The 27 | * separation distance is provided as a power of 2. 28 | * 29 | *
{@code distance = 1 << separation}
30 | * 31 | *

A saturated interval will have all neighbouring indices separated 32 | * approximately within the maximum separation distance. 33 | * 34 | *

Implementations may: 35 | *

    36 | *
  1. Use approximations for performance, for example 37 | * compressing indices into blocks of the defined separation. 38 | *
    {@code c = (i - left) >> separation}
    39 | *
  2. Support only a range of the possible 40 | * {@code separation} values in {@code [0, 30]}. Unsupported {@code separation} 41 | * values should return {@code false}. 42 | *
43 | * 44 | * @param separation Log2 of the maximum separation between indices. 45 | * @return true if saturated 46 | */ 47 | boolean saturated(int separation); 48 | } 49 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/arrays/NaNPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.examples.jmh.arrays; 18 | 19 | /** 20 | * Defines the policy for {@link Double#NaN NaN} values found in data. 21 | * 22 | * @since 1.2 23 | */ 24 | public enum NaNPolicy { 25 | /** NaNs are included in the data. */ 26 | INCLUDE, 27 | /** NaNs are excluded from the data. */ 28 | EXCLUDE, 29 | /** NaNs result in an exception. */ 30 | ERROR 31 | } 32 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/arrays/PivotStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.examples.jmh.arrays; 18 | 19 | /** 20 | * Storage for pivot indices used for partitioning an array into multiple regions. 21 | * 22 | *

A pivot is an index position that contains a value equal to the value in a fully 23 | * sorted array. 24 | * 25 | *

For a pivot {@code p}: 26 | * 27 | *

{@code
28 |  * i < p < j
29 |  * data[i] <= data[p] <= data[j]
30 |  * }
31 | * 32 | *

Implementations may assume indices are positive. Implementations are not required to 33 | * store all indices, and may discard previously stored indices during operation. Behaviour 34 | * should be documented. 35 | * 36 | *

This interface is used by methods that create pivots. Methods that use pivots should 37 | * use the {@link PivotCache} interface. 38 | * 39 | * @since 1.2 40 | */ 41 | interface PivotStore { 42 | /** 43 | * Add the pivot index to the store. 44 | * 45 | * @param index Index. 46 | */ 47 | void add(int index); 48 | 49 | /** 50 | * Add a range of pivot indices to the store. 51 | * 52 | *

If {@code fromIndex == toIndex} this is equivalent to {@link #add(int)}. 53 | * 54 | *

If {@code fromIndex > toIndex} the behavior is not defined.

55 | * 56 | * @param fromIndex Start index of the range (inclusive). 57 | * @param toIndex End index of the range (inclusive). 58 | */ 59 | void add(int fromIndex, int toIndex); 60 | } 61 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/arrays/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Benchmarks for the {@code org.apache.commons.numbers.arrays} components. 20 | * 21 | * @since 1.2 22 | */ 23 | package org.apache.commons.numbers.examples.jmh.arrays; 24 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/complex/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Benchmarks for the {@code org.apache.commons.numbers.complex} components. 20 | */ 21 | 22 | package org.apache.commons.numbers.examples.jmh.complex; 23 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Benchmarks for the {@code org.apache.commons.numbers.core} components. 20 | */ 21 | package org.apache.commons.numbers.examples.jmh.core; 22 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/gamma/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Benchmarks for the {@code org.apache.commons.numbers.gamma} components. 20 | */ 21 | 22 | package org.apache.commons.numbers.examples.jmh.gamma; 23 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

Performance benchmarks

20 | * 21 | *

22 | * This package contains code to perform a 23 | * JMH run. 24 | *

25 | */ 26 | package org.apache.commons.numbers.examples.jmh; 27 | -------------------------------------------------------------------------------- /commons-numbers-examples/examples-jmh/src/test/java/org/apache/commons/numbers/examples/jmh/arrays/DoubleMathTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.numbers.examples.jmh.arrays; 19 | 20 | import org.junit.jupiter.api.Assertions; 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * Test for {@link DoubleMath}. 25 | */ 26 | class DoubleMathTest { 27 | @Test 28 | void testGreaterThanLessThan() { 29 | final double[] values = {0.0, 1.0, Double.POSITIVE_INFINITY, Double.NaN}; 30 | final int[] sign = {-1, 1}; 31 | for (final double a : values) { 32 | for (final double b : values) { 33 | for (final int i : sign) { 34 | final double x = i * a; 35 | for (final int j : sign) { 36 | final double y = j * b; 37 | Assertions.assertEquals(Double.compare(x, y) > 0, DoubleMath.greaterThan(x, y), 38 | () -> x + " > " + y); 39 | Assertions.assertEquals(Double.compare(x, y) < 0, DoubleMath.lessThan(x, y), 40 | () -> x + " < " + y); 41 | } 42 | } 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /commons-numbers-field/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-field/src/main/java/org/apache/commons/numbers/field/AbstractField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.field; 18 | 19 | import org.apache.commons.numbers.core.NativeOperators; 20 | 21 | /** 22 | * Boiler-plate code for concrete implementations of {@link Field}. 23 | * 24 | * @param Type of the field elements. 25 | */ 26 | public abstract class AbstractField> 27 | implements Field { 28 | /** Create an instance. */ 29 | public AbstractField() {} 30 | 31 | /** {@inheritDoc} */ 32 | @Override 33 | public T add(T a, T b) { 34 | return a.add(b); 35 | } 36 | 37 | /** {@inheritDoc} */ 38 | @Override 39 | public T subtract(T a, T b) { 40 | return a.subtract(b); 41 | } 42 | 43 | /** {@inheritDoc} */ 44 | @Override 45 | public T negate(T a) { 46 | return a.negate(); 47 | } 48 | 49 | /** {@inheritDoc} */ 50 | @Override 51 | public T multiply(int n, T a) { 52 | return a.multiply(n); 53 | } 54 | 55 | /** {@inheritDoc} */ 56 | @Override 57 | public T multiply(T a, T b) { 58 | return a.multiply(b); 59 | } 60 | 61 | /** {@inheritDoc} */ 62 | @Override 63 | public T divide(T a, T b) { 64 | return a.divide(b); 65 | } 66 | 67 | /** {@inheritDoc} */ 68 | @Override 69 | public T reciprocal(T a) { 70 | return a.reciprocal(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /commons-numbers-field/src/main/java/org/apache/commons/numbers/field/BigFractionField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.field; 18 | 19 | import org.apache.commons.numbers.fraction.BigFraction; 20 | 21 | /** 22 | * {@link BigFraction} field. 23 | */ 24 | public final class BigFractionField extends AbstractField { 25 | /** Singleton. */ 26 | private static final BigFractionField INSTANCE = new BigFractionField(); 27 | 28 | /** Singleton. */ 29 | private BigFractionField() {} 30 | 31 | /** 32 | * Get the field instance. 33 | * 34 | * @return the field instance. 35 | */ 36 | public static BigFractionField get() { 37 | return INSTANCE; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | @Override 42 | public BigFraction one() { 43 | return BigFraction.ONE; 44 | } 45 | 46 | /** {@inheritDoc} */ 47 | @Override 48 | public BigFraction zero() { 49 | return BigFraction.ZERO; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /commons-numbers-field/src/main/java/org/apache/commons/numbers/field/DDField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.field; 18 | 19 | import org.apache.commons.numbers.core.DD; 20 | 21 | /** 22 | * {@link DD} field. 23 | * 24 | * @since 1.2 25 | */ 26 | public final class DDField extends AbstractField
{ 27 | /** Singleton. */ 28 | private static final DDField INSTANCE = new DDField(); 29 | 30 | /** Singleton. */ 31 | private DDField() {} 32 | 33 | /** 34 | * Get the field instance. 35 | * 36 | * @return the field instance. 37 | */ 38 | public static DDField get() { 39 | return INSTANCE; 40 | } 41 | 42 | /** {@inheritDoc} */ 43 | @Override 44 | public DD one() { 45 | return DD.ONE; 46 | } 47 | 48 | /** {@inheritDoc} */ 49 | @Override 50 | public DD zero() { 51 | return DD.ZERO; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64Field.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.field; 18 | 19 | /** 20 | * {@link Double} field. 21 | */ 22 | public final class FP64Field extends AbstractField { 23 | /** 0d. */ 24 | private static final FP64 ZERO = FP64.of(0d); 25 | /** 1d. */ 26 | private static final FP64 ONE = FP64.of(1d); 27 | /** Singleton. */ 28 | private static final FP64Field INSTANCE = new FP64Field(); 29 | 30 | /** Singleton. */ 31 | private FP64Field() {} 32 | 33 | /** 34 | * Get the field instance. 35 | * 36 | * @return the field instance. 37 | */ 38 | public static FP64Field get() { 39 | return INSTANCE; 40 | } 41 | 42 | /** {@inheritDoc} */ 43 | @Override 44 | public FP64 one() { 45 | return ONE; 46 | } 47 | 48 | /** {@inheritDoc} */ 49 | @Override 50 | public FP64 zero() { 51 | return ZERO; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FractionField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.field; 18 | 19 | import org.apache.commons.numbers.fraction.Fraction; 20 | 21 | /** 22 | * {@link Fraction} field. 23 | */ 24 | public final class FractionField extends AbstractField { 25 | /** Singleton. */ 26 | private static final FractionField INSTANCE = new FractionField(); 27 | 28 | /** Singleton. */ 29 | private FractionField() {} 30 | 31 | /** 32 | * Get the field instance. 33 | * 34 | * @return the field instance. 35 | */ 36 | public static FractionField get() { 37 | return INSTANCE; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | @Override 42 | public Fraction one() { 43 | return Fraction.ONE; 44 | } 45 | 46 | /** {@inheritDoc} */ 47 | @Override 48 | public Fraction zero() { 49 | return Fraction.ZERO; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /commons-numbers-field/src/main/java/org/apache/commons/numbers/field/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Field-related utilities. 19 | */ 20 | package org.apache.commons.numbers.field; 21 | -------------------------------------------------------------------------------- /commons-numbers-field/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-field/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-field/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-field/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | Commons Numbers Field 23 | 24 | 25 | 26 | 27 |
28 |

29 | Commons Numbers provides number types and utilities. 30 |

31 | 32 |

33 | The "field" module contains utilities related to the concept of field. 34 |

35 |
36 | 37 | 38 | 39 |
40 | -------------------------------------------------------------------------------- /commons-numbers-field/src/test/java/org/apache/commons/numbers/field/FieldTestData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.field; 18 | 19 | import java.util.function.BiPredicate; 20 | 21 | /** 22 | * Data store for {@link FieldParametricTest}. 23 | */ 24 | class FieldTestData { 25 | private final Field field; 26 | private final T a; 27 | private final T b; 28 | private final T c; 29 | private final BiPredicate equal; 30 | 31 | FieldTestData(Field field, 32 | T a, 33 | T b, 34 | T c) { 35 | this(field, a, b, c, Object::equals); 36 | } 37 | 38 | FieldTestData(Field field, 39 | T a, 40 | T b, 41 | T c, 42 | BiPredicate equal) { 43 | this.field = field; 44 | this.a = a; 45 | this.b = b; 46 | this.c = c; 47 | this.equal = equal; 48 | } 49 | 50 | public Field getField() { 51 | return field; 52 | } 53 | 54 | public T getA() { 55 | return a; 56 | } 57 | 58 | public T getB() { 59 | return b; 60 | } 61 | 62 | public T getC() { 63 | return c; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return field.toString() + " [a=" + a + ", b=" + b + ", c=" + c + "]"; 69 | } 70 | 71 | public boolean equals(T x, T y) { 72 | return equal.test(x, y); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /commons-numbers-field/src/test/java/org/apache/commons/numbers/field/UserGuideTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.field; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Tests for examples contained in the user guide. 24 | */ 25 | class UserGuideTest { 26 | 27 | @Test 28 | void testField1() { 29 | Field field = FP64Field.get(); 30 | FP64 result = field.one().multiply(3).divide(field.one().multiply(4)); 31 | double value = result.doubleValue(); 32 | Assertions.assertEquals(0.75, value); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /commons-numbers-fraction/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * 19 | * Fraction number type and fraction number formatting. 20 | * 21 | */ 22 | package org.apache.commons.numbers.fraction; 23 | -------------------------------------------------------------------------------- /commons-numbers-fraction/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-fraction/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-fraction/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-fraction/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Fraction 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "fraction" module contains utilities related to fractions. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-gamma/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | The org.apache.commons.numbers.gamma package contains derivative 8 | work originating from the "Boost C++ Libraries" . 9 | https://www.boost.org/ 10 | Copyright 2006-7, 2013-14 John Maddock. 11 | Copyright 2007, 2013-14 Paul A. Bristow. 12 | Copyright 2013-14 Nikhar Agrawal. 13 | Copyright 2013-14, 2020 Christopher Kormanyos. 14 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Beta.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Beta function. 21 | * 22 | *

\[ B(a, b) = \frac{\Gamma(a)\ \Gamma(b)}{\Gamma(a+b)} = \frac{(a-1)!\ (b-1)!}{(a+b-1)!} \] 23 | * 24 | *

where \( \Gamma(z) \) is the gamma function. 25 | * 26 | *

This code has been adapted from the Boost 27 | * {@code c++} implementation {@code }. 28 | * 29 | * @see 30 | * 31 | * Boost C++ Beta function 32 | * @since 1.1 33 | */ 34 | public final class Beta { 35 | 36 | /** Private constructor. */ 37 | private Beta() { 38 | // intentionally empty. 39 | } 40 | 41 | /** 42 | * Computes the value of the 43 | * 44 | * beta function B(a, b). 45 | * 46 | *

\[ B(a, b) = \frac{\Gamma(a)\ \Gamma(b)}{\Gamma(a+b)} \] 47 | * 48 | *

where \( \Gamma(z) \) is the gamma function. 49 | * 50 | * @param a Parameter {@code a}. 51 | * @param b Parameter {@code b}. 52 | * @return the beta function \( B(a, b) \). 53 | */ 54 | public static double value(double a, 55 | double b) { 56 | return BoostBeta.beta(a, b); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Erf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Error function. 21 | * 22 | *

\[ \operatorname{erf}(z) = \frac{2}{\sqrt\pi}\int_0^z e^{-t^2}\,dt \] 23 | */ 24 | public final class Erf { 25 | /** Private constructor. */ 26 | private Erf() { 27 | // intentionally empty. 28 | } 29 | 30 | /** 31 | * Returns the error function. 32 | * 33 | *

The returned value is always between -1 and 1 (inclusive). 34 | * The appropriate extreme is returned when {@code erf(x)} is 35 | * indistinguishable from either -1 or 1 at {@code double} precision. 36 | * 37 | *

Special cases: 38 | *

    39 | *
  • If the argument is 0, then the result is 0. 40 | *
  • If the argument is {@code > 6}, then the result is 1. 41 | *
  • If the argument is {@code < 6}, then the result is -1. 42 | *
  • If the argument is nan, then the result is nan. 43 | *
44 | * 45 | * @param x the value. 46 | * @return the error function. 47 | */ 48 | public static double value(double x) { 49 | return BoostErf.erf(x); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Erfc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Complementary error function. 21 | * 22 | *

\[ \begin{aligned} \operatorname{erfc}(z) 23 | * &= 1 - \operatorname{erf}(z) \\ 24 | * &= \frac{2}{\sqrt\pi}\int_z^{\infty} e^{-t^2}\,dt 25 | * \end{aligned} \] 26 | */ 27 | public final class Erfc { 28 | /** Private constructor. */ 29 | private Erfc() { 30 | // intentionally empty. 31 | } 32 | 33 | /** 34 | * Returns the complementary error function. 35 | * 36 | *

The value returned is always between 0 and 2 (inclusive). 37 | * The appropriate extreme is returned when {@code erfc(x)} is 38 | * indistinguishable from either 0 or 2 at {@code double} precision. 39 | * 40 | *

Special cases: 41 | *

    42 | *
  • If the argument is 0, then the result is 1. 43 | *
  • If the argument is {@code > 28}, then the result is 0. 44 | *
  • If the argument is {@code < 6}, then the result is 2. 45 | *
  • If the argument is nan, then the result is nan. 46 | *
47 | * 48 | * @param x Value. 49 | * @return the complementary error function. 50 | */ 51 | public static double value(double x) { 52 | return BoostErf.erfc(x); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Erfcx.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Scaled complementary error function. 21 | * 22 | *

\[ \operatorname{erfcx}(z) = \operatorname{erfc}(z)\ e^{z^2} \] 23 | * 24 | *

For large z the value is approximately: 25 | * 26 | *

\[ \operatorname{erfcx}(z) = \frac{1}{z \sqrt{\pi}} \] 27 | * 28 | * @see Erfc 29 | * @since 1.1 30 | */ 31 | public final class Erfcx { 32 | /** Private constructor. */ 33 | private Erfcx() { 34 | // intentionally empty. 35 | } 36 | 37 | /** 38 | * Returns the scaled complementary error function. 39 | * 40 | *

Special cases: 41 | *

    42 | *
  • If the argument is 0, then the result is 1. 43 | *
  • If the argument is +infinity, then the result is 0. 44 | *
  • If the argument is negative and {@code exp(x*x)} is infinite, then the result is +infinity. 45 | *
  • If the argument is nan, then the result is nan. 46 | *
47 | * 48 | * @param x Value. 49 | * @return the scaled complementary error function. 50 | */ 51 | public static double value(double x) { 52 | return BoostErf.erfcx(x); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Gamma 21 | * function \( \Gamma(x) \). 22 | * 23 | *

The gamma 24 | * function can be seen to extend the factorial function to cover real and 25 | * complex numbers, but with its argument shifted by {@code -1}. This 26 | * implementation supports real numbers. 27 | * 28 | *

This code has been adapted from: 29 | *

    30 | *
  • The Boost 31 | * {@code c++} implementation {@code }. 32 | *
  • The NSWC Library of Mathematics Subroutines double 33 | * precision implementation, {@code DGAMMA}. 34 | *
35 | * 36 | * @see 37 | * 38 | * Boost C++ Gamma functions 39 | */ 40 | public final class Gamma { 41 | /** Private constructor. */ 42 | private Gamma() { 43 | // intentionally empty. 44 | } 45 | 46 | /** 47 | * Computes the value of \( \Gamma(x) \). 48 | * 49 | * @param x Argument. 50 | * @return \( \Gamma(x) \) 51 | */ 52 | public static double value(final double x) { 53 | return BoostGamma.tgamma(x); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/GammaException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Package private exception class with constants for frequently used messages. 21 | */ 22 | class GammaException extends IllegalArgumentException { 23 | /** Error message for "out of range" condition. */ 24 | static final String OUT_OF_RANGE = "Number %s is out of range [%s, %s]"; 25 | 26 | /** Serializable version identifier. */ 27 | private static final long serialVersionUID = 20170505L; 28 | 29 | /** 30 | * Create an exception where the message is constructed by applying 31 | * the {@code format()} method from {@code java.lang.String}. 32 | * 33 | * @param message the exception message with replaceable parameters 34 | * @param formatArguments the arguments for formatting the message 35 | */ 36 | GammaException(String message, Object... formatArguments) { 37 | super(String.format(message, formatArguments)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/InverseErf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Inverse of the error function. 21 | */ 22 | public final class InverseErf { 23 | /** Private constructor. */ 24 | private InverseErf() { 25 | // intentionally empty. 26 | } 27 | 28 | /** 29 | * Returns the inverse error function. 30 | * 31 | *

Special cases: 32 | *

    33 | *
  • If the argument is 0, then the result is 0. 34 | *
  • If the argument is 1, then the result is positive infinity. 35 | *
  • If the argument is -1, then the result is negative infinity. 36 | *
  • If the argument is outside the interval {@code [-1, 1]}, then the result is nan. 37 | *
  • If the argument is nan, then the result is nan. 38 | *
39 | * 40 | * @param x Value (in {@code [-1, 1]}) 41 | * @return t such that {@code x =} {@link Erf#value(double) Erf.value(t)}. 42 | */ 43 | public static double value(final double x) { 44 | return BoostErf.erfInv(x); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/InverseErfc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Inverse of the complementary error function. 21 | */ 22 | public final class InverseErfc { 23 | /** Private constructor. */ 24 | private InverseErfc() { 25 | // intentionally empty. 26 | } 27 | 28 | /** 29 | * Returns the inverse complementary error function. 30 | * 31 | *

Special cases: 32 | *

    33 | *
  • If the argument is 1, then the result is 0. 34 | *
  • If the argument is 0, then the result is positive infinity. 35 | *
  • If the argument is 2, then the result is negative infinity. 36 | *
  • If the argument is outside the interval {@code [0, 2]}, then the result is nan. 37 | *
  • If the argument is nan, then the result is nan. 38 | *
39 | * 40 | * @param x Value (in {@code [0, 2]}) 41 | * @return t such that {@code x =} {@link Erfc#value(double) Erfc.value(t)}. 42 | */ 43 | public static double value(double x) { 44 | return BoostErf.erfcInv(x); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGamma1p.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Function \( \ln \Gamma(1 + x) \). 21 | * 22 | * Class is immutable. 23 | */ 24 | final class LogGamma1p { 25 | /** Private constructor. */ 26 | private LogGamma1p() { 27 | // intentionally empty 28 | } 29 | 30 | /** 31 | * Computes the function \( \ln \Gamma(1 + x) \) for \( -0.5 \leq x \leq 1.5 \). 32 | * 33 | * This implementation is based on the double precision implementation in 34 | * the NSWC Library of Mathematics Subroutines, {@code DGMLN1}. 35 | * 36 | * @param x Argument. 37 | * @return \( \ln \Gamma(1 + x) \) 38 | * @throws IllegalArgumentException if {@code x < -0.5} or {@code x > 1.5}. 39 | */ 40 | public static double value(final double x) { 41 | if (x < -0.5 || x > 1.5) { 42 | throw new GammaException(GammaException.OUT_OF_RANGE, x, -0.5, 1.5); 43 | } 44 | 45 | return -Math.log1p(InvGamma1pm1.value(x)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/LogGammaSum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | /** 20 | * Computes \( \log_e(\Gamma(a+b)) \). 21 | *

22 | * This class is immutable. 23 | *

24 | */ 25 | final class LogGammaSum { 26 | /** Private constructor. */ 27 | private LogGammaSum() { 28 | // intentionally empty 29 | } 30 | 31 | /** 32 | * Computes the value of log Γ(a + b) for 1 ≤ a, b ≤ 2. 33 | * Based on the NSWC Library of Mathematics Subroutines 34 | * implementation, {@code DGSMLN}. 35 | * 36 | * @param a First argument. 37 | * @param b Second argument. 38 | * @return the value of {@code log(Gamma(a + b))}. 39 | * @throws IllegalArgumentException if {@code a} or {@code b} is lower than 1 40 | * or larger than 2. 41 | */ 42 | static double value(double a, 43 | double b) { 44 | if (a < 1 || 45 | a > 2) { 46 | throw new GammaException(GammaException.OUT_OF_RANGE, a, 1, 2); 47 | } 48 | if (b < 1 || 49 | b > 2) { 50 | throw new GammaException(GammaException.OUT_OF_RANGE, b, 1, 2); 51 | } 52 | 53 | final double x = (a - 1) + (b - 1); 54 | if (x <= 0.5) { 55 | return LogGamma1p.value(1 + x); 56 | } else if (x <= 1.5) { 57 | return LogGamma1p.value(x) + Math.log1p(x); 58 | } else { 59 | return LogGamma1p.value(x - 1) + Math.log(x * (1 + x)); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Γ (Gamma) and Β (Beta) family of functions. 20 | * 21 | * Implementation of {@link org.apache.commons.numbers.gamma.InvGamma1pm1 InvGamma1pm1} 22 | * and {@link org.apache.commons.numbers.gamma.LogGamma1p LogGamma1p} is based on the 23 | * algorithms described in 24 | *
    25 | *
  • 26 | * Didonato and Morris (1986), 27 | * Computation of the Incomplete Gamma Function Ratios and their Inverse, 28 | * TOMS 12(4), 377-393, 29 | *
  • 30 | *
  • 31 | * Didonato and Morris (1992), 32 | * Algorithm 708: Significant Digit Computation of the Incomplete Beta Function 33 | * Ratios, TOMS 18(3), 360-373, 34 | *
  • 35 | *
36 | * and implemented in the 37 | * NSWC Library of Mathematical Functions. 38 | */ 39 | package org.apache.commons.numbers.gamma; 40 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Gamma 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "gamma" module contains utilities related to the "Gamma" function. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BetaTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | import org.junit.jupiter.params.ParameterizedTest; 20 | import org.junit.jupiter.params.provider.CsvFileSource; 21 | 22 | /** 23 | * Tests for {@link Beta}. 24 | * 25 | *

The class directly calls the methods in {@link BoostBeta}. This test ensures 26 | * the arguments are passed through correctly. Accuracy of the function is tested 27 | * in {@link BoostBetaTest}. 28 | */ 29 | class BetaTest { 30 | @ParameterizedTest 31 | @CsvFileSource(resources = "beta_med_data.csv") 32 | void testBeta(double a, double b, double beta) { 33 | TestUtils.assertEquals(beta, Beta.value(a, b), 200); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/InverseErfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Tests for {@link InverseErf}. 24 | */ 25 | class InverseErfTest { 26 | @Test 27 | void testErfInvNaN() { 28 | Assertions.assertTrue(Double.isNaN(InverseErf.value(-1.001))); 29 | Assertions.assertTrue(Double.isNaN(InverseErf.value(+1.001))); 30 | Assertions.assertTrue(Double.isNaN(InverseErf.value(Double.NaN))); 31 | } 32 | 33 | @Test 34 | void testErfInvInfinite() { 35 | Assertions.assertTrue(Double.isInfinite(InverseErf.value(-1))); 36 | Assertions.assertTrue(InverseErf.value(-1) < 0); 37 | Assertions.assertTrue(Double.isInfinite(InverseErf.value(+1))); 38 | Assertions.assertTrue(InverseErf.value(+1) > 0); 39 | } 40 | 41 | @Test 42 | void testErfInv() { 43 | for (double x = -5.9; x < 5.9; x += 0.01) { 44 | final double y = Erf.value(x); 45 | final double dydx = 2 * Math.exp(-x * x) / Math.sqrt(Math.PI); 46 | Assertions.assertEquals(x, InverseErf.value(y), 1.0e-15 / dydx); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/InverseErfcTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Tests for {@link InverseErfc}. 24 | */ 25 | class InverseErfcTest { 26 | @Test 27 | void testErfcInvNaN() { 28 | Assertions.assertTrue(Double.isNaN(InverseErfc.value(-0.001))); 29 | Assertions.assertTrue(Double.isNaN(InverseErfc.value(+2.001))); 30 | } 31 | 32 | @Test 33 | void testErfcInvInfinite() { 34 | Assertions.assertTrue(Double.isInfinite(InverseErfc.value(-0))); 35 | Assertions.assertTrue(InverseErfc.value(0) > 0); 36 | Assertions.assertTrue(Double.isInfinite(InverseErfc.value(+2))); 37 | Assertions.assertTrue(InverseErfc.value(+2) < 0); 38 | } 39 | 40 | @Test 41 | void testErfcInv() { 42 | for (double x = -5.85; x < 5.9; x += 0.01) { 43 | final double y = Erfc.value(x); 44 | final double dydxAbs = 2 * Math.exp(-x * x) / Math.sqrt(Math.PI); 45 | Assertions.assertEquals(x, InverseErfc.value(y), 1.0e-15 / dydxAbs); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/LanczosApproximationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Tests for {@link LanczosApproximation}. 24 | */ 25 | class LanczosApproximationTest { 26 | @Test 27 | void testG() { 28 | Assertions.assertEquals(607d / 128d, LanczosApproximation.g()); 29 | } 30 | 31 | @Test 32 | void testSomeValues() { 33 | // Given that few values are checked, this test would only serve 34 | // as early warning of unexpected changes to the current code. 35 | Assertions.assertEquals(29.020294557631818d, LanczosApproximation.value(0.1d)); 36 | Assertions.assertEquals(13.14778027539684d, LanczosApproximation.value(1.0d)); 37 | Assertions.assertEquals(7.897828855157814d, LanczosApproximation.value(2.0d)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/UserGuideTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.gamma; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Tests for examples contained in the user guide. 24 | */ 25 | class UserGuideTest { 26 | 27 | @Test 28 | void testGamma1() { 29 | double result = Erfc.value(1.23); 30 | Assertions.assertTrue(0 <= result && result <= 2); 31 | 32 | // Default function evaluation 33 | double a = 1.23; 34 | double x = 4.56; 35 | double result1 = IncompleteGamma.Lower.value(a, x); 36 | 37 | // Parameterize function evaluation 38 | double epsilon = 1e-10; 39 | int maxIterations = 1000; 40 | double result2 = IncompleteGamma.Lower.value(a, x, epsilon, maxIterations); 41 | Assertions.assertEquals(result1, result2, result1 * 1e-14); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /commons-numbers-primes/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | 22 | org.apache.commons 23 | commons-numbers-parent 24 | 1.3-SNAPSHOT 25 | 26 | 27 | commons-numbers-primes 28 | Apache Commons Numbers Primes 29 | 30 | Utilities related to prime numbers. 31 | 32 | 33 | 34 | org.apache.commons.numbers.primes 35 | 36 | org.apache.commons.numbers.primes 37 | 38 | org.apache.commons.numbers.primes 39 | 40 | ${basedir}/.. 41 | 42 | ${numbers.build.outputTimestamp} 43 | primes 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Methods related to prime numbers like primality test, factor decomposition. 19 | */ 20 | package org.apache.commons.numbers.primes; 21 | -------------------------------------------------------------------------------- /commons-numbers-primes/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-primes/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-primes/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |

26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-primes/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Primes 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "primes" module contains utilities related to prime numbers. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/UserGuideTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.primes; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import org.junit.jupiter.api.Assertions; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Tests for examples contained in the user guide. 26 | */ 27 | class UserGuideTest { 28 | 29 | @Test 30 | void testPrimes1() { 31 | int n = 51237173; 32 | boolean prime = Primes.isPrime(n); 33 | int m = Primes.nextPrime(n); 34 | Assertions.assertFalse(prime); 35 | Assertions.assertEquals(51237233, m); 36 | 37 | List f1 = Primes.primeFactors(n); 38 | List f2 = Primes.primeFactors(m); 39 | Assertions.assertEquals(Arrays.asList(13, 863, 4567), f1); 40 | Assertions.assertEquals(Arrays.asList(m), f2); 41 | // n == 13 * 863 * 4567 42 | Assertions.assertEquals(n, f1.stream().mapToInt(i -> i).reduce((i, j) -> i * j).getAsInt()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /commons-numbers-quaternion/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | -------------------------------------------------------------------------------- /commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Quaternion number type. 19 | */ 20 | package org.apache.commons.numbers.quaternion; 21 | -------------------------------------------------------------------------------- /commons-numbers-quaternion/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-quaternion/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-quaternion/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-quaternion/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Quaternion 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "quaternion" module contains utilities related to quaternions. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Commons Numbers 2 | Copyright 2001-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/SolverException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.rootfinder; 18 | 19 | /** 20 | * Package private exception class with constants for frequently used messages. 21 | */ 22 | class SolverException extends IllegalArgumentException { 23 | /** Error message for "too large" condition. */ 24 | static final String TOO_LARGE = "%s > %s"; 25 | /** Error message for "out of range" condition. */ 26 | static final String OUT_OF_RANGE = "%s is out of range [%s, %s]"; 27 | /** Error message for "failed bracketing" condition. */ 28 | static final String BRACKETING = "No bracketing: f(%s)=%s, f(%s)=%s"; 29 | 30 | /** Serializable version identifier. */ 31 | private static final long serialVersionUID = 20190602L; 32 | 33 | /** 34 | * Create an exception where the message is constructed by applying 35 | * the {@code format()} method from {@code String}. 36 | * 37 | * @param message the exception message with replaceable parameters 38 | * @param formatArguments the arguments for formatting the message 39 | * @see String#format(String, Object...) 40 | */ 41 | SolverException(String message, Object... formatArguments) { 42 | super(String.format(message, formatArguments)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Root finding utilities. 19 | */ 20 | package org.apache.commons.numbers.rootfinder; 21 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger profile from commons parent pom 18 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Commons Numbers Root Finder 24 | 25 | 26 | 27 | 28 |
29 |

30 | Commons Numbers provides number types and utilities. 31 |

32 | 33 |

34 | The "rootfinder" module contains utilities for finding the zero of a function. 35 |

36 |
37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/test/java/org/apache/commons/numbers/rootfinder/MonitoredFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.rootfinder; 18 | 19 | import java.util.function.DoubleUnaryOperator; 20 | 21 | /** 22 | * Wrapper class for counting functions calls. 23 | */ 24 | class MonitoredFunction implements DoubleUnaryOperator { 25 | private final int maxCount; 26 | private int callsCount; 27 | private final DoubleUnaryOperator f; 28 | 29 | MonitoredFunction(DoubleUnaryOperator f) { 30 | this(f, Integer.MAX_VALUE); 31 | } 32 | 33 | MonitoredFunction(DoubleUnaryOperator f, 34 | int maxCount) { 35 | callsCount = 0; 36 | this.f = f; 37 | this.maxCount = maxCount; 38 | } 39 | 40 | int getCallsCount() { 41 | return callsCount; 42 | } 43 | 44 | @Override 45 | public double applyAsDouble(double x) { 46 | if (++callsCount > maxCount) { 47 | throw new IllegalStateException(callsCount + " > " + maxCount + 48 | ": too many calls"); 49 | } 50 | return f.applyAsDouble(x); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/test/java/org/apache/commons/numbers/rootfinder/QuinticFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.rootfinder; 18 | 19 | import java.util.function.DoubleUnaryOperator; 20 | 21 | /** 22 | * Auxiliary class for testing solvers. 23 | */ 24 | class QuinticFunction implements DoubleUnaryOperator { 25 | @Override 26 | public double applyAsDouble(double x) { 27 | return (x - 1) * (x - 0.5) * x * (x + 0.5) * (x + 1); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/test/java/org/apache/commons/numbers/rootfinder/Sin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.rootfinder; 18 | 19 | import java.util.function.DoubleUnaryOperator; 20 | 21 | /** 22 | * Auxiliary class for testing solvers. 23 | */ 24 | class Sin implements DoubleUnaryOperator { 25 | @Override 26 | public double applyAsDouble(double x) { 27 | return Math.sin(x); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /commons-numbers-rootfinder/src/test/java/org/apache/commons/numbers/rootfinder/UserGuideTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.numbers.rootfinder; 18 | 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Tests for examples contained in the user guide. 24 | */ 25 | class UserGuideTest { 26 | 27 | @Test 28 | void testBrentSolver1() { 29 | double relAccuracy = 1e-6; 30 | double absAccuracy = 1e-14; 31 | double functionAccuracy = 1e-15; 32 | BrentSolver solver = new BrentSolver(relAccuracy, 33 | absAccuracy, 34 | functionAccuracy); 35 | double result1 = solver.findRoot(Math::sin, 3, 4); 36 | double result2 = solver.findRoot(Math::sin, 3, 3.14, 4); // With initial guess 37 | // result1 ~ result2 ~ Math.PI 38 | Assertions.assertEquals(Math.PI, result1, Math.PI * relAccuracy); 39 | Assertions.assertEquals(Math.PI, result2, Math.PI * relAccuracy); 40 | 41 | // *** Throws an IllegalArgumentException *** 42 | Assertions.assertThrows(IllegalArgumentException.class, 43 | () -> solver.findRoot(Math::sin, 2, 3)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /dist-archive/src/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | bin 19 | 20 | tar.gz 21 | zip 22 | 23 | ${project.artifactId}-${project.version} 24 | false 25 | 26 | 27 | false 28 | false 29 | 30 | 31 | 32 | 33 | 34 | ${project.basedir}/.. 35 | 36 | LICENSE* 37 | NOTICE 38 | RELEASE-NOTES.txt 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /dist-archive/src/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | src 19 | 20 | tar.gz 21 | zip 22 | 23 | ${project.artifactId}-${project.version}-src 24 | 25 | 26 | ../ 27 | 28 | .asf.yaml 29 | **/.git/** 30 | .gitattributes 31 | .github/** 32 | .gitignore 33 | **/site-content/** 34 | site-content.README 35 | **/target/** 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /doc/development/development.howto.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | This document summarizes the development process of Commons Numbers: 18 | 19 | 1. The "master" branch collects all modifications that will be part 20 | of the next release. 21 | Usually, non trivial changes should not be committed directly to the "master" 22 | branch; they should be merged from a branch specifically created for 23 | that purpose (see next point). 24 | 2. Work on an identified issue (bug fix or new feature) must be done in a 25 | new branch named after its corresponding report in the bug-tracking 26 | system (JIRA), e.g. "feature-NUMBERS-123". 27 | After completion, and in the absence of technical objections, the feature 28 | branch is merged into the "master" branch, using the "--no-ff" git 29 | option. 30 | That feature branch is then deleted. 31 | -------------------------------------------------------------------------------- /doc/release/copyLongTermJavadoc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | set -e 19 | 20 | # List of all modules paths for which the long-term Javadoc links must be copied 21 | # We keep only the official distribution (i.e. _not_ "commons-numbers-examples"). 22 | MODULES=(commons-numbers-angle \ 23 | commons-numbers-arrays \ 24 | commons-numbers-combinatorics \ 25 | commons-numbers-complex \ 26 | commons-numbers-core \ 27 | commons-numbers-field \ 28 | commons-numbers-fraction \ 29 | commons-numbers-gamma \ 30 | commons-numbers-primes \ 31 | commons-numbers-quaternion \ 32 | commons-numbers-rootfinder) 33 | 34 | while getopts r:v: option 35 | do 36 | case "${option}" 37 | in 38 | r) REVISION=${OPTARG};; 39 | v) VERSION=${OPTARG};; 40 | esac 41 | done 42 | 43 | if [ "$REVISION" == "" ]; then 44 | echo "Missing SVN revision: Specify '-r '"; 45 | exit 1; 46 | fi 47 | 48 | if [ "$VERSION" == "" ]; then 49 | echo "Missing component version: Specify '-v '"; 50 | exit 1; 51 | fi 52 | 53 | for mod in ${MODULES[@]}; do 54 | echo $mod 55 | CPLIST+=" cp $REVISION $mod/apidocs $mod/javadocs/api-$VERSION" 56 | done 57 | 58 | echo -n "Copying long-term links ... " 59 | svnmucc -U https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-numbers \ 60 | $CPLIST \ 61 | -m "Commons Numbers: Copying $VERSION apidocs to versioned directories for the long-term links." 62 | echo "Done." 63 | -------------------------------------------------------------------------------- /doc/release/settings-security.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | {YBj6__Your_encrypted_master_password__3iR4=} 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc/release/settings.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | apache.snapshots.https 24 | __Your_apache_login__ 25 | {0Lbb__Your_encrypted_password__O4sQ=} 26 | 27 | 28 | 29 | 30 | apache.releases.https 31 | __Your_apache_login__ 32 | {0Lbb__Your_encrypted_password__O4sQ=} 33 | 34 | 35 | 36 | 37 | stagingSite 38 | __Your_apache_login__ 39 | 41 | 42 | 43 | 44 | 45 | people.apache.org 46 | __Your_apache_login__ 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | release 56 | 57 | __Your_key_identifier__ 58 | gpg2 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | bin 21 | 22 | tar.gz 23 | zip 24 | 25 | false 26 | 27 | 28 | 29 | LICENSE* 30 | NOTICE* 31 | RELEASE-NOTES.txt 32 | 33 | 34 | 35 | target 36 | 37 | 38 | *.jar 39 | 40 | 41 | 42 | target/site 43 | docs 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | src 20 | 21 | tar.gz 22 | zip 23 | 24 | 25 | ${project.artifactId}-${commons.release.version}-src 26 | 27 | 28 | 29 | 30 | *.txt 31 | *.xml 32 | 33 | 34 | 35 | src 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/conf/checkstyle/license-header.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | -------------------------------------------------------------------------------- /src/media/math.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-numbers/3c2ccd782e3a3a293b657834dd99793f6e204431/src/media/math.xcf -------------------------------------------------------------------------------- /src/site/resources/download_numbers.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # Just call the standard mirrors.cgi script. It will use download.html 19 | # as the input template. 20 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /src/site/resources/images/commons_numbers.small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-numbers/3c2ccd782e3a3a293b657834dd99793f6e204431/src/site/resources/images/commons_numbers.small.png -------------------------------------------------------------------------------- /src/site/resources/images/userguide/cannonball_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-numbers/3c2ccd782e3a3a293b657834dd99793f6e204431/src/site/resources/images/userguide/cannonball_example.png -------------------------------------------------------------------------------- /src/site/resources/images/userguide/cluster_comparison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-numbers/3c2ccd782e3a3a293b657834dd99793f6e204431/src/site/resources/images/userguide/cluster_comparison.png -------------------------------------------------------------------------------- /src/site/resources/images/userguide/constant_voltage_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-numbers/3c2ccd782e3a3a293b657834dd99793f6e204431/src/site/resources/images/userguide/constant_voltage_example.png -------------------------------------------------------------------------------- /src/site/resources/images/userguide/low_discrepancy_sequences.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-numbers/3c2ccd782e3a3a293b657834dd99793f6e204431/src/site/resources/images/userguide/low_discrepancy_sequences.png -------------------------------------------------------------------------------- /src/site/resources/images/userguide/real_distribution_examples.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-numbers/3c2ccd782e3a3a293b657834dd99793f6e204431/src/site/resources/images/userguide/real_distribution_examples.png -------------------------------------------------------------------------------- /src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /src/site/resources/release-notes/RELEASE-NOTES-1.0-beta1.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache Commons Numbers 1.0-beta1 RELEASE NOTES 3 | 4 | The Apache Commons Numbers team is pleased to announce the release of 5 | commons-numbers-parent-1.0-beta1 6 | 7 | The Apache Commons Numbers project provides number types and utilities. 8 | 9 | This is a beta release of Apache Commons Numbers. No guarantees are made regarding the stability 10 | of the API or compatibility with future releases. 11 | 12 | Apache Commons Numbers 1.0-beta1 contains the following library modules: 13 | commons-numbers-angle (requires Java 8+) 14 | commons-numbers-arrays (requires Java 8+) 15 | commons-numbers-combinatorics (requires Java 8+) 16 | commons-numbers-complex (requires Java 8+) 17 | commons-numbers-core (requires Java 8+) 18 | commons-numbers-field (requires Java 8+) 19 | commons-numbers-fraction (requires Java 8+) 20 | commons-numbers-gamma (requires Java 8+) 21 | commons-numbers-primes (requires Java 8+) 22 | commons-numbers-quaternion (requires Java 8+) 23 | commons-numbers-rootfinder (requires Java 8+) 24 | 25 | No changes defined in this version. 26 | 27 | For complete information on Apache Commons Numbers, including instructions on how to submit bug 28 | reports, patches, or suggestions for improvement, see the Apache Commons Numbers website: 29 | 30 | http://commons.apache.org/proper/commons-numbers/ 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/site/resources/style/project.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | @import url("http://commons.apache.org/style/commons-maven.css"); 19 | -------------------------------------------------------------------------------- /src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | Apache Commons Numbers 24 | 25 | 26 | 27 | 28 |
29 |

30 | Apache Commons Numbers provides implementations of number types and utilities. 31 | Features include: 32 |

33 |
    34 |
  • angles
  • 35 |
  • arrays
  • 36 |
  • combinatorics
  • 37 |
  • complex numbers
  • 38 |
  • core arithmetic
  • 39 |
  • fields
  • 40 |
  • fractions
  • 41 |
  • gamma functions
  • 42 |
  • primes
  • 43 |
  • quaternions
  • 44 |
  • root finding
  • 45 |
46 |
47 | 48 |
49 | 50 |

51 | Download the 52 | 53 | Latest Release of Apache Commons Numbers. 54 |

55 |
56 | 57 |
58 | 59 |
60 | -------------------------------------------------------------------------------- /src/site/xdoc/release-history.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | Home 19 | Commons Documentation Team 20 | 21 | 22 | 23 |
24 |

Note. For older release javadocs see the individual artifact sub-sites.

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
VersionRelease date (YYYY-MM-DD)Required Java VersionRelease notes
1.22024-08-128+release notes for 1.2
1.12022-11-018+release notes for 1.1
1.02021-07-178+release notes for 1.0
1.0-beta12020-04-058+release notes for 1.0-beta1
40 | 41 |
42 | 43 | 44 |
45 | --------------------------------------------------------------------------------