Copy disabled (too large)
Download .txt
Showing preview only (14,538K chars total). Download the full file to get everything.
Repository: eobermuhlner/big-math
Branch: master
Commit: 7d84ea3ffcef
Files: 606
Total size: 13.7 MB
Directory structure:
gitextract_36f9jpuf/
├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── build.gradle
├── ch.obermuhlner.math.big/
│ ├── build.gradle
│ └── src/
│ ├── main/
│ │ └── java/
│ │ └── ch/
│ │ └── obermuhlner/
│ │ └── math/
│ │ └── big/
│ │ ├── BigComplex.java
│ │ ├── BigComplexMath.java
│ │ ├── BigDecimalMath.java
│ │ ├── BigFloat.java
│ │ ├── BigRational.java
│ │ ├── DefaultBigDecimalMath.java
│ │ ├── internal/
│ │ │ ├── AsinCalculator.java
│ │ │ ├── AtanhCalculator.java
│ │ │ ├── CosCalculator.java
│ │ │ ├── CoshCalculator.java
│ │ │ ├── ExpCalculator.java
│ │ │ ├── PowerIterator.java
│ │ │ ├── PowerNIterator.java
│ │ │ ├── PowerTwoNIterator.java
│ │ │ ├── PowerTwoNMinusOneIterator.java
│ │ │ ├── PowerTwoNPlusOneIterator.java
│ │ │ ├── SeriesCalculator.java
│ │ │ ├── SinCalculator.java
│ │ │ └── SinhCalculator.java
│ │ └── stream/
│ │ ├── BigDecimalStream.java
│ │ └── BigFloatStream.java
│ └── test/
│ └── java/
│ └── ch/
│ └── obermuhlner/
│ ├── math/
│ │ └── big/
│ │ ├── BigComplexMathTest.java
│ │ ├── BigComplexTest.java
│ │ ├── BigDecimalMathTest.java
│ │ ├── BigFloatTest.java
│ │ ├── BigRationalTest.java
│ │ ├── DefaultBigDecimalMathTest.java
│ │ └── stream/
│ │ ├── BigDecimalStreamTest.java
│ │ └── BigFloatStreamTest.java
│ └── util/
│ └── ThreadUtil.java
├── ch.obermuhlner.math.big.example/
│ ├── build.gradle
│ ├── docu/
│ │ ├── benchmarks/
│ │ │ ├── csv2chart.properties
│ │ │ ├── perf_adaptive_log_precisions_to_1000.csv
│ │ │ ├── perf_atan2_y_5_x_from_-10_to_10.csv
│ │ │ ├── perf_atan2_y_from_-10_to_10_x_5.csv
│ │ │ ├── perf_atan2_yx_from_-10_to_10.csv
│ │ │ ├── perf_atan2_yx_from_-10_to_10.properties
│ │ │ ├── perf_atanh_funcs_from_-1_to_1_impl.csv
│ │ │ ├── perf_basic_operations_fast_precisions_to_10000.csv
│ │ │ ├── perf_basic_operations_fast_precisions_to_100000.csv
│ │ │ ├── perf_basic_operations_slow2_precisions_to_10000.csv
│ │ │ ├── perf_basic_operations_slow2_precisions_to_100000.csv
│ │ │ ├── perf_basic_operations_slow_precisions_to_10000.csv
│ │ │ ├── perf_basic_operations_slow_precisions_to_100000.csv
│ │ │ ├── perf_bigdec_string_impl_precisions_to_10000.csv
│ │ │ ├── perf_bigdec_string_impl_precisions_to_100000.csv
│ │ │ ├── perf_bigdec_string_impl_precisions_to_2000.csv
│ │ │ ├── perf_bigdec_string_precisions_to_10000.csv
│ │ │ ├── perf_bigdec_string_precisions_to_100000.csv
│ │ │ ├── perf_bigdec_string_precisions_to_1000000.csv
│ │ │ ├── perf_bigdec_string_precisions_to_2000.csv
│ │ │ ├── perf_cos_funcs_from_0_to_3.csv
│ │ │ ├── perf_exp_funcs_from_0_to_1.csv
│ │ │ ├── perf_exp_funcs_from_0_to_10.csv
│ │ │ ├── perf_exp_funcs_from_0_to_3.csv
│ │ │ ├── perf_factorial_impl_loops_values_to_1000.csv
│ │ │ ├── perf_factorial_impl_recursion_values_to_100.csv
│ │ │ ├── perf_factorial_impl_recursion_values_to_1000.csv
│ │ │ ├── perf_factorial_impl_values_to_100.csv
│ │ │ ├── perf_factorial_impl_values_to_1000.csv
│ │ │ ├── perf_factorial_impl_values_to_200.csv
│ │ │ ├── perf_factorial_impl_values_to_500.csv
│ │ │ ├── perf_fast_funcs_from_-10_to_10.csv
│ │ │ ├── perf_fast_funcs_from_0_to_10.csv
│ │ │ ├── perf_fast_funcs_from_0_to_100.csv
│ │ │ ├── perf_fast_funcs_from_0_to_2.csv
│ │ │ ├── perf_fast_funcs_precisions_to_1000.csv
│ │ │ ├── perf_hyperbolic_funcs_from_0_to_2.csv
│ │ │ ├── perf_java9_sqrt_from_0_to_10.csv
│ │ │ ├── perf_java9_sqrt_from_0_to_100.csv
│ │ │ ├── perf_java9_sqrt_from_0_to_10000.csv
│ │ │ ├── perf_java9_sqrt_precisions_to_1000.csv
│ │ │ ├── perf_java9_sqrt_precisions_to_10000.csv
│ │ │ ├── perf_java9_sqrt_precisions_to_200.csv
│ │ │ ├── perf_log_from_0_to_100000.csv
│ │ │ ├── perf_pow_frac_from_0_to_1000.csv
│ │ │ ├── perf_pow_from_0_to_100.csv
│ │ │ ├── perf_pow_int_from_0_to_10000.csv
│ │ │ ├── perf_pow_int_from_0_to_100000.csv
│ │ │ ├── perf_sin_funcs_from_0_to_3.csv
│ │ │ ├── perf_slow_funcs_from_-10_to_10.csv
│ │ │ ├── perf_slow_funcs_from_0_to_10.csv
│ │ │ ├── perf_slow_funcs_from_0_to_100.csv
│ │ │ ├── perf_slow_funcs_from_0_to_1000.csv
│ │ │ ├── perf_slow_funcs_from_0_to_2.csv
│ │ │ ├── perf_slow_funcs_precisions_to_1000.csv
│ │ │ ├── perf_trigo_funcs_from_0_to_1.csv
│ │ │ ├── regression/
│ │ │ │ ├── after_fewer_mc.csv
│ │ │ │ ├── before after fewer mc optimization.csv
│ │ │ │ ├── before_fewer_mc.csv
│ │ │ │ ├── v1.0.0.csv
│ │ │ │ ├── v1.1.0.csv
│ │ │ │ └── v1.2.0.csv
│ │ │ ├── test_asin_impl_from_0_to_1.csv
│ │ │ ├── test_exp_impl_from_0_to_4.csv
│ │ │ ├── test_log_adaptive_impl_from_0_to_10.csv
│ │ │ ├── test_log_impl_from_0_to_10.csv
│ │ │ ├── test_log_impl_from_0_to_100.csv
│ │ │ ├── test_root_impl_from_0_to_10.csv
│ │ │ ├── test_sqrt_impl_from_0_to_1.csv
│ │ │ ├── test_sqrt_impl_from_0_to_100.csv
│ │ │ ├── test_sqrt_impl_from_0_to_1000.csv
│ │ │ ├── values_atan2_yx_from_-10_to_10.csv
│ │ │ └── values_atan2_yx_from_-10_to_10.properties
│ │ ├── tables/
│ │ │ └── bernoulli.csv
│ │ └── wordpress/
│ │ ├── AdaptiveNewton.txt
│ │ └── BigDecimalMath.txt
│ └── src/
│ └── main/
│ └── java/
│ └── ch/
│ └── obermuhlner/
│ └── math/
│ └── big/
│ └── example/
│ ├── BernoulliTable.java
│ ├── BigDecimalMathExample.java
│ ├── BigFloatExample.java
│ ├── DefaultBigDecimalMathExample.java
│ ├── FunctionTable.java
│ ├── HighPrecisionMath.java
│ ├── PiExample.java
│ ├── StopWatch.java
│ ├── internal/
│ │ ├── AggregateCsv.java
│ │ ├── BigDecimalExperiments.java
│ │ ├── BigDecimalMathExperimental.java
│ │ ├── GammaExperiments.java
│ │ ├── PerformanceBigDecimalMath.java
│ │ ├── PerformanceRegressionBigDecimalMath.java
│ │ └── SqrtExperiments.java
│ └── stream/
│ ├── BigDecimalStreamExample.java
│ └── BigFloatStreamExample.java
├── docs/
│ ├── _config.yml
│ ├── index.md
│ ├── javadoc/
│ │ ├── v1.3.0/
│ │ │ ├── META-INF/
│ │ │ │ └── MANIFEST.MF
│ │ │ ├── allclasses-frame.html
│ │ │ ├── allclasses-noframe.html
│ │ │ ├── ch/
│ │ │ │ └── obermuhlner/
│ │ │ │ └── math/
│ │ │ │ └── big/
│ │ │ │ ├── BigDecimalMath.html
│ │ │ │ ├── BigFloat.Context.html
│ │ │ │ ├── BigFloat.html
│ │ │ │ ├── BigRational.html
│ │ │ │ ├── internal/
│ │ │ │ │ ├── AsinCalculator.html
│ │ │ │ │ ├── CosCalculator.html
│ │ │ │ │ ├── CoshCalculator.html
│ │ │ │ │ ├── ExpCalculator.html
│ │ │ │ │ ├── PowerIterator.html
│ │ │ │ │ ├── PowerNIterator.html
│ │ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ │ ├── SeriesCalculator.html
│ │ │ │ │ ├── SinCalculator.html
│ │ │ │ │ ├── SinhCalculator.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ ├── package-tree.html
│ │ │ │ └── stream/
│ │ │ │ ├── BigDecimalStream.html
│ │ │ │ ├── BigFloatStream.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── constant-values.html
│ │ │ ├── deprecated-list.html
│ │ │ ├── help-doc.html
│ │ │ ├── index-all.html
│ │ │ ├── index.html
│ │ │ ├── overview-frame.html
│ │ │ ├── overview-summary.html
│ │ │ ├── overview-tree.html
│ │ │ ├── package-list
│ │ │ ├── script.js
│ │ │ └── stylesheet.css
│ │ ├── v2.0.0/
│ │ │ ├── allclasses-frame.html
│ │ │ ├── allclasses-noframe.html
│ │ │ ├── ch/
│ │ │ │ └── obermuhlner/
│ │ │ │ └── math/
│ │ │ │ └── big/
│ │ │ │ ├── BigComplex.html
│ │ │ │ ├── BigComplexMath.html
│ │ │ │ ├── BigDecimalMath.html
│ │ │ │ ├── BigFloat.Context.html
│ │ │ │ ├── BigFloat.html
│ │ │ │ ├── BigRational.html
│ │ │ │ ├── internal/
│ │ │ │ │ ├── AsinCalculator.html
│ │ │ │ │ ├── CosCalculator.html
│ │ │ │ │ ├── CoshCalculator.html
│ │ │ │ │ ├── ExpCalculator.html
│ │ │ │ │ ├── PowerIterator.html
│ │ │ │ │ ├── PowerNIterator.html
│ │ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ │ ├── SeriesCalculator.html
│ │ │ │ │ ├── SinCalculator.html
│ │ │ │ │ ├── SinhCalculator.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ ├── package-tree.html
│ │ │ │ └── stream/
│ │ │ │ ├── BigDecimalStream.html
│ │ │ │ ├── BigFloatStream.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── constant-values.html
│ │ │ ├── deprecated-list.html
│ │ │ ├── help-doc.html
│ │ │ ├── index-all.html
│ │ │ ├── index.html
│ │ │ ├── overview-frame.html
│ │ │ ├── overview-summary.html
│ │ │ ├── overview-tree.html
│ │ │ ├── package-list
│ │ │ ├── script.js
│ │ │ └── stylesheet.css
│ │ ├── v2.0.1/
│ │ │ ├── allclasses-frame.html
│ │ │ ├── allclasses-noframe.html
│ │ │ ├── ch/
│ │ │ │ └── obermuhlner/
│ │ │ │ └── math/
│ │ │ │ └── big/
│ │ │ │ ├── BigComplex.html
│ │ │ │ ├── BigComplexMath.html
│ │ │ │ ├── BigDecimalMath.html
│ │ │ │ ├── BigFloat.Context.html
│ │ │ │ ├── BigFloat.html
│ │ │ │ ├── BigRational.html
│ │ │ │ ├── internal/
│ │ │ │ │ ├── AsinCalculator.html
│ │ │ │ │ ├── CosCalculator.html
│ │ │ │ │ ├── CoshCalculator.html
│ │ │ │ │ ├── ExpCalculator.html
│ │ │ │ │ ├── PowerIterator.html
│ │ │ │ │ ├── PowerNIterator.html
│ │ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ │ ├── SeriesCalculator.html
│ │ │ │ │ ├── SinCalculator.html
│ │ │ │ │ ├── SinhCalculator.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ ├── package-tree.html
│ │ │ │ └── stream/
│ │ │ │ ├── BigDecimalStream.html
│ │ │ │ ├── BigFloatStream.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── constant-values.html
│ │ │ ├── deprecated-list.html
│ │ │ ├── help-doc.html
│ │ │ ├── index-all.html
│ │ │ ├── index.html
│ │ │ ├── overview-frame.html
│ │ │ ├── overview-summary.html
│ │ │ ├── overview-tree.html
│ │ │ ├── package-list
│ │ │ ├── script.js
│ │ │ └── stylesheet.css
│ │ ├── v2.1.0/
│ │ │ ├── allclasses-frame.html
│ │ │ ├── allclasses-noframe.html
│ │ │ ├── ch/
│ │ │ │ └── obermuhlner/
│ │ │ │ └── math/
│ │ │ │ └── big/
│ │ │ │ ├── BigComplex.html
│ │ │ │ ├── BigComplexMath.html
│ │ │ │ ├── BigDecimalMath.html
│ │ │ │ ├── BigFloat.Context.html
│ │ │ │ ├── BigFloat.html
│ │ │ │ ├── BigRational.html
│ │ │ │ ├── DefaultBigDecimalMath.html
│ │ │ │ ├── internal/
│ │ │ │ │ ├── AsinCalculator.html
│ │ │ │ │ ├── AtanhCalculator.html
│ │ │ │ │ ├── CosCalculator.html
│ │ │ │ │ ├── CoshCalculator.html
│ │ │ │ │ ├── ExpCalculator.html
│ │ │ │ │ ├── PowerIterator.html
│ │ │ │ │ ├── PowerNIterator.html
│ │ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ │ ├── PowerTwoNMinusOneIterator.html
│ │ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ │ ├── SeriesCalculator.html
│ │ │ │ │ ├── SinCalculator.html
│ │ │ │ │ ├── SinhCalculator.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ ├── package-tree.html
│ │ │ │ └── stream/
│ │ │ │ ├── BigDecimalStream.html
│ │ │ │ ├── BigFloatStream.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── constant-values.html
│ │ │ ├── deprecated-list.html
│ │ │ ├── help-doc.html
│ │ │ ├── index-all.html
│ │ │ ├── index.html
│ │ │ ├── overview-frame.html
│ │ │ ├── overview-summary.html
│ │ │ ├── overview-tree.html
│ │ │ ├── package-list
│ │ │ ├── script.js
│ │ │ └── stylesheet.css
│ │ ├── v2.2.0/
│ │ │ ├── allclasses-frame.html
│ │ │ ├── allclasses-noframe.html
│ │ │ ├── ch/
│ │ │ │ └── obermuhlner/
│ │ │ │ └── math/
│ │ │ │ └── big/
│ │ │ │ ├── BigComplex.html
│ │ │ │ ├── BigComplexMath.html
│ │ │ │ ├── BigDecimalMath.html
│ │ │ │ ├── BigFloat.Context.html
│ │ │ │ ├── BigFloat.html
│ │ │ │ ├── BigRational.html
│ │ │ │ ├── DefaultBigDecimalMath.html
│ │ │ │ ├── internal/
│ │ │ │ │ ├── AsinCalculator.html
│ │ │ │ │ ├── AtanhCalculator.html
│ │ │ │ │ ├── CosCalculator.html
│ │ │ │ │ ├── CoshCalculator.html
│ │ │ │ │ ├── ExpCalculator.html
│ │ │ │ │ ├── PowerIterator.html
│ │ │ │ │ ├── PowerNIterator.html
│ │ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ │ ├── PowerTwoNMinusOneIterator.html
│ │ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ │ ├── SeriesCalculator.html
│ │ │ │ │ ├── SinCalculator.html
│ │ │ │ │ ├── SinhCalculator.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ ├── package-tree.html
│ │ │ │ └── stream/
│ │ │ │ ├── BigDecimalStream.html
│ │ │ │ ├── BigFloatStream.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── constant-values.html
│ │ │ ├── deprecated-list.html
│ │ │ ├── help-doc.html
│ │ │ ├── index-all.html
│ │ │ ├── index.html
│ │ │ ├── overview-frame.html
│ │ │ ├── overview-summary.html
│ │ │ ├── overview-tree.html
│ │ │ ├── package-list
│ │ │ ├── script.js
│ │ │ ├── serialized-form.html
│ │ │ └── stylesheet.css
│ │ ├── v2.2.1/
│ │ │ ├── META-INF/
│ │ │ │ └── MANIFEST.MF
│ │ │ ├── allclasses-frame.html
│ │ │ ├── allclasses-noframe.html
│ │ │ ├── ch/
│ │ │ │ └── obermuhlner/
│ │ │ │ └── math/
│ │ │ │ └── big/
│ │ │ │ ├── BigComplex.html
│ │ │ │ ├── BigComplexMath.html
│ │ │ │ ├── BigDecimalMath.html
│ │ │ │ ├── BigFloat.Context.html
│ │ │ │ ├── BigFloat.html
│ │ │ │ ├── BigRational.html
│ │ │ │ ├── DefaultBigDecimalMath.html
│ │ │ │ ├── internal/
│ │ │ │ │ ├── AsinCalculator.html
│ │ │ │ │ ├── AtanhCalculator.html
│ │ │ │ │ ├── CosCalculator.html
│ │ │ │ │ ├── CoshCalculator.html
│ │ │ │ │ ├── ExpCalculator.html
│ │ │ │ │ ├── PowerIterator.html
│ │ │ │ │ ├── PowerNIterator.html
│ │ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ │ ├── PowerTwoNMinusOneIterator.html
│ │ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ │ ├── SeriesCalculator.html
│ │ │ │ │ ├── SinCalculator.html
│ │ │ │ │ ├── SinhCalculator.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ ├── package-tree.html
│ │ │ │ └── stream/
│ │ │ │ ├── BigDecimalStream.html
│ │ │ │ ├── BigFloatStream.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── constant-values.html
│ │ │ ├── deprecated-list.html
│ │ │ ├── help-doc.html
│ │ │ ├── index-all.html
│ │ │ ├── index.html
│ │ │ ├── overview-frame.html
│ │ │ ├── overview-summary.html
│ │ │ ├── overview-tree.html
│ │ │ ├── package-list
│ │ │ ├── script.js
│ │ │ ├── serialized-form.html
│ │ │ └── stylesheet.css
│ │ ├── v2.3.0/
│ │ │ ├── allclasses-frame.html
│ │ │ ├── allclasses-noframe.html
│ │ │ ├── ch/
│ │ │ │ └── obermuhlner/
│ │ │ │ └── math/
│ │ │ │ └── big/
│ │ │ │ ├── BigComplex.html
│ │ │ │ ├── BigComplexMath.html
│ │ │ │ ├── BigDecimalMath.html
│ │ │ │ ├── BigFloat.Context.html
│ │ │ │ ├── BigFloat.html
│ │ │ │ ├── BigRational.html
│ │ │ │ ├── DefaultBigDecimalMath.LocalMathContext.html
│ │ │ │ ├── DefaultBigDecimalMath.html
│ │ │ │ ├── internal/
│ │ │ │ │ ├── AsinCalculator.html
│ │ │ │ │ ├── AtanhCalculator.html
│ │ │ │ │ ├── CosCalculator.html
│ │ │ │ │ ├── CoshCalculator.html
│ │ │ │ │ ├── ExpCalculator.html
│ │ │ │ │ ├── PowerIterator.html
│ │ │ │ │ ├── PowerNIterator.html
│ │ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ │ ├── PowerTwoNMinusOneIterator.html
│ │ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ │ ├── SeriesCalculator.html
│ │ │ │ │ ├── SinCalculator.html
│ │ │ │ │ ├── SinhCalculator.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ ├── package-tree.html
│ │ │ │ └── stream/
│ │ │ │ ├── BigDecimalStream.html
│ │ │ │ ├── BigFloatStream.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── constant-values.html
│ │ │ ├── deprecated-list.html
│ │ │ ├── help-doc.html
│ │ │ ├── index-all.html
│ │ │ ├── index.html
│ │ │ ├── overview-frame.html
│ │ │ ├── overview-summary.html
│ │ │ ├── overview-tree.html
│ │ │ ├── package-list
│ │ │ ├── script.js
│ │ │ ├── serialized-form.html
│ │ │ └── stylesheet.css
│ │ ├── v2.3.1/
│ │ │ ├── allclasses-frame.html
│ │ │ ├── allclasses-noframe.html
│ │ │ ├── ch/
│ │ │ │ └── obermuhlner/
│ │ │ │ └── math/
│ │ │ │ └── big/
│ │ │ │ ├── BigComplex.html
│ │ │ │ ├── BigComplexMath.html
│ │ │ │ ├── BigDecimalMath.html
│ │ │ │ ├── BigFloat.Context.html
│ │ │ │ ├── BigFloat.html
│ │ │ │ ├── BigRational.html
│ │ │ │ ├── DefaultBigDecimalMath.LocalMathContext.html
│ │ │ │ ├── DefaultBigDecimalMath.html
│ │ │ │ ├── analysis/
│ │ │ │ │ └── solver/
│ │ │ │ │ ├── BisectionSolver.html
│ │ │ │ │ ├── NewtonRaphsonSolver.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── internal/
│ │ │ │ │ ├── AsinCalculator.html
│ │ │ │ │ ├── AtanhCalculator.html
│ │ │ │ │ ├── CosCalculator.html
│ │ │ │ │ ├── CoshCalculator.html
│ │ │ │ │ ├── ExpCalculator.html
│ │ │ │ │ ├── PowerIterator.html
│ │ │ │ │ ├── PowerNIterator.html
│ │ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ │ ├── PowerTwoNMinusOneIterator.html
│ │ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ │ ├── SeriesCalculator.html
│ │ │ │ │ ├── SinCalculator.html
│ │ │ │ │ ├── SinhCalculator.html
│ │ │ │ │ ├── package-frame.html
│ │ │ │ │ ├── package-summary.html
│ │ │ │ │ └── package-tree.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ ├── package-tree.html
│ │ │ │ └── stream/
│ │ │ │ ├── BigDecimalStream.html
│ │ │ │ ├── BigFloatStream.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── constant-values.html
│ │ │ ├── deprecated-list.html
│ │ │ ├── help-doc.html
│ │ │ ├── index-all.html
│ │ │ ├── index.html
│ │ │ ├── overview-frame.html
│ │ │ ├── overview-summary.html
│ │ │ ├── overview-tree.html
│ │ │ ├── package-list
│ │ │ ├── script.js
│ │ │ ├── serialized-form.html
│ │ │ └── stylesheet.css
│ │ └── v2.3.2/
│ │ ├── allclasses-frame.html
│ │ ├── allclasses-noframe.html
│ │ ├── ch/
│ │ │ └── obermuhlner/
│ │ │ └── math/
│ │ │ └── big/
│ │ │ ├── BigComplex.html
│ │ │ ├── BigComplexMath.html
│ │ │ ├── BigDecimalMath.html
│ │ │ ├── BigFloat.Context.html
│ │ │ ├── BigFloat.html
│ │ │ ├── BigRational.html
│ │ │ ├── DefaultBigDecimalMath.LocalMathContext.html
│ │ │ ├── DefaultBigDecimalMath.html
│ │ │ ├── internal/
│ │ │ │ ├── AsinCalculator.html
│ │ │ │ ├── AtanhCalculator.html
│ │ │ │ ├── CosCalculator.html
│ │ │ │ ├── CoshCalculator.html
│ │ │ │ ├── ExpCalculator.html
│ │ │ │ ├── PowerIterator.html
│ │ │ │ ├── PowerNIterator.html
│ │ │ │ ├── PowerTwoNIterator.html
│ │ │ │ ├── PowerTwoNMinusOneIterator.html
│ │ │ │ ├── PowerTwoNPlusOneIterator.html
│ │ │ │ ├── SeriesCalculator.html
│ │ │ │ ├── SinCalculator.html
│ │ │ │ ├── SinhCalculator.html
│ │ │ │ ├── package-frame.html
│ │ │ │ ├── package-summary.html
│ │ │ │ └── package-tree.html
│ │ │ ├── package-frame.html
│ │ │ ├── package-summary.html
│ │ │ ├── package-tree.html
│ │ │ └── stream/
│ │ │ ├── BigDecimalStream.html
│ │ │ ├── BigFloatStream.html
│ │ │ ├── package-frame.html
│ │ │ ├── package-summary.html
│ │ │ └── package-tree.html
│ │ ├── constant-values.html
│ │ ├── deprecated-list.html
│ │ ├── help-doc.html
│ │ ├── index-all.html
│ │ ├── index.html
│ │ ├── overview-frame.html
│ │ ├── overview-summary.html
│ │ ├── overview-tree.html
│ │ ├── package-list
│ │ ├── script.js
│ │ ├── serialized-form.html
│ │ └── stylesheet.css
│ ├── markdown/
│ │ ├── atan2.md
│ │ └── gamma/
│ │ ├── csv2chart.properties
│ │ ├── factorial_calculating_spouge_constants.csv
│ │ ├── factorial_calculating_spouge_constants.properties
│ │ ├── factorial_spouge_cached_prec200.csv
│ │ ├── factorial_spouge_cached_prec200.properties
│ │ ├── factorial_spouge_cached_precisions.csv
│ │ ├── factorial_spouge_cached_precisions.properties
│ │ ├── factorial_spouge_prec200.csv
│ │ ├── factorial_spouge_prec200.properties
│ │ ├── factorial_spouge_precision.csv
│ │ ├── factorial_spouge_precision.properties
│ │ └── gamma.md
│ └── releases/
│ ├── next_release_note.md
│ ├── template_release_note.md
│ ├── v1.0-beta1.md
│ ├── v1.0-beta2.md
│ ├── v1.0.0.md
│ ├── v1.1.0.md
│ ├── v1.2.0.md
│ ├── v1.2.1.md
│ ├── v1.3.0.md
│ ├── v2.0.0.md
│ ├── v2.0.1.md
│ ├── v2.1.0.md
│ ├── v2.2.0.md
│ ├── v2.2.1.md
│ ├── v2.3.0.md
│ ├── v2.3.1.md
│ └── v2.3.2.md
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── pom.xml
├── regression/
│ ├── README.md
│ ├── analysis/
│ │ ├── build.gradle
│ │ ├── fast functions performance over releases.csv
│ │ ├── medium functions performance over releases.csv
│ │ ├── multi threading fix.csv
│ │ ├── performance over releases.csv
│ │ ├── selected functions performance over releases.csv
│ │ ├── slow functions performance over releases.csv
│ │ └── very slow functions performance over releases.csv
│ ├── v1_0_0/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v1_1_0/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v1_2_0/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v1_2_1/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v1_3_0/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v2_0_0/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v2_0_1/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v2_1_0/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v2_2_0/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v2_2_1/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v2_3_0/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v2_3_1/
│ │ ├── build.gradle
│ │ └── performance.csv
│ ├── v2_3_2/
│ │ ├── build.gradle
│ │ └── performance.csv
│ └── v_current/
│ ├── build.gradle
│ └── performance.csv
├── run_regression_analysis.sh
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# gradle stuff
.gradle
build
gradle.properties
# Eclipse IDE stuff
.project
.classpath
bin
out
.settings
# IntelliJ IDEA stuff
*.iml
.idea
================================================
FILE: .travis.yml
================================================
env:
- BIGDECIMALTEST_LEVEL=Medium
dist: trusty
language: java
jdk:
- oraclejdk11
before_install:
- chmod +x gradlew
addons:
sonarcloud:
organization: "eobermuhlner"
token:
secure: rsfHxDskN6m18xYPNdG6CZIES7D98Dekv2ZtNOU1BxeuQGqTZjn/gm/LjzK99alzmrd2gsO8EK67EGMRFM+cPqHGRJaFsNm2WgqU3UmwoVSe6wvFkDazZAHySRNeEcdmtxHUlUeQZXZvdI+gXpgiJlYxrfxh3zhDLIW5Iha2wOTTDjp/DM+VvMLo5YLDe/uKMj638QgwjJi4GFUHrkMwOx6YOm16JDOn+5BUfkjAkTDwnQF3enmiHtySXufat6hI0w1gUbUvUB5VW3HOdHdwXf2FE5VuDraWPzWkquytM0kzaFaCRDcjvXF8OXQR3aq0Jdb0cV+niY+6y6vNBPldk1rSBJr5Hn4nDFdClxb6Q1Dq5f2YvakUq9hTInluxTyPvQh5FmJZh7pq1bM8gBUIPN6ZwuicqMDtlGff4UiXKzI/waV42xUj7ZnXWWrHYrgBxcmC3HPuNGpXOifnyduVsDx4MuwHyVAGIXLzVFNDhRhykR2YJLBz3+JEL+MyoW/6UX1Jmxw9isxP6ALYe8SNtae46UVVNB8AOCg3DAdcEiCVMnCRx8gJxCFpdZ0fd1Tvm54/OoGDWh0W5rja2X+1y4yRlZc8jlp3dqyJrZBwM7ufO6rg1uNw1kzT8bslIhxjN5GAxH8nIrBl7VzKk6UynXiqmsvQvYx9M7giee9abRA=
script:
- ./gradlew sonarqube
after_success:
- bash <(curl -s https://codecov.io/bash)
# set sudo to required, because this setup gets more memory
sudo: required
# keep gradle cache
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
================================================
FILE: LICENSE.txt
================================================
MIT License
Copyright (c) 2017 Eric Obermühlner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
[](https://travis-ci.org/eobermuhlner/big-math)
[](https://codecov.io/gh/eobermuhlner/big-math)
[](https://sonarcloud.io/dashboard?id=big-math)
[](https://github.com/eobermuhlner/big-math/issues)
[](https://github.com/eobermuhlner/big-math/issues)
[](https://search.maven.org/artifact/ch.obermuhlner/big-math)
[](https://github.com/eobermuhlner/big-math/graphs/commit-activity)
[](https://gitter.im/eobermuhlner-big-math/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
<p align="center">
<img alt="big-math" src="docs/images/big-math-splashscreen.png">
</p>
Advanced Java `BigDecimal` math functions (`pow`, `sqrt`, `log`, `sin`, ...) using arbitrary precision.
See also the official [Big-Math Documentation](http://eobermuhlner.github.io/big-math/).
## BigDecimalMath
The class `BigDecimalMath` provides efficient and accurate implementations for:
* `log(BigDecimal, MathContext)`
* `exp(BigDecimal, MathContext)`
* `pow(BigDecimal, BigDecimal, MathContext)` calculates x^y
* `sqrt(BigDecimal, MathContext)`
* `root(BigDecimal, BigDecimal, MathContext)` calculates the n'th root of x
* `sin(BigDecimal, MathContext)`
* `cos(BigDecimal, MathContext)`
* `tan(BigDecimal, MathContext)`
* `asin(BigDecimal, MathContext)`
* `acos(BigDecimal, MathContext)`
* `atan(BigDecimal, MathContext)`
* `atan2(BigDecimal, BigDecimal, MathContext)`
* `sinh(BigDecimal, MathContext)`
* `cosh(BigDecimal, MathContext)`
* `tanh(BigDecimal, MathContext)`
* `asinh(BigDecimal, MathContext)`
* `acosh(BigDecimal, MathContext)`
* `atanh(BigDecimal, MathContext)`
* `toDegrees(BigDecimal, MathContext)` converts from radians to degrees
* `toRadians(BigDecimal, MathContext)` converts from degrees to radians
* `pow(BigDecimal, long, MathContext)` calculates x^y for `long` y
* `factorial(int)` calculates n!
* `bernoulli(int)` calculates Bernoulli numbers
* `pi(MathContext)` calculates pi to an arbitrary precision
* `e(MathContext)` calculates e to an arbitrary precision
* `toBigDecimal(String)` creates a `BigDecimal` from string representation (faster than `BigDecimal(String)`)
* `mantissa(BigDecimal)` extracts the mantissa from a `BigDecimal` (mantissa * 10^exponent)
* `exponent(BigDecimal)` extracts the exponent from a `BigDecimal` (mantissa * 10^exponent)
* `integralPart(BigDecimal)` extracts the integral part from a `BigDecimal` (everything before the decimal point)
* `fractionalPart(BigDecimal)` extracts the fractional part from a `BigDecimal` (everything after the decimal point)
* `isIntValue(BigDecimal)` checks whether the `BigDecimal` can be represented as an `int` value
* `isDoubleValue(BigDecimal)` checks whether the `BigDecimal` can be represented as a `double` value
* `roundWithTrailingZeroes(BigDecimal, MathContext)` rounds a `BigDecimal` to an arbitrary precision with trailing zeroes.
### Usage
#### Mathematical calculations for `BigDecimal`
For calculations with arbitrary precision you need to specify how precise you want a calculated result.
For `BigDecimal` calculations this is done using the `MathContext`.
```java
MathContext mathContext = new MathContext(100);
System.out.println("sqrt(2) = " + BigDecimalMath.sqrt(BigDecimal.valueOf(2), mathContext));
System.out.println("log10(2) = " + BigDecimalMath.log10(BigDecimal.valueOf(2), mathContext));
System.out.println("exp(2) = " + BigDecimalMath.exp(BigDecimal.valueOf(2), mathContext));
System.out.println("sin(2) = " + BigDecimalMath.sin(BigDecimal.valueOf(2), mathContext));
```
will produce the following output on the console:
```
sqrt(2) = 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573
log10(2) = 0.3010299956639811952137388947244930267681898814621085413104274611271081892744245094869272521181861720
exp(2) = 7.389056098930650227230427460575007813180315570551847324087127822522573796079057763384312485079121795
sin(2) = 0.9092974268256816953960198659117448427022549714478902683789730115309673015407835446201266889249593803
```
Since many mathematical constants have an infinite number of digits you need to specfiy the desired precision for them as well:
```java
MathContext mathContext = new MathContext(100);
System.out.println("pi = " + BigDecimalMath.pi(mathContext));
System.out.println("e = " + BigDecimalMath.e(mathContext));
```
will produce the following output on the console:
```
pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427
```
#### Convenience methods for `BigDecimal`
Additional `BigDecimalMath` provides several useful methods (that are plain missing for `BigDecimal`):
```java
MathContext mathContext = new MathContext(100);
System.out.println("mantissa(1.456E99) = " + BigDecimalMath.mantissa(BigDecimal.valueOf(1.456E99)));
System.out.println("exponent(1.456E99) = " + BigDecimalMath.exponent(BigDecimal.valueOf(1.456E99)));
System.out.println("integralPart(123.456) = " + BigDecimalMath.integralPart(BigDecimal.valueOf(123.456)));
System.out.println("fractionalPart(123.456) = " + BigDecimalMath.fractionalPart(BigDecimal.valueOf(123.456)));
System.out.println("isIntValue(123) = " + BigDecimalMath.isIntValue(BigDecimal.valueOf(123)));
System.out.println("isIntValue(123.456) = " + BigDecimalMath.isIntValue(BigDecimal.valueOf(123.456)));
System.out.println("isDoubleValue(123.456) = " + BigDecimalMath.isDoubleValue(BigDecimal.valueOf(123.456)));
System.out.println("isDoubleValue(1.23E999) = " + BigDecimalMath.isDoubleValue(new BigDecimal("1.23E999")));
```
will produce the following output on the console:
```
mantissa(1.456E99) = 1.456
exponent(1.456E99) = 99
integralPart(123.456) = 123
fractionalPart(123.456) = 0.456
isIntValue(123) = true
isIntValue(123.456) = false
isDoubleValue(123.456) = true
isDoubleValue(1.23E999) = false
```
The `BigDecimalMath` class is thread-safe and can be used in concurrent use cases.
#### Streams of `BigDecimal`
The class `BigDecimalStream` provides factory methods for streams of `BigDecimal` elements.
Overloaded variants of `range(start, end, step)` provide sequential elements equivalent to `IntStream.range(start, end)` but with configurable step (exclusive the end value).
Similar methods for the `rangeClosed()` (inclusive the end value) are available.
The streams are well behaved when used in parallel mode.
The following code snippet:
```java
System.out.println("Range [0, 10) step 1 (using BigDecimal as input parameters)");
BigDecimalStream.range(BigDecimal.valueOf(0), BigDecimal.valueOf(10), BigDecimal.valueOf(1), mathContext)
.forEach(System.out::println);
System.out.println("Range [0, 10) step 3 (using long as input parameters)");
BigDecimalStream.range(0, 10, 3, mathContext)
.forEach(System.out::println);
```
produces this output:
```
Range [0, 10) step 1 (using BigDecimal as input parameters)
0
1
2
3
4
5
6
7
8
9
Range [0, 12] step 3 (using long as input parameters)
0
3
6
9
12
```
### FAQ
#### Why do I have to pass `MathContext` to most functions?
Many mathematical functions have results that have many digits (often an infinite number of digits).
When calculating these functions you need to specify the number of digits you want in the result,
because calculating an infinite number of digits would take literally forever and consume an infinite amount of memory.
The `MathContext` contains a precision and information on how to round the last digits, so it is an obvious choice to specify the desired precision of mathematical functions.
#### What if I really do not want to pass the `MathContext` everytime?
The convenience class `DefaultBigDecimalMath` was added that provides mathematical functions
where the `MathContext` must not be passed every time.
Please refer to the chapter [DefaultBigDecimalMath](#defaultbigdecimalmath)
#### I specified a precision of `n` digits, but the results have completely different number of digits after the decimal point. Why?
It is a common misconception that the precision defines the number of digits after the decimal point.
Instead the precision defines the number of relevant digits, independent of the decimal point.
The following numbers all have a precision of 3 digits:
* 12300
* 1230
* 123
* 12.3
* 1.23
* 0.123
* 0.0123
To specify the number of digits after the decimal point use `BigDecimal.setScale(scale, mathContext)`.
#### Why are `BigDecimalMath` functions so slow?
The mathematical functions in `BigDecimalMath` are heavily optimized to calculate the result in the specified precision, but in order to calculate them often tens or even hundreds of basic operations (+, -, *, /) using `BigDecimal` are necessary.
If the calculation of your function is too slow for your purpose you should verify whether you really need the full precision in your particular use case. Sometimes you can adapt the precision depending on input factors of your calculation.
#### How are the mathematical functions in `BigDecimalMath` calculated?
For the mathematical background and performance analysis please refer to this article:
* [BigDecimalMath](http://obermuhlner.ch/wordpress/2016/06/02/bigdecimalmath/)
Some of the implementation details are explained here:
* [Adaptive precision in Newton’s Method](http://obermuhlner.ch/wordpress/2016/06/07/adaptive-precision-in-newtons-method/)
#### Why is there `BigDecimalMath.toBigDecimal(String)` if Java already has a `BigDecimal(String)` constructor?
The `BigDecimal(String)` constructor as provided by Java gets increasingly slower if you pass longer strings to it.
The implementation in Java 11 and before is O(n^2).
If you want to convert very long strings (10000 characters or longer) then this slow constructor may become an issue.
`BigDecimalMath.toBigDecimal(String)` is a drop-in replacement with the same functionality
(converting a string representation into a `BigDecimal`) but it is using a faster recursive implementation.
The following chart shows the time necessary to create a `BigDecimal` from a string representation of increasing length:

#### I only need a `sqrt` function - should I use this library?
Since Java 9 the `BigDecimal` class has a new function `sqrt(BigDecimal, MathContext)`.
If you only need the square root function then by all means use the provided standard function instead of this library.
If you need any other high level function then you should still consider using this library.
For high precision (above 150 digits) the current implementation of
Java 9 `BigDecimal.sqrt()` becomes increasingly slower than `BigDecimalMath.sqrt()`.
You should consider whether the increased performance is worth having an additional dependency.
The following charts shows the time needed to calculate the square root of 3.1 with increasing precision.


### Performance
The following charts show the time needed to calculate the functions over a range of values with a precision of 300 digits.





## BigComplex
The class `BigComplex` represents complex numbers in the form `(a + bi)`.
It follows the design of `BigDecimal` with some convenience improvements like overloaded operator methods.
A big difference to `BigDecimal` is that `BigComplex.equals()` implements the *mathematical* equality
and *not* the strict technical equality.
This was a difficult decision because it means that `BigComplex` behaves slightly different than `BigDecimal`
but considering that the strange equality of `BigDecimal` is a major source of bugs we
decided it was worth the slight inconsistency.
If you need the strict equality use `BigComplex.strictEquals()`.
* `re`
* `im`
* `add(BigComplex)`
* `add(BigComplex, MathContext)`
* `add(BigDecimal)`
* `add(BigDecimal, MathContext)`
* `add(double)`
* `subtract(BigComplex)`
* `subtract(BigComplex, MathContext)`
* `subtract(BigDecimal)`
* `subtract(BigDecimal, MathContext)`
* `subtract(double)`
* `multiply(BigComplex)`
* `multiply(BigComplex, MathContext)`
* `multiply(BigDecimal)`
* `multiply(BigDecimal, MathContext)`
* `multiply(double)`
* `divide(BigComplex)`
* `divide(BigComplex, MathContext)`
* `divide(BigDecimal)`
* `divide(BigDecimal, MathContext)`
* `divide(double)`
* `reciprocal(MathContext)`
* `conjugate()`
* `negate()`
* `abs(MathContext)`
* `angle(MathContext)`
* `absSquare(MathContext)`
* `isReal()`
* `re()`
* `im()`
* `round(MathContext)`
* `hashCode()`
* `equals(Object)`
* `strictEquals(Object)`
* `toString()`
* `valueOf(BigDecimal)`
* `valueOf(double)`
* `valueOf(BigDecimal, BigDecimal)`
* `valueOf(double, double)`
* `valueOfPolar(BigDecimal, BigDecimal, MathContext)`
* `valueOfPolar(double, double, MathContext`
## BigComplexMath
The class `BigComplexMath` is the equivalent of `BigDecimalMath` and contains mathematical functions in the complex domain.
* `sin(BigComplex, MathContext)`
* `cos(BigComplex, MathContext)`
* `tan(BigComplex, MathContext)`
* `asin(BigComplex, MathContext)`
* `acos(BigComplex, MathContext)`
* `atan(BigComplex, MathContext)`
* `acot(BigComplex, MathContext)`
* `exp(BigComplex, MathContext)`
* `log(BigComplex, MathContext)`
* `pow(BigComplex, long, MathContext)`
* `pow(BigComplex, BigDecimal, MathContext)`
* `pow(BigComplex, BigComplex, MathContext)`
* `sqrt(BigComplex, MathContext)`
* `root(BigComplex, BigDecimal, MathContext)`
* `root(BigComplex, BigComplex, MathContext)`
## DefaultBigDecimalMath
The class `DefaultBigDecimalMath` is a wrapper around `BigDecimalMath` that passes always the current `MathContext` to the
functions that need a `MathContext` argument.
The initial default `MathContext` is equivalent to `MathContext.DECIMAL128` but this can be overridden by setting the following system properties:
- `ch.obermuhlner.math.big.default.precision` to a positive integer precision (default=34)
- `ch.obermuhlner.math.big.default.rounding` to a RoundingMode name (default=HALF_UP)
It is also possible to programmatically set the default `MathContext` using `setDefaultMathContext(MathContext)`.
It is recommended to set the desired precision in the `MathContext` very early in the startup of the application and to not change it afterwards.
**Important**: Avoid the pitfall of setting the precision temporarily using `setDefaultMathContext(MathContext)` for a calculation.
This can lead to race conditions and calculations with the wrong precision if other threads in your application do the same thing.
To set a temporary `MathContext` you have to choice to use either:
- `DefaultBigDecimalMath.createLocalMathContext()` in a try-with-resources statement
- `DefaultBigDecimalMath.withLocalMathContext()` with a lambda function
Example code using `DefaultBigDecimalMath.createLocalMathContext()`:
```java
System.out.println("Pi[default]: " + DefaultBigDecimalMath.pi());
try (DefaultBigDecimalMath.LocalMathContext context = DefaultBigDecimalMath.createLocalMathContext(5)) {
System.out.println("Pi[5]: " + DefaultBigDecimalMath.pi());
try (DefaultBigDecimalMath.LocalMathContext context2 = DefaultBigDecimalMath.createLocalMathContext(10)) {
System.out.println("Pi[10]: " + DefaultBigDecimalMath.pi());
};
System.out.println("Pi[5]: " + DefaultBigDecimalMath.pi());
};
System.out.println("Pi[default]: " + DefaultBigDecimalMath.pi());
```
Example code using `DefaultBigDecimalMath.withLocalMathContext()`:
```java
System.out.println("Pi[default]: " + DefaultBigDecimalMath.pi());
DefaultBigDecimalMath.withLocalMathContext(5, () -> {
System.out.println("Pi[5]: " + DefaultBigDecimalMath.pi());
DefaultBigDecimalMath.withLocalMathContext(10, () -> {
System.out.println("Pi[10]: " + DefaultBigDecimalMath.pi());
});
System.out.println("Pi[5]: " + DefaultBigDecimalMath.pi());
});
System.out.println("Pi[default]: " + DefaultBigDecimalMath.pi());
```
Both snippets will give the following output:
```console
Pi[default]: 3.141592653589793238462643383279503
Pi[5]: 3.1416
Pi[10]: 3.141592654
Pi[5]: 3.1416
Pi[default]: 3.141592653589793238462643383279503
```
The temporary `MathContext` are stored in `ThreadLocal` variables
and will therefore not conflict with each other when used in multi-threaded use case.
**Important**: Due to the `ThreadLocal` variables the temporary `MathContext` will
_not_ be available in other threads.
This includes streams using `parallel()`, thread pools and manually started threads.
If you need temporary `MathContext` for calculations then you _must_
set the local `MathContext` inside _every_ separate thread.
```java
try (DefaultBigDecimalMath.LocalMathContext context = DefaultBigDecimalMath.createLocalMathContext(5)) {
BigDecimalStream.range(0.0, 1.0, 0.01, DefaultBigDecimalMath.currentMathContext())
.map(b -> DefaultBigDecimalMath.cos(b))
.map(b -> "sequential " + Thread.currentThread().getName() + " [5]: " + b)
.forEach(System.out::println);
BigDecimalStream.range(0.0, 1.0, 0.01, DefaultBigDecimalMath.currentMathContext())
.parallel()
.map(b -> {
try (DefaultBigDecimalMath.LocalMathContext context2 = DefaultBigDecimalMath.createLocalMathContext(5)) {
return DefaultBigDecimalMath.cos(b);
}
})
.map(b -> "parallel " + Thread.currentThread().getName() + " [5]: " + b)
.forEach(System.out::println);
}
```
## BigFloat
The class `BigFloat` is an experimental wrapper around `BigDecimal` which simplifies the consistent usage of the `MathContext` and provides a simpler API for calculations.
The API for calculations is simplified and more consistent with the typical mathematical usage.
* Factory methods on the `Context` class for values:
* `valueOf(BigFloat)`
* `valueOf(BigDecimal)`
* `valueOf(int)`
* `valueOf(long)`
* `valueOf(double)`
* `valueOf(String)`
* `pi()`
* `e()`
* All standard operators:
* `add(x)`
* `subtract(x)`
* `multiply(x)`
* `divide(x)`
* `remainder(x)`
* `pow(y)`
* `root(y)`
* Calculation methods are overloaded for different value types:
* `add(BigFloat)`
* `add(BigDecimal)`
* `add(int)`
* `add(long)`
* `add(double)`
* ...
* Mathematical functions are written in the traditional form:
* `abs(x)`
* `log(x)`
* `sin(x)`
* `min(x1, x2, ...)`
* `max(x1, x2, ...)`
* ...
* Support for advanced mathematical functions:
* `sqrt(x)`
* `log(x)`
* `exp(x)`
* `sin(x)`
* `cos(x)`
* `tan(x)`
* ...
* Methods to access parts of a value:
* `getMantissa()`
* `getExponent()`
* `getIntegralPart()`
* `getFractionalPart()`
* Methods to verify value type conversions:
* `isIntValue()`
* `isDoubleValue()`
* Equals and Hashcode methods:
* `equals(Object)` returns whether two `BigFloat` values are mathematically the same
* `hashCode()` consistent with `equals(Object)`
* Comparison methods:
* `isEqual(BigFloat)`
* `isLessThan(BigFloat)`
* `isLessThanOrEqual(BigFloat)`
* `isGreaterThan(BigFloat)`
* `isGreaterThanOrEqual(BigFloat)`
* Sign methods:
* `signum()`
* `isNegative()`
* `isZero()`
* `isPositive()`
### Usage
Before doing any calculations you need to create a `Context` specifying the precision used for all calculations.
```java
Context context = BigFloat.context(100); // precision of 100 digits
Context anotherContext = BigFloat.context(new MathContext(10, RoundingMode.HALF_UP); // precision of 10 digits, rounding half up
```
The `Context` can then be used to create the first value of the calculation:
```java
BigFloat value1 = context.valueOf(640320);
```
The `BigFloat` instance holds a reference to the `Context`. This context is then passed from calculation to calculation.
```java
BigFloat value2 = context.valueOf(640320).pow(3).divide(24);
BigFloat value3 = BigFloat.sin(value2);
```
The `BigFloat` result can be converted to other numerical types:
```java
BigDecimal bigDecimalValue = value3.toBigDecimal();
double doubleValue = value3.toDouble();
long longValue = value3.toLong();
int intValue = value3.toInt();
```
The `BigFloatStream` provides similar stream factories as `BigDecimalStream` that will produce streams of `BigFloat` elements.
### Usage in Java Module Systems (Jigsaw and OSGi)
Since release 2.0.1 the deployed big-math Jar file contains now a module name for the Jigsaw module system (Java 9 and later).
This allows it to be used as automatic module with a well defined module name instead
of deriving the name magically from the Jar file name.
The module name follows the reverse domain convention and is: `ch.obermuhlner.math.big`
The big-math Jar file is also OSGi compatible.
The `MANIFEST.MF` contains all the necessary headers and exports the public packages:
- `ch.obermuhlner.math.big`
- `ch.obermuhlner.math.big.stream`
### Usage in Kotlin
If you want to use big-math library in Kotlin you may do so directly, or you use the
[kotlin-big-math](https://github.com/eobermuhlner/kotlin-big-math) library that provides additional features, like operators.
## Using big-math in your projects
To use the Java library you can either download the newest version of the .jar file from the
[published releases on Github](https://github.com/eobermuhlner/big-math/releases/)
or use the following dependency to
[Maven Central](https://search.maven.org/#search%7Cga%7C1%7Cbig-math)
in your build script (please verify the version number to be the newest release):
### Use big-math in Maven Build
```xml
<dependency>
<groupId>ch.obermuhlner</groupId>
<artifactId>big-math</artifactId>
<version>2.3.2</version>
</dependency>
```
### Use big-math in Gradle Build
```gradle
repositories {
mavenCentral()
}
dependencies {
compile 'ch.obermuhlner:big-math:2.3.2'
}
```
================================================
FILE: build.gradle
================================================
buildscript {
ext.kotlin_version = '1.1.3'
ext.dokka_version = '0.9.15'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}"
}
}
================================================
FILE: ch.obermuhlner.math.big/build.gradle
================================================
plugins {
id 'org.sonarqube' version '2.7'
id 'java'
id 'eclipse'
id 'maven'
id 'signing'
id 'jacoco'
}
group = 'ch.obermuhlner'
version = '2.3.2'
archivesBaseName = 'big-math'
ext {
moduleName = "ch.obermuhlner.math.big"
if (!project.hasProperty("ossrhUsername")) {
ossrhUsername = "undefined"
}
if (!project.hasProperty("ossrhPassword")) {
ossrhPassword="undefined"
}
}
repositories {
mavenLocal()
mavenCentral()
}
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
dependencies {
testCompile 'junit:junit:4.12'
}
test {
testLogging {
events "failed"
exceptionFormat "full"
}
}
sonarqube {
properties {
property "sonar.projectKey", "big-math"
}
}
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}
check.dependsOn jacocoTestReport
jar {
manifest {
attributes(
"Automatic-Module-Name": moduleName,
"Bundle-ManifestVersion": 2,
"Bundle-Name": archivesBaseName,
"Bundle-SymbolicName": moduleName,
"Bundle-Version": version,
"Export-Package": "ch.obermuhlner.math.big, ch.obermuhlner.math.big.stream")
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
//archives jar // no longer needed tp add - will lead to duplicate
archives sourcesJar
archives javadocJar
}
signing {
required {
gradle.taskGraph.hasTask("uploadArchives")
}
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Big Math'
packaging 'jar'
// optionally artifactId can be defined here
description 'Math functions for BigDecimal.'
url 'https://github.com/eobermuhlner/big-math'
scm {
connection 'scm:git:git://github.com/big-math.git'
developerConnection 'scm:ssh://github.com:eobermuhlner/big-math.git'
url 'https://github.com/eobermuhlner/big-math/'
}
licenses {
license {
name 'MIT License'
url 'https://raw.githubusercontent.com/eobermuhlner/big-math/master/LICENSE.txt'
}
}
developers {
developer {
id 'eobermuhlner'
name 'Eric Obermuhlner'
email 'eobermuhlner@gmail.com'
}
}
}
}
}
}
// See http://central.sonatype.org/pages/gradle.html
================================================
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigComplex.java
================================================
package ch.obermuhlner.math.big;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Objects;
/**
* Represents a complex number consisting of a real and an imaginary {@link BigDecimal} part in the form {@code a + bi}.
*
* <p>It generally follows the design of {@link BigDecimal} with some convenience improvements like overloaded operator methods.</p>
*
* <p>The biggest difference to {@link BigDecimal} is that {@link BigComplex#equals(Object) BigComplex.equals(Object)} implements the <strong>mathematical</strong> equality
* and <strong>not</strong> the strict technical equality.
* This was a difficult decision because it means that {@code BigComplex} behaves slightly different than {@link BigDecimal}
* but considering that the strange equality of {@link BigDecimal} is a major source of bugs we
* decided it was worth the slight inconsistency.
* If you need the strict equality use {@link BigComplex#strictEquals(Object)}`.</p>
*
* <p>This class is immutable and therefore inherently thread safe.</p>
*/
public final class BigComplex {
/**
* Zero represented as complex number.
*/
public static final BigComplex ZERO = new BigComplex(BigDecimal.ZERO, BigDecimal.ZERO);
/**
* Real 1 represented as complex number.
*/
public static final BigComplex ONE = new BigComplex(BigDecimal.ONE, BigDecimal.ZERO);
/**
* Imaginary 1 represented as complex number.
*/
public static final BigComplex I = new BigComplex(BigDecimal.ZERO, BigDecimal.ONE);
/**
* The real {@link BigDecimal} part of this complex number.
*/
public final BigDecimal re;
/**
* The imaginary {@link BigDecimal} part of this complex number.
*/
public final BigDecimal im;
private BigComplex(BigDecimal re, BigDecimal im) {
this.re = re;
this.im = im;
}
/**
* Calculates the addition of the given complex value to this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@link BigComplex} value to add
* @return the calculated {@link BigComplex} result
*/
public BigComplex add(BigComplex value) {
return valueOf(
re.add(value.re),
im.add(value.im));
}
/**
* Calculates the addition of the given complex value to this complex number using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@link BigComplex} value to add
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex add(BigComplex value, MathContext mathContext) {
return valueOf(
re.add(value.re, mathContext),
im.add(value.im, mathContext));
}
/**
* Calculates the addition of the given real {@link BigDecimal} value to this complex number using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@link BigDecimal} value to add
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex add(BigDecimal value, MathContext mathContext) {
return valueOf(
re.add(value, mathContext),
im);
}
/**
* Calculates the addition of the given real {@link BigDecimal} value to this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@link BigDecimal} value to add
* @return the calculated {@link BigComplex} result
*/
public BigComplex add(BigDecimal value) {
return valueOf(
re.add(value),
im);
}
/**
* Calculates the addition of the given real {@code double} value to this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@code double} value to add
* @return the calculated {@link BigComplex} result
*/
public BigComplex add(double value) {
return add(BigDecimal.valueOf(value));
}
/**
* Calculates the subtraction of the given complex value from this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@link BigComplex} value to subtract
* @return the calculated {@link BigComplex} result
*/
public BigComplex subtract(BigComplex value) {
return valueOf(
re.subtract(value.re),
im.subtract(value.im));
}
/**
* Calculates the subtraction of the given complex value from this complex number using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@link BigComplex} value to subtract
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex subtract(BigComplex value, MathContext mathContext) {
return valueOf(
re.subtract(value.re, mathContext),
im.subtract(value.im, mathContext));
}
/**
* Calculates the subtraction of the given real {@link BigDecimal} value from this complex number using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@link BigDecimal} value to add
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex subtract(BigDecimal value, MathContext mathContext) {
return valueOf(
re.subtract(value, mathContext),
im);
}
/**
* Calculates the subtraction of the given real {@link BigDecimal} value from this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@link BigDecimal} value to subtract
* @return the calculated {@link BigComplex} result
*/
public BigComplex subtract(BigDecimal value) {
return valueOf(
re.subtract(value),
im);
}
/**
* Calculates the subtraction of the given real {@code double} value from this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@code double} value to subtract
* @return the calculated {@link BigComplex} result
*/
public BigComplex subtract(double value) {
return subtract(BigDecimal.valueOf(value));
}
/**
* Calculates the multiplication of the given complex value to this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@link BigComplex} value to multiply
* @return the calculated {@link BigComplex} result
*/
public BigComplex multiply(BigComplex value) {
return valueOf(
re.multiply(value.re).subtract(im.multiply(value.im)),
re.multiply(value.im).add(im.multiply(value.re)));
}
/**
* Calculates the multiplication of the given complex value with this complex number using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@link BigComplex} value to multiply
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex multiply(BigComplex value, MathContext mathContext) {
return valueOf(
re.multiply(value.re, mathContext).subtract(im.multiply(value.im, mathContext), mathContext),
re.multiply(value.im, mathContext).add(im.multiply(value.re, mathContext), mathContext));
}
/**
* Calculates the multiplication of the given real {@link BigDecimal} value with this complex number using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@link BigDecimal} value to multiply
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex multiply(BigDecimal value, MathContext mathContext) {
return valueOf(
re.multiply(value, mathContext),
im.multiply(value, mathContext));
}
/**
* Calculates the multiplication of the given real {@link BigDecimal} value with this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@link BigDecimal} value to multiply
* @return the calculated {@link BigComplex} result
*/
public BigComplex multiply(BigDecimal value) {
return valueOf(
re.multiply(value),
im.multiply(value));
}
/**
* Calculates the multiplication of the given real {@code double} value with this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the real {@code double} value to multiply
* @return the calculated {@link BigComplex} result
*/
public BigComplex multiply(double value) {
return multiply(BigDecimal.valueOf(value));
}
/**
* Calculates this complex number divided by the given complex value using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@link BigComplex} value to divide by
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex divide(BigComplex value, MathContext mathContext) {
return multiply(value.reciprocal(mathContext), mathContext);
}
/**
* Calculates this complex number divided by the given real {@link BigDecimal} value using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@link BigDecimal} value to divide by
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex divide(BigDecimal value, MathContext mathContext) {
return valueOf(
re.divide(value, mathContext),
im.divide(value, mathContext));
}
/**
* Calculates this complex number divided by the given real {@code double} value using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param value the {@code double} value to divide by
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex divide(double value, MathContext mathContext) {
return divide(BigDecimal.valueOf(value), mathContext);
}
/**
* Calculates the reciprocal of this complex number using the specified {@link MathContext}.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigComplex reciprocal(MathContext mathContext) {
BigDecimal scale = absSquare(mathContext);
return valueOf(
re.divide(scale, mathContext),
im.negate().divide(scale, mathContext));
}
/**
* Calculates the conjugate {@code a - bi} of this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @return the calculated {@link BigComplex} result
*/
public BigComplex conjugate() {
return valueOf(re, im.negate());
}
/**
* Calculates the negation {@code -a - bi} of this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @return the calculated {@link BigComplex} result
*/
public BigComplex negate() {
return valueOf(re.negate(), im.negate());
}
/**
* Calculates the absolute value (also known as magnitude, length or radius) of this complex number.
*
* <p>This method is slower than {@link #absSquare(MathContext)} since it needs to calculate the {@link BigDecimalMath#sqrt(BigDecimal, MathContext)}.</p>
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
* @see #absSquare(MathContext)
*/
public BigDecimal abs(MathContext mathContext) {
return BigDecimalMath.sqrt(absSquare(mathContext), mathContext);
}
/**
* Calculates the angle in radians (also known as argument) of this complex number.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
*/
public BigDecimal angle(MathContext mathContext) {
return BigDecimalMath.atan2(im, re, mathContext);
}
/**
* Calculates the square of the absolute value of this complex number.
*
* <p>This method is faster than {@link #abs(MathContext)} since it does not need to calculate the {@link BigDecimalMath#sqrt(BigDecimal, MathContext)}.</p>
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
* @see #abs(MathContext)
*/
public BigDecimal absSquare(MathContext mathContext) {
return re.multiply(re, mathContext).add(im.multiply(im, mathContext), mathContext);
}
/**
* Returns whether this complex number only has a real part (the imaginary part is 0).
*
* @return {@code true} if this complex number only has a real part, {@code false} if the imaginary part is not 0
*/
public boolean isReal() {
return im.signum() == 0;
}
/**
* Returns the real part of this complex number as {@link BigComplex} number.
*
* @return the real part as as {@link BigComplex} number
*/
public BigComplex re() {
return valueOf(re, BigDecimal.ZERO);
}
/**
* Returns the imaginary part of this complex number as {@link BigComplex} number.
*
* @return the imaginary part as as {@link BigComplex} number
*/
public BigComplex im() {
return valueOf(BigDecimal.ZERO, im);
}
/**
* Returns this complex nuber rounded to the specified precision.
*
* <p>This methods <strong>does not</strong> modify this instance.</p>
*
* @param mathContext the {@link MathContext} used to calculate the result
* @return the rounded {@link BigComplex} result
*/
public BigComplex round(MathContext mathContext) {
return valueOf(re.round(mathContext), im.round(mathContext));
}
@Override
public int hashCode() {
return Objects.hash(re, im);
}
/**
* {@inheritDoc}
*
* <p>Contrary to {@link BigDecimal#equals(Object)} this method implements <strong>mathematical</strong> equality
* (by calling {@link BigDecimal#compareTo(BigDecimal)} on the real and imaginary parts)
* instead of strict equality.</p>
*
* @see #strictEquals(Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BigComplex other = (BigComplex) obj;
return re.compareTo(other.re) == 0 && im.compareTo(other.im) == 0;
}
/**
* Returns whether the real and imaginary parts of this complex number are strictly equal.
*
* <p>This method uses the strict equality as defined by {@link BigDecimal#equals(Object)} on the real and imaginary parts.</p>
* <p>Please note that {@link #equals(Object) BigComplex.equals(Object)} implements <strong>mathematical</strong> equality instead
* (by calling {@link BigDecimal#compareTo(BigDecimal) on the real and imaginary parts}).</p>
*
* @param obj the object to compare for strict equality
* @return {@code true} if the specified object is strictly equal to this complex number
* @see #equals(Object)
*/
public boolean strictEquals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BigComplex other = (BigComplex) obj;
return re.equals(other.re) && im.equals(other.im);
}
@Override
public String toString() {
if (im.signum() >= 0) {
return "(" + re + " + " + im + " i)";
} else {
return "(" + re + " - " + im.negate() + " i)";
}
}
/**
* Returns a complex number with the specified real {@link BigDecimal} part.
*
* @param real the real {@link BigDecimal} part
* @return the complex number
*/
public static BigComplex valueOf(BigDecimal real) {
return valueOf(real, BigDecimal.ZERO);
}
/**
* Returns a complex number with the specified real {@code double} part.
*
* @param real the real {@code double} part
* @return the complex number
*/
public static BigComplex valueOf(double real) {
return valueOf(BigDecimal.valueOf(real), BigDecimal.ZERO);
}
/**
* Returns a complex number with the specified real and imaginary {@code double} parts.
*
* @param real the real {@code double} part
* @param imaginary the imaginary {@code double} part
* @return the complex number
*/
public static BigComplex valueOf(double real, double imaginary) {
return valueOf(BigDecimal.valueOf(real), BigDecimal.valueOf(imaginary));
}
/**
* Returns a complex number with the specified real and imaginary {@link BigDecimal} parts.
*
* @param real the real {@link BigDecimal} part
* @param imaginary the imaginary {@link BigDecimal} part
* @return the complex number
*/
public static BigComplex valueOf(BigDecimal real, BigDecimal imaginary) {
if (real.signum() == 0) {
if (imaginary.signum() == 0) {
return ZERO;
}
if (imaginary.compareTo(BigDecimal.ONE) == 0) {
return I;
}
}
if (imaginary.signum() == 0 && real.compareTo(BigDecimal.ONE) == 0) {
return ONE;
}
return new BigComplex(real, imaginary);
}
/**
* Returns a complex number with the specified polar {@link BigDecimal} radius and angle using the specified {@link MathContext}.
*
* @param radius the {@link BigDecimal} radius of the polar representation
* @param angle the {@link BigDecimal} angle in radians of the polar representation
* @param mathContext the {@link MathContext} used to calculate the result
* @return the complex number
*/
public static BigComplex valueOfPolar(BigDecimal radius, BigDecimal angle, MathContext mathContext) {
if (radius.signum() == 0) {
return ZERO;
}
return valueOf(
radius.multiply(BigDecimalMath.cos(angle, mathContext), mathContext),
radius.multiply(BigDecimalMath.sin(angle, mathContext), mathContext));
}
public static BigComplex valueOfPolar(double radius, double angle, MathContext mathContext) {
return valueOfPolar(BigDecimal.valueOf(radius), BigDecimal.valueOf(angle), mathContext);
}
}
================================================
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigComplexMath.java
================================================
package ch.obermuhlner.math.big;
import static ch.obermuhlner.math.big.BigComplex.I;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.List;
/**
* Provides advanced functions operating on {@link BigComplex}s.
*/
public class BigComplexMath {
private static final BigDecimal TWO = BigDecimal.valueOf(2);
/**
* Calculates the reciprocal of the given complex number using the specified {@link MathContext}.
*
* @param x the complex number to calculate the reciprocal
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
* @see BigComplex#reciprocal(MathContext)
*/
public static BigComplex reciprocal(BigComplex x, MathContext mathContext) {
return x.reciprocal(mathContext);
}
/**
* Calculates the conjugate of the given complex number using the specified {@link MathContext}.
*
* @param x the complex number to calculate the conjugate
* @return the calculated {@link BigComplex} result
* @see BigComplex#conjugate()
*/
public static BigComplex conjugate(BigComplex x) {
return x.conjugate();
}
/**
* Calculates the absolute value (also known as magnitude, length or radius) of the given complex number using the specified {@link MathContext}.
*
* @param x the complex number to calculate the absolute value
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
* @see BigComplex#abs(MathContext)
*/
public static BigDecimal abs(BigComplex x, MathContext mathContext) {
return x.abs(mathContext);
}
/**
* Calculates the square of the absolute value (also known as magnitude, length or radius) of the given complex number using the specified {@link MathContext}.
*
* @param x the complex number to calculate the square of the absolute value
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} result
* @see BigComplex#absSquare(MathContext)
*/
public static BigDecimal absSquare(BigComplex x, MathContext mathContext) {
return x.absSquare(mathContext);
}
/**
* Calculates the angle in radians of the given complex number using the specified {@link MathContext}.
*
* @param x the complex number to calculate the angle
* @param mathContext the {@link MathContext} used to calculate the result
* @return the calculated {@link BigComplex} angle in radians
* @see BigComplex#angle(MathContext)
*/
public static BigDecimal angle(BigComplex x, MathContext mathContext) {
return x.angle(mathContext);
}
/**
* Calculates the factorial of the specified {@link BigComplex}.
*
* <p>This implementation uses
* <a href="https://en.wikipedia.org/wiki/Spouge%27s_approximation">Spouge's approximation</a>
* to calculate the factorial for non-integer values.</p>
*
* <p>This involves calculating a series of constants that depend on the desired precision.
* Since this constant calculation is quite expensive (especially for higher precisions),
* the constants for a specific precision will be cached
* and subsequent calls to this method with the same precision will be much faster.</p>
*
* <p>It is therefore recommended to do one call to this method with the standard precision of your application during the startup phase
* and to avoid calling it with many different precisions.</p>
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Factorial#Extension_of_factorial_to_non-integer_values_of_argument">Wikipedia: Factorial - Extension of factorial to non-integer values of argument</a></p>
*
* @param x the {@link BigComplex}
* @param mathContext the {@link MathContext} used for the result
* @return the factorial {@link BigComplex}
* @throws ArithmeticException if x is a negative integer value (-1, -2, -3, ...)
* @see BigDecimalMath#factorial(BigDecimal, MathContext)
* @see #gamma(BigComplex, MathContext)
*/
public static BigComplex factorial(BigComplex x, MathContext mathContext) {
if (x.isReal() && BigDecimalMath.isIntValue(x.re) && x.re.intValueExact() > 0) {
return BigComplex.valueOf(BigDecimalMath.factorial(x.re.intValueExact()).round(mathContext));
}
// https://en.wikipedia.org/wiki/Spouge%27s_approximation
MathContext mc = new MathContext(mathContext.getPrecision() * 2, mathContext.getRoundingMode());
int a = mathContext.getPrecision() * 13 / 10;
List<BigDecimal> constants = BigDecimalMath.getSpougeFactorialConstants(a);
BigDecimal bigA = BigDecimal.valueOf(a);
boolean negative = false;
BigComplex factor = BigComplex.valueOf(constants.get(0));
for (int k = 1; k < a; k++) {
BigDecimal bigK = BigDecimal.valueOf(k);
factor = factor.add(BigComplex.valueOf(constants.get(k)).divide(x.add(bigK), mc), mc);
negative = !negative;
}
BigComplex result = pow(x.add(bigA, mc), x.add(BigDecimal.valueOf(0.5), mc), mc);
result = result.multiply(exp(x.negate().subtract(bigA, mc), mc), mc);
result = result.multiply(factor, mc);
return result.round(mathContext);
}
/**
* Calculates the gamma function of the specified {@link BigComplex}.
*
* <p>This implementation uses {@link #factorial(BigComplex, MathContext)} internally,
* therefore the performance implications described there apply also for this method.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Gamma_function">Wikipedia: Gamma function</a></p>
*
* @param x the {@link BigComplex}
* @param mathContext the {@link MathContext} used for the result
* @return the gamma {@link BigComplex}
* @throws ArithmeticException if x-1 is a negative integer value (-1, -2, -3, ...)
* @see BigDecimalMath#gamma(BigDecimal, MathContext)
* @see #factorial(BigComplex, MathContext)
*/
public static BigComplex gamma(BigComplex x, MathContext mathContext) {
return factorial(x.subtract(BigComplex.ONE), mathContext);
}
/**
* Calculates the natural exponent of {@link BigComplex} x (e<sup>x</sup>) in the complex domain.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Exponential_function#Complex_plane">Wikipedia: Exponent (Complex plane)</a></p>
*
* @param x the {@link BigComplex} to calculate the exponent for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated exponent {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex exp(BigComplex x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal expRe = BigDecimalMath.exp(x.re, mc);
return BigComplex.valueOf(
expRe.multiply(BigDecimalMath.cos(x.im, mc), mc).round(mathContext),
expRe.multiply(BigDecimalMath.sin(x.im, mc), mc)).round(mathContext);
}
/**
* Calculates the sine (sinus) of {@link BigComplex} x in the complex domain.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Sine#Sine_with_a_complex_argument">Wikipedia: Sine (Sine with a complex argument)</a></p>
*
* @param x the {@link BigComplex} to calculate the sine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated sine {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex sin(BigComplex x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return BigComplex.valueOf(
BigDecimalMath.sin(x.re, mc).multiply(BigDecimalMath.cosh(x.im, mc), mc).round(mathContext),
BigDecimalMath.cos(x.re, mc).multiply(BigDecimalMath.sinh(x.im, mc), mc).round(mathContext));
}
/**
* Calculates the cosine (cosinus) of {@link BigComplex} x in the complex domain.
*
* @param x the {@link BigComplex} to calculate the cosine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated cosine {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex cos(BigComplex x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return BigComplex.valueOf(
BigDecimalMath.cos(x.re, mc).multiply(BigDecimalMath.cosh(x.im, mc), mc).round(mathContext),
BigDecimalMath.sin(x.re, mc).multiply(BigDecimalMath.sinh(x.im, mc), mc).negate().round(mathContext));
}
//
// http://scipp.ucsc.edu/~haber/archives/physics116A10/arc_10.pdf
/**
* Calculates the tangens of {@link BigComplex} x in the complex domain.
*
* @param x the {@link BigComplex} to calculate the tangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated tangens {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex tan(BigComplex x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return sin(x, mc).divide(cos(x, mc), mc).round(mathContext);
}
/**
* Calculates the arc tangens (inverted tangens) of {@link BigComplex} x in the complex domain.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Extension_to_complex_plane">Wikipedia: Inverse trigonometric functions (Extension to complex plane)</a></p>
*
* @param x the {@link BigComplex} to calculate the arc tangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc tangens {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex atan(BigComplex x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return log(I.subtract(x, mc).divide(I.add(x, mc), mc), mc).divide(I, mc).divide(TWO, mc).round(mathContext);
}
/**
* Calculates the arc cotangens (inverted cotangens) of {@link BigComplex} x in the complex domain.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Extension_to_complex_plane">Wikipedia: Inverse trigonometric functions (Extension to complex plane)</a></p>
*
* @param x the {@link BigComplex} to calculate the arc cotangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc cotangens {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex acot(BigComplex x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return log(x.add(I, mc).divide(x.subtract(I, mc), mc), mc).divide(I, mc).divide(TWO, mc).round(mathContext);
}
/**
* Calculates the arc sine (inverted sine) of {@link BigComplex} x in the complex domain.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Extension_to_complex_plane">Wikipedia: Inverse trigonometric functions (Extension to complex plane)</a></p>
*
* @param x the {@link BigComplex} to calculate the arc sine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc sine {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex asin(BigComplex x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return I.negate().multiply(log(I.multiply(x, mc).add(sqrt(BigComplex.ONE.subtract(x.multiply(x, mc), mc), mc), mc), mc), mc).round(mathContext);
}
/**
* Calculates the arc cosine (inverted cosine) of {@link BigComplex} x in the complex domain.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Extension_to_complex_plane">Wikipedia: Inverse trigonometric functions (Extension to complex plane)</a></p>
*
* @param x the {@link BigComplex} to calculate the arc cosine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc cosine {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex acos(BigComplex x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return I.negate().multiply(log(x.add(sqrt(x.multiply(x, mc).subtract(BigComplex.ONE, mc), mc), mc), mc), mc).round(mathContext);
}
/**
* Calculates the square root of {@link BigComplex} x in the complex domain (√x).
*
* <p>See <a href="https://en.wikipedia.org/wiki/Square_root#Square_root_of_an_imaginary_number">Wikipedia: Square root (Square root of an imaginary number)</a></p>
*
* @param x the {@link BigComplex} to calculate the square root for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated square root {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex sqrt(BigComplex x, MathContext mathContext) {
// https://math.stackexchange.com/questions/44406/how-do-i-get-the-square-root-of-a-complex-number
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal magnitude = x.abs(mc);
BigComplex a = x.add(magnitude, mc);
return a.divide(a.abs(mc), mc).multiply(BigDecimalMath.sqrt(magnitude, mc), mc).round(mathContext);
}
/**
* Calculates the natural logarithm of {@link BigComplex} x in the complex domain.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Complex_logarithm">Wikipedia: Complex logarithm</a></p>
*
* @param x the {@link BigComplex} to calculate the natural logarithm for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated natural logarithm {@link BigComplex} with the precision specified in the <code>mathContext</code>
*/
public static BigComplex log(BigComplex x, MathContext mathContext) {
// https://en.wikipedia.org/wiki/Complex_logarithm
MathContext mc1 = new MathContext(mathContext.getPrecision() + 20, mathContext.getRoundingMode());
MathContext mc2 = new MathContext(mathContext.getPrecision() + 5, mathContext.getRoundingMode());
return BigComplex.valueOf(
BigDecimalMath.log(x.abs(mc1), mc1).round(mathContext),
x.angle(mc2)).round(mathContext);
}
/**
* Calculates {@link BigComplex} x to the power of <code>long</code> y (x<sup>y</sup>).
*
* <p>The implementation tries to minimize the number of multiplications of {@link BigComplex x} (using squares whenever possible).</p>
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Exponentiation#Efficient_computation_with_integer_exponents">Wikipedia: Exponentiation - efficient computation</a></p>
*
* @param x the {@link BigComplex} value to take to the power
* @param y the <code>long</code> value to serve as exponent
* @param mathContext the {@link MathContext} used for the result
* @return the calculated x to the power of y with the precision specified in the <code>mathContext</code>
*/
public static BigComplex pow(BigComplex x, long y, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 10, mathContext.getRoundingMode());
if (y < 0) {
return BigComplex.ONE.divide(pow(x, -y, mc), mc).round(mathContext);
}
BigComplex result = BigComplex.ONE;
while (y > 0) {
if ((y & 1) == 1) {
// odd exponent -> multiply result with x
result = result.multiply(x, mc);
y -= 1;
}
if (y > 0) {
// even exponent -> square x
x = x.multiply(x, mc);
}
y >>= 1;
}
return result.round(mathContext);
}
/**
* Calculates {@link BigComplex} x to the power of {@link BigDecimal} y (x<sup>y</sup>).
*
* @param x the {@link BigComplex} value to take to the power
* @param y the {@link BigDecimal} value to serve as exponent
* @param mathContext the {@link MathContext} used for the result
* @return the calculated x to the power of y with the precision specified in the <code>mathContext</code>
*/
public static BigComplex pow(BigComplex x, BigDecimal y, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal angleTimesN = x.angle(mc).multiply(y, mc);
return BigComplex.valueOf(
BigDecimalMath.cos(angleTimesN, mc),
BigDecimalMath.sin(angleTimesN, mc)).multiply(BigDecimalMath.pow(x.abs(mc), y, mc), mc).round(mathContext);
}
/**
* Calculates {@link BigComplex} x to the power of {@link BigComplex} y (x<sup>y</sup>).
*
* @param x the {@link BigComplex} value to take to the power
* @param y the {@link BigComplex} value to serve as exponent
* @param mathContext the {@link MathContext} used for the result
* @return the calculated x to the power of y with the precision specified in the <code>mathContext</code>
*/
public static BigComplex pow(BigComplex x, BigComplex y, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return exp(y.multiply(log(x, mc), mc), mc).round(mathContext);
}
/**
* Calculates the {@link BigDecimal} n'th root of {@link BigComplex} x (<sup>n</sup>√x).
*
* <p>See <a href="http://en.wikipedia.org/wiki/Square_root">Wikipedia: Square root</a></p>
* @param x the {@link BigComplex} value to calculate the n'th root
* @param n the {@link BigDecimal} defining the root
* @param mathContext the {@link MathContext} used for the result
*
* @return the calculated n'th root of x with the precision specified in the <code>mathContext</code>
*/
public static BigComplex root(BigComplex x, BigDecimal n, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return pow(x, BigDecimal.ONE.divide(n, mc), mc).round(mathContext);
}
/**
* Calculates the {@link BigComplex} n'th root of {@link BigComplex} x (<sup>n</sup>√x).
*
* <p>See <a href="http://en.wikipedia.org/wiki/Square_root">Wikipedia: Square root</a></p>
* @param x the {@link BigComplex} value to calculate the n'th root
* @param n the {@link BigComplex} defining the root
* @param mathContext the {@link MathContext} used for the result
*
* @return the calculated n'th root of x with the precision specified in the <code>mathContext</code>
*/
public static BigComplex root(BigComplex x, BigComplex n, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
return pow(x, BigComplex.ONE.divide(n, mc), mc).round(mathContext);
}
// TODO add root() for the k'th root - https://math.stackexchange.com/questions/322481/principal-nth-root-of-a-complex-number
}
================================================
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigDecimalMath.java
================================================
package ch.obermuhlner.math.big;
import static java.math.BigDecimal.ONE;
import static java.math.BigDecimal.TEN;
import static java.math.BigDecimal.ZERO;
import static java.math.BigDecimal.valueOf;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.*;
import ch.obermuhlner.math.big.internal.AsinCalculator;
import ch.obermuhlner.math.big.internal.CosCalculator;
import ch.obermuhlner.math.big.internal.CoshCalculator;
import ch.obermuhlner.math.big.internal.ExpCalculator;
import ch.obermuhlner.math.big.internal.SinCalculator;
import ch.obermuhlner.math.big.internal.SinhCalculator;
/**
* Provides advanced functions operating on {@link BigDecimal}s.
*/
public class BigDecimalMath {
private static final BigDecimal TWO = valueOf(2);
private static final BigDecimal THREE = valueOf(3);
private static final BigDecimal MINUS_ONE = valueOf(-1);
private static final BigDecimal ONE_HALF = valueOf(0.5);
private static final BigDecimal ONE_HUNDRED_EIGHTY = valueOf(180);
private static final BigDecimal DOUBLE_MAX_VALUE = BigDecimal.valueOf(Double.MAX_VALUE);
private static volatile BigDecimal log2Cache;
private static final Object log2CacheLock = new Object();
private static volatile BigDecimal log3Cache;
private static final Object log3CacheLock = new Object();
private static volatile BigDecimal log10Cache;
private static final Object log10CacheLock = new Object();
private static volatile BigDecimal piCache;
private static final Object piCacheLock = new Object();
private static volatile BigDecimal eCache;
private static final Object eCacheLock = new Object();
private static final BigDecimal ROUGHLY_TWO_PI = new BigDecimal("3.141592653589793").multiply(TWO);
private static final int EXPECTED_INITIAL_PRECISION = 15;
private static BigDecimal[] factorialCache = new BigDecimal[100];
static {
BigDecimal result = ONE;
factorialCache[0] = result;
for (int i = 1; i < factorialCache.length; i++) {
result = result.multiply(valueOf(i));
factorialCache[i] = result;
}
}
private static final Map<Integer, List<BigDecimal>> spougeFactorialConstantsCache = new HashMap<>();
private static final Object spougeFactorialConstantsCacheLock = new Object();
private BigDecimalMath() {
// prevent instances
}
/**
* Creates a {@link BigDecimal} from the specified <code>String</code> representation.
*
* <p>This method is equivalent to the String constructor {@link BigDecimal#BigDecimal(String)}
* but has been optimized for large strings (several thousand digits).</p>
*
* @param string the String representation
* @return the created {@link BigDecimal}
* @throws NumberFormatException if <code>string</code> is not a valid representation of a {@link BigDecimal}
* @see BigDecimal#BigDecimal(String)
* @see #toBigDecimal(String, MathContext)
*/
public static BigDecimal toBigDecimal(String string) {
return toBigDecimal(string, MathContext.UNLIMITED);
}
/**
* Creates a {@link BigDecimal} from the specified <code>String</code> representation.
*
* <p>This method is equivalent to the String constructor {@link BigDecimal#BigDecimal(String, MathContext)}
* but has been optimized for large strings (several thousand digits).</p>
*
* @param string the string representation
* @param mathContext the {@link MathContext} used for the result
* @return the created {@link BigDecimal}
* @throws NumberFormatException if <code>string</code> is not a valid representation of a {@link BigDecimal}
* @throws ArithmeticException if the result is inexact but the rounding mode is {@code UNNECESSARY}
* @see BigDecimal#BigDecimal(String, MathContext)
* @see #toBigDecimal(String)
*/
public static BigDecimal toBigDecimal(String string, MathContext mathContext) {
int len = string.length();
if (len < 600) {
return new BigDecimal(string, mathContext);
}
int splitLength = len / (len >= 10000 ? 8 : 5);
return toBigDecimal(string, mathContext, splitLength);
}
static BigDecimal toBigDecimal(String string, MathContext mathContext, int splitLength) {
int len = string.length();
if (len < splitLength) {
return new BigDecimal(string, mathContext);
}
char[] chars = string.toCharArray();
boolean numberHasSign = false;
boolean negative = false;
int numberIndex = 0;
int dotIndex = -1;
int expIndex = -1;
boolean expHasSign = false;
int scale = 0;
for (int i = 0; i < len; i++) {
char c = chars[i];
switch (c) {
case '+':
if (expIndex >= 0) {
if (expHasSign) {
throw new NumberFormatException("Multiple signs in exponent");
}
expHasSign = true;
} else {
if (numberHasSign) {
throw new NumberFormatException("Multiple signs in number");
}
numberHasSign = true;
numberIndex = i + 1;
}
break;
case '-':
if (expIndex >= 0) {
if (expHasSign) {
throw new NumberFormatException("Multiple signs in exponent");
}
expHasSign = true;
} else {
if (numberHasSign) {
throw new NumberFormatException("Multiple signs in number");
}
numberHasSign = true;
negative = true;
numberIndex = i + 1;
}
break;
case 'e':
case 'E':
if (expIndex >= 0) {
throw new NumberFormatException("Multiple exponent markers");
}
expIndex = i;
break;
case '.':
if (dotIndex >= 0) {
throw new NumberFormatException("Multiple decimal points");
}
dotIndex = i;
break;
default:
if (dotIndex >= 0 && expIndex == -1) {
scale++;
}
}
}
int numberEndIndex;
int exp = 0;
if (expIndex >= 0) {
numberEndIndex = expIndex;
String expString = new String(chars, expIndex + 1, len - expIndex - 1);
exp = Integer.parseInt(expString);
scale = adjustScale(scale, exp);
} else {
numberEndIndex = len;
}
BigDecimal result;
if (dotIndex >= 0) {
int leftLength = dotIndex - numberIndex;
BigDecimal bigDecimalLeft = toBigDecimalRecursive(chars, numberIndex, leftLength, exp, splitLength);
int rightLength = numberEndIndex - dotIndex - 1;
BigDecimal bigDecimalRight = toBigDecimalRecursive(chars, dotIndex + 1, rightLength, exp-rightLength, splitLength);
result = bigDecimalLeft.add(bigDecimalRight);
} else {
result = toBigDecimalRecursive(chars, numberIndex, numberEndIndex - numberIndex, exp, splitLength);
}
if (scale != 0) {
result = result.setScale(scale);
}
if (negative) {
result = result.negate();
}
if (mathContext.getPrecision() != 0) {
result = result.round(mathContext);
}
return result;
}
private static int adjustScale(int scale, long exp) {
long adjustedScale = scale - exp;
if (adjustedScale > Integer.MAX_VALUE || adjustedScale < Integer.MIN_VALUE)
throw new NumberFormatException("Scale out of range: " + adjustedScale + " while adjusting scale " + scale + " to exponent " + exp);
return (int) adjustedScale;
}
private static BigDecimal toBigDecimalRecursive(char[] chars, int offset, int length, int scale, int splitLength) {
if (length > splitLength) {
int mid = length / 2;
BigDecimal bigDecimalLeft = toBigDecimalRecursive(chars, offset, mid, scale + length - mid, splitLength);
BigDecimal bigDecimalRight = toBigDecimalRecursive(chars, offset + mid, length - mid, scale, splitLength);
return bigDecimalLeft.add(bigDecimalRight);
}
if (length == 0) {
return BigDecimal.ZERO;
}
return new BigDecimal(chars, offset, length).movePointRight(scale);
}
/**
* Returns whether the specified {@link BigDecimal} value can be represented as <code>int</code>.
*
* <p>If this returns <code>true</code> you can call {@link BigDecimal#intValueExact()} without fear of an {@link ArithmeticException}.</p>
*
* @param value the {@link BigDecimal} to check
* @return <code>true</code> if the value can be represented as <code>int</code> value
*/
public static boolean isIntValue(BigDecimal value) {
// TODO impl isIntValue() without exceptions
try {
value.intValueExact();
return true;
} catch (ArithmeticException ex) {
// ignored
}
return false;
}
/**
* Returns whether the specified {@link BigDecimal} value can be represented as <code>long</code>.
*
* <p>If this returns <code>true</code> you can call {@link BigDecimal#longValueExact()} without fear of an {@link ArithmeticException}.</p>
*
* @param value the {@link BigDecimal} to check
* @return <code>true</code> if the value can be represented as <code>long</code> value
*/
public static boolean isLongValue(BigDecimal value) {
// TODO impl isLongValue() without exceptions
try {
value.longValueExact();
return true;
} catch (ArithmeticException ex) {
// ignored
}
return false;
}
/**
* Returns whether the specified {@link BigDecimal} value can be represented as <code>double</code>.
*
* <p>If this returns <code>true</code> you can call {@link BigDecimal#doubleValue()}
* without fear of getting {@link Double#POSITIVE_INFINITY} or {@link Double#NEGATIVE_INFINITY} as result.</p>
*
* <p>Example: <code>BigDecimalMath.isDoubleValue(new BigDecimal("1E309"))</code> returns <code>false</code>,
* because <code>new BigDecimal("1E309").doubleValue()</code> returns <code>Infinity</code>.</p>
*
* <p>Note: This method does <strong>not</strong> check for possible loss of precision.</p>
*
* <p>For example <code>BigDecimalMath.isDoubleValue(new BigDecimal("1.23400000000000000000000000000000001"))</code> will return <code>true</code>,
* because <code>new BigDecimal("1.23400000000000000000000000000000001").doubleValue()</code> returns a valid double value,
* although it loses precision and returns <code>1.234</code>.</p>
*
* <p><code>BigDecimalMath.isDoubleValue(new BigDecimal("1E-325"))</code> will return <code>true</code>
* although this value is smaller than {@link Double#MIN_VALUE} (and therefore outside the range of values that can be represented as <code>double</code>)
* because <code>new BigDecimal("1E-325").doubleValue()</code> returns <code>0</code> which is a legal value with loss of precision.</p>
*
* @param value the {@link BigDecimal} to check
* @return <code>true</code> if the value can be represented as <code>double</code> value
*/
public static boolean isDoubleValue(BigDecimal value) {
if (value.compareTo(DOUBLE_MAX_VALUE) > 0) {
return false;
}
if (value.compareTo(DOUBLE_MAX_VALUE.negate()) < 0) {
return false;
}
return true;
}
/**
* Returns the mantissa of the specified {@link BigDecimal} written as <em>mantissa * 10<sup>exponent</sup></em>.
*
* <p>The mantissa is defined as having exactly 1 digit before the decimal point.</p>
*
* @param value the {@link BigDecimal}
* @return the mantissa
* @see #exponent(BigDecimal)
*/
public static BigDecimal mantissa(BigDecimal value) {
int exponent = exponent(value);
if (exponent == 0) {
return value;
}
return value.movePointLeft(exponent);
}
/**
* Returns the exponent of the specified {@link BigDecimal} written as <em>mantissa * 10<sup>exponent</sup></em>.
*
* <p>The mantissa is defined as having exactly 1 digit before the decimal point.</p>
*
* @param value the {@link BigDecimal}
* @return the exponent
* @see #mantissa(BigDecimal)
*/
public static int exponent(BigDecimal value) {
return value.precision() - value.scale() - 1;
}
/**
* Returns the number of significant digits of the specified {@link BigDecimal}.
*
* <p>The result contains the number of all digits before the decimal point and
* all digits after the decimal point excluding trailing zeroes.</p>
*
* <p>Examples:</p>
* <ul>
* <li><code>significantDigits(new BigDecimal("12300.00"))</code> returns 5</li>
* <li><code>significantDigits(new BigDecimal("1.23000"))</code> returns 3</li>
* <li><code>significantDigits(new BigDecimal("0.00012300"))</code> returns 3</li>
* <li><code>significantDigits(new BigDecimal("12300.4500"))</code> returns 7</li>
* </ul>
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Significant_figures">Wikipedia: Significant figures</a></p>
*
* @param value the {@link BigDecimal}
* @return the number of significant digits
* @see BigDecimal#stripTrailingZeros()
* @see BigDecimal#precision()
*/
public static int significantDigits(BigDecimal value) {
BigDecimal stripped = value.stripTrailingZeros();
if (stripped.scale() >= 0) {
return stripped.precision();
} else {
return stripped.precision() - stripped.scale();
}
}
/**
* Returns the integral part of the specified {@link BigDecimal} (left of the decimal point).
*
* @param value the {@link BigDecimal}
* @return the integral part
* @see #fractionalPart(BigDecimal)
*/
public static BigDecimal integralPart(BigDecimal value) {
return value.setScale(0, BigDecimal.ROUND_DOWN);
}
/**
* Returns the fractional part of the specified {@link BigDecimal} (right of the decimal point).
*
* @param value the {@link BigDecimal}
* @return the fractional part
* @see #integralPart(BigDecimal)
*/
public static BigDecimal fractionalPart(BigDecimal value) {
return value.subtract(integralPart(value));
}
/**
* Rounds the specified {@link BigDecimal} to the precision of the specified {@link MathContext}.
*
* <p>This method calls {@link BigDecimal#round(MathContext)}.</p>
*
* @param value the {@link BigDecimal} to round
* @param mathContext the {@link MathContext} used for the result
* @return the rounded {@link BigDecimal} value
* @see BigDecimal#round(MathContext)
* @see BigDecimalMath#roundWithTrailingZeroes(BigDecimal, MathContext)
*/
public static BigDecimal round(BigDecimal value, MathContext mathContext) {
return value.round(mathContext);
}
/**
* Rounds the specified {@link BigDecimal} to the precision of the specified {@link MathContext} including trailing zeroes.
*
* <p>This method is similar to {@link BigDecimal#round(MathContext)} but does <strong>not</strong> remove the trailing zeroes.</p>
*
* <p>Example:</p>
<pre>
MathContext mc = new MathContext(5);
System.out.println(BigDecimalMath.roundWithTrailingZeroes(new BigDecimal("1.234567"), mc)); // 1.2346
System.out.println(BigDecimalMath.roundWithTrailingZeroes(new BigDecimal("123.4567"), mc)); // 123.46
System.out.println(BigDecimalMath.roundWithTrailingZeroes(new BigDecimal("0.001234567"), mc)); // 0.0012346
System.out.println(BigDecimalMath.roundWithTrailingZeroes(new BigDecimal("1.23"), mc)); // 1.2300
System.out.println(BigDecimalMath.roundWithTrailingZeroes(new BigDecimal("1.230000"), mc)); // 1.2300
System.out.println(BigDecimalMath.roundWithTrailingZeroes(new BigDecimal("0.00123"), mc)); // 0.0012300
System.out.println(BigDecimalMath.roundWithTrailingZeroes(new BigDecimal("0"), mc)); // 0.0000
System.out.println(BigDecimalMath.roundWithTrailingZeroes(new BigDecimal("0.00000000"), mc)); // 0.0000
</pre>
*
* @param value the {@link BigDecimal} to round
* @param mathContext the {@link MathContext} used for the result
* @return the rounded {@link BigDecimal} value including trailing zeroes
* @see BigDecimal#round(MathContext)
* @see BigDecimalMath#round(BigDecimal, MathContext)
*/
public static BigDecimal roundWithTrailingZeroes(BigDecimal value, MathContext mathContext) {
if (value.precision() == mathContext.getPrecision()) {
return value;
}
if (value.signum() == 0) {
return BigDecimal.ZERO.setScale(mathContext.getPrecision() - 1);
}
try {
BigDecimal stripped = value.stripTrailingZeros();
int exponentStripped = exponent(stripped); // value.precision() - value.scale() - 1;
BigDecimal zero;
if (exponentStripped < -1) {
zero = BigDecimal.ZERO.setScale(mathContext.getPrecision() - exponentStripped);
} else {
zero = BigDecimal.ZERO.setScale(mathContext.getPrecision() + exponentStripped + 1);
}
return stripped.add(zero, mathContext);
} catch (ArithmeticException ex) {
return value.round(mathContext);
}
}
/**
* Calculates the reciprocal of the specified {@link BigDecimal}.
*
* @param x the {@link BigDecimal}
* @param mathContext the {@link MathContext} used for the result
* @return the reciprocal {@link BigDecimal}
* @throws ArithmeticException if x = 0
* @throws ArithmeticException if the result is inexact but the
* rounding mode is {@code UNNECESSARY} or
* {@code mc.precision == 0} and the quotient has a
* non-terminating decimal expansion.
*/
public static BigDecimal reciprocal(BigDecimal x, MathContext mathContext) {
return BigDecimal.ONE.divide(x, mathContext);
}
/**
* Calculates the factorial of the specified integer argument.
*
* <p>factorial = 1 * 2 * 3 * ... n</p>
*
* @param n the {@link BigDecimal}
* @return the factorial {@link BigDecimal}
* @throws ArithmeticException if x < 0
*/
public static BigDecimal factorial(int n) {
if (n < 0) {
throw new ArithmeticException("Illegal factorial(n) for n < 0: n = " + n);
}
if (n < factorialCache.length) {
return factorialCache[n];
}
BigDecimal result = factorialCache[factorialCache.length - 1];
return result.multiply(factorialRecursion(factorialCache.length, n));
}
private static BigDecimal factorialLoop(int n1, final int n2) {
final long limit = Long.MAX_VALUE / n2;
long accu = 1;
BigDecimal result = BigDecimal.ONE;
while (n1 <= n2) {
if (accu <= limit) {
accu *= n1;
} else {
result = result.multiply(BigDecimal.valueOf(accu));
accu = n1;
}
n1++;
}
return result.multiply(BigDecimal.valueOf(accu));
}
private static BigDecimal factorialRecursion(final int n1, final int n2) {
int threshold = n1 > 200 ? 80 : 150;
if (n2 - n1 < threshold) {
return factorialLoop(n1, n2);
}
final int mid = (n1 + n2) >> 1;
return factorialRecursion(mid + 1, n2).multiply(factorialRecursion(n1, mid));
}
/**
* Calculates the factorial of the specified {@link BigDecimal}.
*
* <p>This implementation uses
* <a href="https://en.wikipedia.org/wiki/Spouge%27s_approximation">Spouge's approximation</a>
* to calculate the factorial for non-integer values.</p>
*
* <p>This involves calculating a series of constants that depend on the desired precision.
* Since this constant calculation is quite expensive (especially for higher precisions),
* the constants for a specific precision will be cached
* and subsequent calls to this method with the same precision will be much faster.</p>
*
* <p>It is therefore recommended to do one call to this method with the standard precision of your application during the startup phase
* and to avoid calling it with many different precisions.</p>
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Factorial#Extension_of_factorial_to_non-integer_values_of_argument">Wikipedia: Factorial - Extension of factorial to non-integer values of argument</a></p>
*
* @param x the {@link BigDecimal}
* @param mathContext the {@link MathContext} used for the result
* @return the factorial {@link BigDecimal}
* @throws ArithmeticException if x is a negative integer value (-1, -2, -3, ...)
* @throws UnsupportedOperationException if x is a non-integer value and the {@link MathContext} has unlimited precision
* @see #factorial(int)
* @see #gamma(BigDecimal, MathContext)
*/
public static BigDecimal factorial(BigDecimal x, MathContext mathContext) {
if (isIntValue(x)) {
return round(factorial(x.intValueExact()), mathContext);
}
// https://en.wikipedia.org/wiki/Spouge%27s_approximation
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() << 1, mathContext.getRoundingMode());
int a = mathContext.getPrecision() * 13 / 10;
List<BigDecimal> constants = getSpougeFactorialConstants(a);
BigDecimal bigA = BigDecimal.valueOf(a);
boolean negative = false;
BigDecimal factor = constants.get(0);
for (int k = 1; k < a; k++) {
BigDecimal bigK = BigDecimal.valueOf(k);
factor = factor.add(constants.get(k).divide(x.add(bigK), mc));
negative = !negative;
}
BigDecimal result = pow(x.add(bigA), x.add(BigDecimal.valueOf(0.5)), mc);
result = result.multiply(exp(x.negate().subtract(bigA), mc));
result = result.multiply(factor);
return round(result, mathContext);
}
static List<BigDecimal> getSpougeFactorialConstants(int a) {
synchronized (spougeFactorialConstantsCacheLock) {
return spougeFactorialConstantsCache.computeIfAbsent(a, key -> {
List<BigDecimal> constants = new ArrayList<>(a);
MathContext mc = new MathContext(a * 15 / 10);
BigDecimal c0 = sqrt(pi(mc).multiply(TWO, mc), mc);
constants.add(c0);
boolean negative = false;
for (int k = 1; k < a; k++) {
BigDecimal bigK = BigDecimal.valueOf(k);
long deltaAK = (long)a - k;
BigDecimal ck = pow(BigDecimal.valueOf(deltaAK), bigK.subtract(ONE_HALF), mc);
ck = ck.multiply(exp(BigDecimal.valueOf(deltaAK), mc), mc);
ck = ck.divide(factorial(k - 1), mc);
if (negative) {
ck = ck.negate();
}
constants.add(ck);
negative = !negative;
}
return Collections.unmodifiableList(constants);
});
}
}
/**
* Calculates the gamma function of the specified {@link BigDecimal}.
*
* <p>This implementation uses {@link #factorial(BigDecimal, MathContext)} internally,
* therefore the performance implications described there apply also for this method.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Gamma_function">Wikipedia: Gamma function</a></p>
*
* @param x the {@link BigDecimal}
* @param mathContext the {@link MathContext} used for the result
* @return the gamma {@link BigDecimal}
* @throws ArithmeticException if x-1 is a negative integer value (-1, -2, -3, ...)
* @throws UnsupportedOperationException if x is a non-integer value and the {@link MathContext} has unlimited precision
* @see #factorial(BigDecimal, MathContext)
*/
public static BigDecimal gamma(BigDecimal x, MathContext mathContext) {
return factorial(x.subtract(ONE), mathContext);
}
/**
* Calculates the Bernoulli number for the specified index.
*
* <p>This function calculates the <strong>first Bernoulli numbers</strong> and therefore <code>bernoulli(1)</code> returns -0.5</p>
* <p>Note that <code>bernoulli(x)</code> for all odd x > 1 returns 0</p>
* <p>See: <a href="https://en.wikipedia.org/wiki/Bernoulli_number">Wikipedia: Bernoulli number</a></p>
*
* @param n the index of the Bernoulli number to be calculated (starting at 0)
* @param mathContext the {@link MathContext} used for the result
* @return the Bernoulli number for the specified index
* @throws ArithmeticException if x < 0
* @throws ArithmeticException if the result is inexact but the
* rounding mode is {@code UNNECESSARY} or
* {@code mc.precision == 0} and the quotient has a
* non-terminating decimal expansion.
*/
public static BigDecimal bernoulli(int n, MathContext mathContext) {
if (n < 0) {
throw new ArithmeticException("Illegal bernoulli(n) for n < 0: n = " + n);
}
BigRational b = BigRational.bernoulli(n);
return b.toBigDecimal(mathContext);
}
/**
* Calculates {@link BigDecimal} x to the power of {@link BigDecimal} y (x<sup>y</sup>).
*
* @param x the {@link BigDecimal} value to take to the power
* @param y the {@link BigDecimal} value to serve as exponent
* @param mathContext the {@link MathContext} used for the result
* @return the calculated x to the power of y with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
* @see #pow(BigDecimal, long, MathContext)
*/
public static BigDecimal pow(BigDecimal x, BigDecimal y, MathContext mathContext) {
checkMathContext(mathContext);
if (x.signum() == 0) {
switch (y.signum()) {
case 0 : return round(ONE, mathContext);
case 1 : return round(ZERO, mathContext);
}
}
// TODO optimize y=0, y=1, y=10^k, y=-1, y=-10^k
try {
long longValue = y.longValueExact();
return pow(x, longValue, mathContext);
} catch (ArithmeticException ex) {
// ignored
}
if (fractionalPart(y).signum() == 0) {
return powInteger(x, y, mathContext);
}
// x^y = exp(y*log(x))
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = exp(y.multiply(log(x, mc), mc), mc);
return round(result, mathContext);
}
/**
* Calculates {@link BigDecimal} x to the power of <code>long</code> y (x<sup>y</sup>).
*
* <p>The implementation tries to minimize the number of multiplications of {@link BigDecimal x} (using squares whenever possible).</p>
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Exponentiation#Efficient_computation_with_integer_exponents">Wikipedia: Exponentiation - efficient computation</a></p>
*
* @param x the {@link BigDecimal} value to take to the power
* @param y the <code>long</code> value to serve as exponent
* @param mathContext the {@link MathContext} used for the result
* @return the calculated x to the power of y with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if y is negative and the result is inexact but the
* rounding mode is {@code UNNECESSARY} or
* {@code mc.precision == 0} and the quotient has a
* non-terminating decimal expansion.
* @throws ArithmeticException if the rounding mode is
* {@code UNNECESSARY} and the
* {@code BigDecimal} operation would require rounding.
*/
public static BigDecimal pow(BigDecimal x, long y, MathContext mathContext) {
MathContext mc = mathContext.getPrecision() == 0 ? mathContext : new MathContext(mathContext.getPrecision() + 10, mathContext.getRoundingMode());
// TODO optimize y=0, y=1, y=10^k, y=-1, y=-10^k
if (y < 0) {
BigDecimal value = reciprocal(pow(x, -y, mc), mc);
return round(value, mathContext);
}
BigDecimal result = ONE;
while (y > 0) {
if ((y & 1) == 1) {
// odd exponent -> multiply result with x
result = result.multiply(x, mc);
y -= 1;
}
if (y > 0) {
// even exponent -> square x
x = x.multiply(x, mc);
}
y >>= 1;
}
return round(result, mathContext);
}
/**
* Calculates {@link BigDecimal} x to the power of the integer value y (x<sup>y</sup>).
*
* <p>The value y MUST be an integer value.</p>
*
* @param x the {@link BigDecimal} value to take to the power
* @param integerY the {@link BigDecimal} <strong>integer</strong> value to serve as exponent
* @param mathContext the {@link MathContext} used for the result
* @return the calculated x to the power of y with the precision specified in the <code>mathContext</code>
* @see #pow(BigDecimal, long, MathContext)
*/
private static BigDecimal powInteger(BigDecimal x, BigDecimal integerY, MathContext mathContext) {
if (fractionalPart(integerY).signum() != 0) {
throw new IllegalArgumentException("Not integer value: " + integerY);
}
if (integerY.signum() < 0) {
return ONE.divide(powInteger(x, integerY.negate(), mathContext), mathContext);
}
MathContext mc = new MathContext(Math.max(mathContext.getPrecision(), -integerY.scale()) + 30, mathContext.getRoundingMode());
BigDecimal result = ONE;
while (integerY.signum() > 0) {
BigDecimal halfY = integerY.divide(TWO, mc);
if (fractionalPart(halfY).signum() != 0) {
// odd exponent -> multiply result with x
result = result.multiply(x, mc);
integerY = integerY.subtract(ONE);
halfY = integerY.divide(TWO, mc);
}
if (halfY.signum() > 0) {
// even exponent -> square x
x = x.multiply(x, mc);
}
integerY = halfY;
}
return round(result, mathContext);
}
/**
* Calculates the square root of {@link BigDecimal} x.
*
* <p>See <a href="http://en.wikipedia.org/wiki/Square_root">Wikipedia: Square root</a></p>
*
* @param x the {@link BigDecimal} value to calculate the square root
* @param mathContext the {@link MathContext} used for the result
* @return the calculated square root of x with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if x < 0
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal sqrt(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
switch (x.signum()) {
case 0:
return ZERO;
case -1:
throw new ArithmeticException("Illegal sqrt(x) for x < 0: x = " + x);
}
int maxPrecision = mathContext.getPrecision() + 6;
BigDecimal acceptableError = ONE.movePointLeft(mathContext.getPrecision() + 1);
BigDecimal result;
int adaptivePrecision;
if (isDoubleValue(x)) {
result = BigDecimal.valueOf(Math.sqrt(x.doubleValue()));
adaptivePrecision = EXPECTED_INITIAL_PRECISION;
} else {
result = x.multiply(ONE_HALF, mathContext);
adaptivePrecision = 1;
}
BigDecimal last;
if (adaptivePrecision < maxPrecision) {
if (result.multiply(result).compareTo(x) == 0) {
return round(result, mathContext); // early exit if x is a square number
}
do {
last = result;
adaptivePrecision <<= 1;
if (adaptivePrecision > maxPrecision) {
adaptivePrecision = maxPrecision;
}
MathContext mc = new MathContext(adaptivePrecision, mathContext.getRoundingMode());
result = x.divide(result, mc).add(last).multiply(ONE_HALF, mc);
}
while (adaptivePrecision < maxPrecision || result.subtract(last).abs().compareTo(acceptableError) > 0);
}
return round(result, mathContext);
}
/**
* Calculates the n'th root of {@link BigDecimal} x.
*
* <p>See <a href="https://en.wikipedia.org/wiki/Nth_root">Wikipedia: Nth root</a></p>
* @param x the {@link BigDecimal} value to calculate the n'th root
* @param n the {@link BigDecimal} defining the root
* @param mathContext the {@link MathContext} used for the result
*
* @return the calculated n'th root of x with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if n <= 0
* @throws ArithmeticException if x < 0
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal root(BigDecimal x, BigDecimal n, MathContext mathContext) {
checkMathContext(mathContext);
switch (n.signum()) {
case -1:
case 0:
throw new ArithmeticException("Illegal root(x, n) for n <= 0: n = " + n);
}
switch (x.signum()) {
case 0:
return ZERO;
case -1:
throw new ArithmeticException("Illegal root(x, n) for x < 0: x = " + x);
}
if (isDoubleValue(x) && isDoubleValue(n)) {
double initialResult = Math.pow(x.doubleValue(), 1.0 / n.doubleValue());
if (Double.isFinite(initialResult)) {
return rootUsingNewtonRaphson(x, n, BigDecimal.valueOf(initialResult), mathContext);
}
}
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
return pow(x, BigDecimal.ONE.divide(n, mc), mathContext);
}
private static BigDecimal rootUsingNewtonRaphson(BigDecimal x, BigDecimal n, BigDecimal initialResult, MathContext mathContext) {
if (n.compareTo(BigDecimal.ONE) <= 0) {
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
return pow(x, BigDecimal.ONE.divide(n, mc), mathContext);
}
int maxPrecision = mathContext.getPrecision() * 2;
BigDecimal acceptableError = ONE.movePointLeft(mathContext.getPrecision() + 1);
BigDecimal nMinus1 = n.subtract(ONE);
BigDecimal result = initialResult;
int adaptivePrecision = 12;
if (adaptivePrecision < maxPrecision) {
BigDecimal step;
do {
adaptivePrecision *= 3;
if (adaptivePrecision > maxPrecision) {
adaptivePrecision = maxPrecision;
}
MathContext mc = new MathContext(adaptivePrecision, mathContext.getRoundingMode());
step = x.divide(pow(result, nMinus1, mc), mc).subtract(result).divide(n, mc);
result = result.add(step);
} while (adaptivePrecision < maxPrecision || step.abs().compareTo(acceptableError) > 0);
}
return round(result, mathContext);
}
/**
* Calculates the natural logarithm of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Natural_logarithm">Wikipedia: Natural logarithm</a></p>
*
* @param x the {@link BigDecimal} to calculate the natural logarithm for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated natural logarithm {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if x <= 0
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal log(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
if (x.signum() <= 0) {
throw new ArithmeticException("Illegal log(x) for x <= 0: x = " + x);
}
if (x.compareTo(ONE) == 0) {
return ZERO;
}
BigDecimal result;
switch (x.compareTo(TEN)) {
case 0:
result = logTen(mathContext);
break;
case 1:
result = logUsingExponent(x, mathContext);
break;
default :
result = logUsingTwoThree(x, mathContext);
}
return round(result, mathContext);
}
/**
* Calculates the logarithm of {@link BigDecimal} x to the base 2.
*
* @param x the {@link BigDecimal} to calculate the logarithm base 2 for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated natural logarithm {@link BigDecimal} to the base 2 with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if x <= 0
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal log2(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal result = log(x, mc).divide(logTwo(mc), mc);
return round(result, mathContext);
}
/**
* Calculates the logarithm of {@link BigDecimal} x to the base 10.
*
* @param x the {@link BigDecimal} to calculate the logarithm base 10 for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated natural logarithm {@link BigDecimal} to the base 10 with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if x <= 0
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal log10(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 2, mathContext.getRoundingMode());
BigDecimal result = log(x, mc).divide(logTen(mc), mc);
return round(result, mathContext);
}
private static BigDecimal logUsingNewton(BigDecimal x, MathContext mathContext) {
// https://en.wikipedia.org/wiki/Natural_logarithm in chapter 'High Precision'
// y = y + 2 * (x-exp(y)) / (x+exp(y))
int maxPrecision = mathContext.getPrecision() + 20;
BigDecimal acceptableError = ONE.movePointLeft(mathContext.getPrecision() + 1);
//System.out.println("logUsingNewton(" + x + " " + mathContext + ") precision " + maxPrecision);
BigDecimal result;
int adaptivePrecision;
double doubleX = x.doubleValue();
if (doubleX > 0.0 && isDoubleValue(x)) {
result = BigDecimal.valueOf(Math.log(doubleX));
adaptivePrecision = EXPECTED_INITIAL_PRECISION;
} else {
result = x.divide(TWO, mathContext);
adaptivePrecision = 1;
}
BigDecimal step;
do {
adaptivePrecision *= 3;
if (adaptivePrecision > maxPrecision) {
adaptivePrecision = maxPrecision;
}
MathContext mc = new MathContext(adaptivePrecision, mathContext.getRoundingMode());
BigDecimal expY = BigDecimalMath.exp(result, mc);
step = TWO.multiply(x.subtract(expY)).divide(x.add(expY), mc);
//System.out.println(" step " + step + " adaptivePrecision=" + adaptivePrecision);
result = result.add(step);
} while (adaptivePrecision < maxPrecision || step.abs().compareTo(acceptableError) > 0);
return result;
}
private static BigDecimal logUsingExponent(BigDecimal x, MathContext mathContext) {
MathContext mcDouble = new MathContext(mathContext.getPrecision() << 1, mathContext.getRoundingMode());
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
//System.out.println("logUsingExponent(" + x + " " + mathContext + ") precision " + mc);
int exponent = exponent(x);
BigDecimal mantissa = mantissa(x);
BigDecimal result = logUsingTwoThree(mantissa, mc);
if (exponent != 0) {
result = result.add(valueOf(exponent).multiply(logTen(mcDouble), mc));
}
return result;
}
private static BigDecimal logUsingTwoThree(BigDecimal x, MathContext mathContext) {
MathContext mcDouble = new MathContext(mathContext.getPrecision() << 1, mathContext.getRoundingMode());
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
//System.out.println("logUsingTwoThree(" + x + " " + mathContext + ") precision " + mc);
int factorOfTwo = 0;
int powerOfTwo = 1;
int factorOfThree = 0;
int powerOfThree = 1;
double value = x.doubleValue();
if (value < 0.01) {
// do nothing
} else if (value < 0.1) { // never happens when called by logUsingExponent()
while (value < 0.6) {
value *= 2;
factorOfTwo--;
powerOfTwo <<= 1;
}
}
else if (value < 0.115) { // (0.1 - 0.11111 - 0.115) -> (0.9 - 1.0 - 1.035)
factorOfThree = -2;
powerOfThree = 9;
}
else if (value < 0.14) { // (0.115 - 0.125 - 0.14) -> (0.92 - 1.0 - 1.12)
factorOfTwo = -3;
powerOfTwo = 8;
}
else if (value < 0.2) { // (0.14 - 0.16667 - 0.2) - (0.84 - 1.0 - 1.2)
factorOfTwo = -1;
powerOfTwo = 2;
factorOfThree = -1;
powerOfThree = 3;
}
else if (value < 0.3) { // (0.2 - 0.25 - 0.3) -> (0.8 - 1.0 - 1.2)
factorOfTwo = -2;
powerOfTwo = 4;
}
else if (value < 0.42) { // (0.3 - 0.33333 - 0.42) -> (0.9 - 1.0 - 1.26)
factorOfThree = -1;
powerOfThree = 3;
}
else if (value < 0.7) { // (0.42 - 0.5 - 0.7) -> (0.84 - 1.0 - 1.4)
factorOfTwo = -1;
powerOfTwo = 2;
}
else if (value < 1.4) { // (0.7 - 1.0 - 1.4) -> (0.7 - 1.0 - 1.4)
// do nothing
}
else if (value < 2.5) { // (1.4 - 2.0 - 2.5) -> (0.7 - 1.0 - 1.25)
factorOfTwo = 1;
powerOfTwo = 2;
}
else if (value < 3.5) { // (2.5 - 3.0 - 3.5) -> (0.833333 - 1.0 - 1.166667)
factorOfThree = 1;
powerOfThree = 3;
}
else if (value < 5.0) { // (3.5 - 4.0 - 5.0) -> (0.875 - 1.0 - 1.25)
factorOfTwo = 2;
powerOfTwo = 4;
}
else if (value < 7.0) { // (5.0 - 6.0 - 7.0) -> (0.833333 - 1.0 - 1.166667)
factorOfThree = 1;
powerOfThree = 3;
factorOfTwo = 1;
powerOfTwo = 2;
}
else if (value < 8.5) { // (7.0 - 8.0 - 8.5) -> (0.875 - 1.0 - 1.0625)
factorOfTwo = 3;
powerOfTwo = 8;
}
else if (value < 10.0) { // (8.5 - 9.0 - 10.0) -> (0.94444 - 1.0 - 1.11111)
factorOfThree = 2;
powerOfThree = 9;
}
else {
while (value > 1.4) { // never happens when called by logUsingExponent()
value /= 2;
factorOfTwo++;
powerOfTwo <<= 1;
}
}
BigDecimal correctedX = x;
BigDecimal result = ZERO;
if (factorOfTwo > 0) {
correctedX = correctedX.divide(valueOf(powerOfTwo), mc);
result = result.add(logTwo(mcDouble).multiply(valueOf(factorOfTwo), mc));
}
else if (factorOfTwo < 0) {
correctedX = correctedX.multiply(valueOf(powerOfTwo), mc);
result = result.subtract(logTwo(mcDouble).multiply(valueOf(-factorOfTwo), mc));
}
if (factorOfThree > 0) {
correctedX = correctedX.divide(valueOf(powerOfThree), mc);
result = result.add(logThree(mcDouble).multiply(valueOf(factorOfThree), mc));
}
else if (factorOfThree < 0) {
correctedX = correctedX.multiply(valueOf(powerOfThree), mc);
result = result.subtract(logThree(mcDouble).multiply(valueOf(-factorOfThree), mc));
}
if (x == correctedX && result == ZERO) {
return logUsingNewton(x, mathContext);
}
result = result.add(logUsingNewton(correctedX, mc), mc);
return result;
}
/**
* Returns the number pi.
*
* <p>See <a href="https://en.wikipedia.org/wiki/Pi">Wikipedia: Pi</a></p>
*
* @param mathContext the {@link MathContext} used for the result
* @return the number pi with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal pi(MathContext mathContext) {
checkMathContext(mathContext);
BigDecimal result = null;
synchronized (piCacheLock) {
if (piCache != null && mathContext.getPrecision() <= piCache.precision()) {
result = piCache;
} else {
piCache = piChudnovski(mathContext);
return piCache;
}
}
return round(result, mathContext);
}
private static BigDecimal piChudnovski(MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 10, mathContext.getRoundingMode());
final BigDecimal value24 = BigDecimal.valueOf(24);
final BigDecimal value640320 = BigDecimal.valueOf(640320);
final BigDecimal value13591409 = BigDecimal.valueOf(13591409);
final BigDecimal value545140134 = BigDecimal.valueOf(545140134);
final BigDecimal valueDivisor = value640320.pow(3).divide(value24, mc);
BigDecimal sumA = BigDecimal.ONE;
BigDecimal sumB = BigDecimal.ZERO;
BigDecimal a = BigDecimal.ONE;
long dividendTerm1 = 5; // -(6*k - 5)
long dividendTerm2 = -1; // 2*k - 1
long dividendTerm3 = -1; // 6*k - 1
BigDecimal kPower3 = BigDecimal.ZERO;
long iterationCount = (mc.getPrecision()+13) / 14;
for (long k = 1; k <= iterationCount; k++) {
BigDecimal valueK = BigDecimal.valueOf(k);
dividendTerm1 += -6;
dividendTerm2 += 2;
dividendTerm3 += 6;
BigDecimal dividend = BigDecimal.valueOf(dividendTerm1).multiply(BigDecimal.valueOf(dividendTerm2)).multiply(BigDecimal.valueOf(dividendTerm3));
kPower3 = valueK.pow(3);
BigDecimal divisor = kPower3.multiply(valueDivisor, mc);
a = a.multiply(dividend).divide(divisor, mc);
BigDecimal b = valueK.multiply(a, mc);
sumA = sumA.add(a);
sumB = sumB.add(b);
}
final BigDecimal value426880 = BigDecimal.valueOf(426880);
final BigDecimal value10005 = BigDecimal.valueOf(10005);
final BigDecimal factor = value426880.multiply(sqrt(value10005, mc));
BigDecimal pi = factor.divide(value13591409.multiply(sumA, mc).add(value545140134.multiply(sumB, mc)), mc);
return round(pi, mathContext);
}
/**
* Returns the number e.
*
* <p>See <a href="https://en.wikipedia.org/wiki/E_(mathematical_constant)">Wikipedia: E (mathematical_constant)</a></p>
*
* @param mathContext the {@link MathContext} used for the result
* @return the number e with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal e(MathContext mathContext) {
checkMathContext(mathContext);
BigDecimal result = null;
synchronized (eCacheLock) {
if (eCache != null && mathContext.getPrecision() <= eCache.precision()) {
result = eCache;
} else {
eCache = exp(ONE, mathContext);
return eCache;
}
}
return round(result, mathContext);
}
private static BigDecimal logTen(MathContext mathContext) {
BigDecimal result = null;
synchronized (log10CacheLock) {
if (log10Cache != null && mathContext.getPrecision() <= log10Cache.precision()) {
result = log10Cache;
} else {
log10Cache = logUsingNewton(BigDecimal.TEN, mathContext);
return log10Cache;
}
}
return round(result, mathContext);
}
private static BigDecimal logTwo(MathContext mathContext) {
BigDecimal result = null;
synchronized (log2CacheLock) {
if (log2Cache != null && mathContext.getPrecision() <= log2Cache.precision()) {
result = log2Cache;
} else {
log2Cache = logUsingNewton(TWO, mathContext);
return log2Cache;
}
}
return round(result, mathContext);
}
private static BigDecimal logThree(MathContext mathContext) {
BigDecimal result = null;
synchronized (log3CacheLock) {
if (log3Cache != null && mathContext.getPrecision() <= log3Cache.precision()) {
result = log3Cache;
} else {
log3Cache = logUsingNewton(THREE, mathContext);
return log3Cache;
}
}
return round(result, mathContext);
}
/**
* Calculates the natural exponent of {@link BigDecimal} x (e<sup>x</sup>).
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Exponent">Wikipedia: Exponent</a></p>
*
* @param x the {@link BigDecimal} to calculate the exponent for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated exponent {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal exp(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
if (x.signum() == 0) {
return ONE;
}
return expIntegralFractional(x, mathContext);
}
private static BigDecimal expIntegralFractional(BigDecimal x, MathContext mathContext) {
BigDecimal integralPart = integralPart(x);
if (integralPart.signum() == 0) {
return expTaylor(x, mathContext);
}
BigDecimal fractionalPart = x.subtract(integralPart);
MathContext mc = new MathContext(mathContext.getPrecision() + 10, mathContext.getRoundingMode());
BigDecimal z = ONE.add(fractionalPart.divide(integralPart, mc));
BigDecimal t = expTaylor(z, mc);
BigDecimal result = pow(t, integralPart.intValueExact(), mc);
return round(result, mathContext);
}
private static BigDecimal expTaylor(BigDecimal x, MathContext mathContext) {
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
x = x.divide(valueOf(256), mc);
BigDecimal result = ExpCalculator.INSTANCE.calculate(x, mc);
result = BigDecimalMath.pow(result, 256, mc);
return round(result, mathContext);
}
/**
* Calculates the sine (sinus) of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Sine">Wikipedia: Sine</a></p>
*
* @param x the {@link BigDecimal} to calculate the sine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated sine {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal sin(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
if (x.abs().compareTo(ROUGHLY_TWO_PI) > 0) {
MathContext mc2 = new MathContext(mc.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal twoPi = TWO.multiply(pi(mc2));
x = x.remainder(twoPi, mc2);
}
BigDecimal result = SinCalculator.INSTANCE.calculate(x, mc);
return round(result, mathContext);
}
/**
* Calculates the arc sine (inverted sine) of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Arcsine">Wikipedia: Arcsine</a></p>
*
* @param x the {@link BigDecimal} to calculate the arc sine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc sine {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if x > 1 or x < -1
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal asin(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
if (x.compareTo(ONE) > 0) {
throw new ArithmeticException("Illegal asin(x) for x > 1: x = " + x);
}
if (x.compareTo(MINUS_ONE) < 0) {
throw new ArithmeticException("Illegal asin(x) for x < -1: x = " + x);
}
if (x.signum() == -1) {
return asin(x.negate(), mathContext).negate();
}
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
if (x.compareTo(BigDecimal.valueOf(0.707107)) >= 0) {
BigDecimal xTransformed = sqrt(ONE.subtract(x.multiply(x)), mc);
return acos(xTransformed, mathContext);
}
BigDecimal result = AsinCalculator.INSTANCE.calculate(x, mc);
return round(result, mathContext);
}
/**
* Calculates the cosine (cosinus) of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Cosine">Wikipedia: Cosine</a></p>
*
* @param x the {@link BigDecimal} to calculate the cosine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated cosine {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal cos(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
if (x.abs().compareTo(ROUGHLY_TWO_PI) > 0) {
MathContext mc2 = new MathContext(mc.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal twoPi = TWO.multiply(pi(mc2), mc2);
x = x.remainder(twoPi, mc2);
}
BigDecimal result = CosCalculator.INSTANCE.calculate(x, mc);
return round(result, mathContext);
}
/**
* Calculates the arc cosine (inverted cosine) of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Arccosine">Wikipedia: Arccosine</a></p>
*
* @param x the {@link BigDecimal} to calculate the arc cosine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc sine {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if x > 1 or x < -1
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal acos(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
if (x.compareTo(ONE) > 0) {
throw new ArithmeticException("Illegal acos(x) for x > 1: x = " + x);
}
if (x.compareTo(MINUS_ONE) < 0) {
throw new ArithmeticException("Illegal acos(x) for x < -1: x = " + x);
}
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = pi(mc).divide(TWO, mc).subtract(asin(x, mc));
return round(result, mathContext);
}
/**
* Calculates the tangens of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Tangens">Wikipedia: Tangens</a></p>
*
* @param x the {@link BigDecimal} to calculate the tangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated tangens {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal tan(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
if (x.signum() == 0) {
return ZERO;
}
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal result = sin(x, mc).divide(cos(x, mc), mc);
return round(result, mathContext);
}
/**
* Calculates the arc tangens (inverted tangens) of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Arctangens">Wikipedia: Arctangens</a></p>
*
* @param x the {@link BigDecimal} to calculate the arc tangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc tangens {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal atan(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
x = x.divide(sqrt(ONE.add(x.multiply(x, mc)), mc), mc);
BigDecimal result = asin(x, mc);
return round(result, mathContext);
}
/**
* Calculates the arc tangens (inverted tangens) of {@link BigDecimal} y / x in the range -<i>pi</i> to <i>pi</i>.
*
* <p>This is useful to calculate the angle <i>theta</i> from the conversion of rectangular
* coordinates (<code>x</code>, <code>y</code>) to polar coordinates (r, <i>theta</i>).</p>
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Atan2">Wikipedia: Atan2</a></p>
*
* @param y the {@link BigDecimal}
* @param x the {@link BigDecimal}
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc tangens {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if x = 0 and y = 0
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal atan2(BigDecimal y, BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 3, mathContext.getRoundingMode());
if (x.signum() > 0) { // x > 0
return atan(y.divide(x, mc), mathContext);
} else if (x.signum() < 0) {
if (y.signum() > 0) { // x < 0 && y > 0
return atan(y.divide(x, mc), mc).add(pi(mc), mathContext);
} else if (y.signum() < 0) { // x < 0 && y < 0
return atan(y.divide(x, mc), mc).subtract(pi(mc), mathContext);
} else { // x < 0 && y = 0
return pi(mathContext);
}
} else {
if (y.signum() > 0) { // x == 0 && y > 0
return pi(mc).divide(TWO, mathContext);
} else if (y.signum() < 0) { // x == 0 && y < 0
return pi(mc).divide(TWO, mathContext).negate();
} else {
throw new ArithmeticException("Illegal atan2(y, x) for x = 0; y = 0");
}
}
}
/**
* Calculates the cotangens of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Cotangens">Wikipedia: Cotangens</a></p>
*
* @param x the {@link BigDecimal} to calculate the cotangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated cotanges {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws ArithmeticException if x = 0
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal cot(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
if (x.signum() == 0) {
throw new ArithmeticException("Illegal cot(x) for x = 0");
}
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal result = cos(x, mc).divide(sin(x, mc), mc);
return round(result, mathContext);
}
/**
* Calculates the inverse cotangens (arc cotangens) of {@link BigDecimal} x.
*
* <p>See: <a href="http://en.wikipedia.org/wiki/Arccotangens">Wikipedia: Arccotangens</a></p>
*
* @param x the {@link BigDecimal} to calculate the arc cotangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc cotangens {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal acot(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal result = pi(mc).divide(TWO, mc).subtract(atan(x, mc));
return round(result, mathContext);
}
/**
* Calculates the hyperbolic sine of {@link BigDecimal} x.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p>
*
* @param x the {@link BigDecimal} to calculate the hyperbolic sine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated hyperbolic sine {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal sinh(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal result = SinhCalculator.INSTANCE.calculate(x, mc);
return round(result, mathContext);
}
/**
* Calculates the hyperbolic cosine of {@link BigDecimal} x.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p>
*
* @param x the {@link BigDecimal} to calculate the hyperbolic cosine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated hyperbolic cosine {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal cosh(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());
BigDecimal result = CoshCalculator.INSTANCE.calculate(x, mc);
return round(result, mathContext);
}
/**
* Calculates the hyperbolic tangens of {@link BigDecimal} x.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p>
*
* @param x the {@link BigDecimal} to calculate the hyperbolic tangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated hyperbolic tangens {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal tanh(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = sinh(x, mc).divide(cosh(x, mc), mc);
return round(result, mathContext);
}
/**
* Calculates the hyperbolic cotangens of {@link BigDecimal} x.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p>
*
* @param x the {@link BigDecimal} to calculate the hyperbolic cotangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated hyperbolic cotangens {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal coth(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = cosh(x, mc).divide(sinh(x, mc), mc);
return round(result, mathContext);
}
/**
* Calculates the arc hyperbolic sine (inverse hyperbolic sine) of {@link BigDecimal} x.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p>
*
* @param x the {@link BigDecimal} to calculate the arc hyperbolic sine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc hyperbolic sine {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal asinh(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 10, mathContext.getRoundingMode());
BigDecimal result = log(x.add(sqrt(x.multiply(x, mc).add(ONE, mc), mc)), mc);
return round(result, mathContext);
}
/**
* Calculates the arc hyperbolic cosine (inverse hyperbolic cosine) of {@link BigDecimal} x.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p>
*
* @param x the {@link BigDecimal} to calculate the arc hyperbolic cosine for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc hyperbolic cosine {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal acosh(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = log(x.add(sqrt(x.multiply(x).subtract(ONE), mc)), mc);
return round(result, mathContext);
}
/**
* Calculates the arc hyperbolic tangens (inverse hyperbolic tangens) of {@link BigDecimal} x.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p>
*
* @param x the {@link BigDecimal} to calculate the arc hyperbolic tangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc hyperbolic tangens {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal atanh(BigDecimal x, MathContext mathContext) {
if (x.compareTo(BigDecimal.ONE) >= 0) {
throw new ArithmeticException("Illegal atanh(x) for x >= 1: x = " + x);
}
if (x.compareTo(MINUS_ONE) <= 0) {
throw new ArithmeticException("Illegal atanh(x) for x <= -1: x = " + x);
}
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = log(ONE.add(x).divide(ONE.subtract(x), mc), mc).multiply(ONE_HALF);
return round(result, mathContext);
}
/**
* Calculates the arc hyperbolic cotangens (inverse hyperbolic cotangens) of {@link BigDecimal} x.
*
* <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p>
*
* @param x the {@link BigDecimal} to calculate the arc hyperbolic cotangens for
* @param mathContext the {@link MathContext} used for the result
* @return the calculated arc hyperbolic cotangens {@link BigDecimal} with the precision specified in the <code>mathContext</code>
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal acoth(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = log(x.add(ONE).divide(x.subtract(ONE), mc), mc).multiply(ONE_HALF);
return round(result, mathContext);
}
/**
* Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
* The conversion from radians to degrees is generally inexact, it uses the number PI with the precision specified in the mathContext.
* @param x An angle in radians.
* @param mathContext the {@link MathContext} used for the result
* @return The angle in degrees.
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal toDegrees(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = x.multiply(ONE_HUNDRED_EIGHTY.divide(pi(mc), mc), mc);
return round(result, mathContext);
}
/**
/**
* Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
* The conversion from degrees to radians is generally inexact, it uses the number PI with the precision specified in the mathContext.
*
* @param x An angle in degrees.
* @param mathContext the {@link MathContext} used for the result
* @return The angle in radians.
* @throws UnsupportedOperationException if the {@link MathContext} has unlimited precision
*/
public static BigDecimal toRadians(BigDecimal x, MathContext mathContext) {
checkMathContext(mathContext);
MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode());
BigDecimal result = x.multiply(pi(mc).divide(ONE_HUNDRED_EIGHTY, mc), mc);
return round(result, mathContext);
}
private static void checkMathContext (MathContext mathContext) {
if (mathContext.getPrecision() == 0) {
throw new UnsupportedOperationException("Unlimited MathContext not supported");
}
}
}
================================================
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigFloat.java
================================================
package ch.obermuhlner.math.big;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Objects;
/**
* A wrapper around {@link BigDecimal} which simplifies the consistent usage of the {@link MathContext}
* and provides a simpler API for calculations.
*
* <h2>Overview</h2>
*
* <p>Every {@link BigFloat} instance has a reference to a {@link Context} that specifies the {@link MathContext} to be used for all calculations and values.</p>
*
* <p>The API for calculations is simplified and more consistent with the typical mathematical usage.</p>
* <ul>
* <li>Factory methods for values:
* <ul>
* <li><code>valueOf(BigFloat)</code></li>
* <li><code>valueOf(BigDecimal)</code></li>
* <li><code>valueOf(int)</code></li>
* <li><code>valueOf(long)</code></li>
* <li><code>valueOf(double)</code></li>
* <li><code>valueOf(String)</code></li>
* <li><code>pi()</code></li>
* <li><code>e()</code></li>
* </ul>
* </li>
* <li>All standard operators:
* <ul>
* <li><code>add(x)</code></li>
* <li><code>subtract(x)</code></li>
* <li><code>multiply(x)</code></li>
* <li><code>remainder(x)</code></li>
* <li><code>pow(y)</code></li>
* <li><code>root(y)</code></li>
* </ul>
* </li>
* <li>Calculation methods are overloaded for different value types:
* <ul>
* <li><code>add(BigFloat)</code></li>
* <li><code>add(BigDecimal)</code></li>
* <li><code>add(int)</code></li>
* <li><code>add(long)</code></li>
* <li><code>add(double)</code></li>
* <li>...</li>
* </ul>
* </li>
* <li>Mathematical functions are written as they are traditionally are written:
* <ul>
* <li><code>abs(x)</code></li>
* <li><code>log(x)</code></li>
* <li><code>sin(x)</code></li>
* <li><code>min(x1, x2, ...)</code></li>
* <li><code>max(x1, x2, ...)</code></li>
* <li>...</li>
* </ul>
* </li>
* <li>Support for advanced mathematical functions:
* <ul>
* <li><code>sqrt(x)</code></li>
* <li><code>log(x)</code></li>
* <li><code>exp(x)</code></li>
* <li><code>sin(x)</code></li>
* <li><code>cos(x)</code></li>
* <li><code>tan(x)</code></li>
* <li>...</li>
* </ul>
* </li>
* <li>Methods to access parts of a value:
* <ul>
* <li><code>getMantissa()</code></li>
* <li><code>getExponent()</code></li>
* <li><code>getIntegralPart()</code></li>
* <li><code>getFractionalPart()</code></li>
* </ul>
* </li>
* <li>Equals and Hashcode methods:
* <ul>
* <li><code>equals(Object)</code> that returns whether two <code>BigFloat</code> values are mathematically the same</li>
* <li><code>hashCode()</code> consistent with <code>equals(Object)</code></li>
* </ul>
* </li>
* <li>Comparison methods:
* <ul>
* <li><code>isEqual(BigFloat)</code></li>
* <li><code>isLessThan(BigFloat)</code></li>
* <li><code>isLessThanOrEqual(BigFloat)</code></li>
* <li><code>isGreaterThan(BigFloat)</code></li>
* <li><code>isGreaterThanOrEqual(BigFloat)</code></li>
* </ul>
* </li>
* </ul>
*
* <h3>Usage</h3>
*
* <p>Before doing any calculations you need to create a <code>Context</code> specifying the precision used for all calculations.</p>
* <pre>
* Context context = BigFloat.context(100); // precision of 100 digits
* Context anotherContext = BigFloat.context(new MathContext(10, RoundingMode.HALF_UP); // precision of 10 digits, rounding half up
* </pre>
*
* <p>The <code>Context</code> can then be used to create the first value of the calculation:</p>
* <pre>
* BigFloat value1 = context.valueOf(640320);
* </pre>
*
* <p>The <code>BigFloat</code> instance holds a reference to the <code>Context</code>. This context is then passed from calculation to calculation.</p>
* <pre>
* BigFloat value2 = context.valueOf(640320).pow(3).divide(24);
* BigFloat value3 = BigFloat.sin(value2);
* </pre>
*
* <p>The <code>BigFloat</code> result can be converted to other numerical types:</p>
* <pre>
* BigDecimal bigDecimalValue = value3.toBigDecimal();
* double doubleValue = value3.toDouble();
* long longValue = value3.toLong();
* int intValue = value3.toInt();
* </pre>
*/
@SuppressWarnings("WeakerAccess")
public class BigFloat implements Comparable<BigFloat>, Serializable {
private static final long serialVersionUID = -7323679117445486894L;
/**
* Represents a value that is not a number.
* @see Double#NaN
*/
public static final BigFloat NaN = new SpecialBigFloat(SpecialBigFloat.Type.NaN);
/**
* Represents the positive infinity.
* @see Double#POSITIVE_INFINITY
*/
public static final BigFloat POSITIVE_INFINITY = new SpecialBigFloat(SpecialBigFloat.Type.POSITIVE_INFINITY);
/**
* Represents the positive infinity.
* @see Double#NEGATIVE_INFINITY
*/
public static final BigFloat NEGATIVE_INFINITY = new SpecialBigFloat(SpecialBigFloat.Type.NEGATIVE_INFINITY);
private final BigDecimal value;
private final Context context;
private BigFloat(BigDecimal value, Context context) {
this.value = value;
this.context = context;
}
/**
* Creates a {@link Context} with the specified precision and {@link RoundingMode#HALF_UP} rounding.
*
* @param precision the precision
*
* @return the {@link Context}
*/
public static Context context(int precision) {
return new Context(new MathContext(precision));
}
/**
* Creates a {@link Context} with the specified {@link MathContext}.
*
* @param mathContext the {@link MathContext}
*
* @return the {@link Context}
*/
public static Context context(MathContext mathContext) {
return new Context(mathContext);
}
/**
* Returns the {@link BigFloat} that is <code>this + x</code>.
*
* <p>If the two values do not have the same {@link Context}, the result will contain the {@link Context} with the larger precision.</p>
*
* @param x the value to add
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#add(BigDecimal, MathContext)
*/
public BigFloat add(BigFloat x) {
if (x.isSpecial())
return x.add(this);
Context c = max(context, x.context);
return c.valueOf(value.add(x.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>this + x</code>.
*
* @param x the value to add
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#add(BigDecimal, MathContext)
*/
public BigFloat add(BigDecimal x) {
return add(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this + x</code>.
*
* @param x the value to add
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#add(BigDecimal, MathContext)
*/
public BigFloat add(int x) {
return add(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this + x</code>.
*
* @param x the value to add
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#add(BigDecimal, MathContext)
*/
public BigFloat add(long x) {
return add(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this + x</code>.
*
* @param x the value to add
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#add(BigDecimal, MathContext)
*/
public BigFloat add(double x) {
return add(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this - x</code>.
*
* <p>If the two values do not have the same {@link Context}, the result will contain the {@link Context} with the larger precision.</p>
*
* @param x the value to subtract
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#subtract(BigDecimal, MathContext)
*/
public BigFloat subtract(BigFloat x) {
if (x.isSpecial())
return negate(x).add(this);
Context c = max(context, x.context);
return c.valueOf(value.subtract(x.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>this - x</code>.
*
* @param x the value to subtract
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#subtract(BigDecimal, MathContext)
*/
public BigFloat subtract(BigDecimal x) {
return subtract(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this - x</code>.
*
* @param x the value to subtract
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#subtract(BigDecimal, MathContext)
*/
public BigFloat subtract(int x) {
return subtract(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this - x</code>.
*
* @param x the value to subtract
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#subtract(BigDecimal, MathContext)
*/
public BigFloat subtract(long x) {
return subtract(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this - x</code>.
*
* @param x the value to subtract
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#subtract(BigDecimal, MathContext)
*/
public BigFloat subtract(double x) {
return subtract(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this * x</code>.
*
* <p>If the two values do not have the same {@link Context}, the result will contain the {@link Context} with the larger precision.</p>
*
* @param x the value to multiply
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#multiply(BigDecimal, MathContext)
*/
public BigFloat multiply(BigFloat x) {
if (x.isSpecial())
return x.multiply(this);
Context c = max(context, x.context);
return c.valueOf(value.multiply(x.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>this * x</code>.
*
* @param x the value to multiply
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#multiply(BigDecimal, MathContext)
*/
public BigFloat multiply(BigDecimal x) {
return multiply(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this * x</code>.
*
* @param x the value to multiply
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#multiply(BigDecimal, MathContext)
*/
public BigFloat multiply(int x) {
return multiply(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this * x</code>.
*
* @param x the value to multiply
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#multiply(BigDecimal, MathContext)
*/
public BigFloat multiply(long x) {
return multiply(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this * x</code>.
*
* @param x the value to multiply
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#multiply(BigDecimal, MathContext)
*/
public BigFloat multiply(double x) {
return multiply(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this / x</code>.
*
* <p>If the two values do not have the same {@link Context},
* the result will contain the {@link Context} with the larger precision.</p>
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#divide(BigDecimal, MathContext)
*/
public BigFloat divide(BigFloat x) {
if (x.isSpecial()) {
if (x == NaN) {
return NaN;
} else {
return context.valueOf(0);
}
}
if (this.isZero() && !x.isZero()) {
return context.valueOf(0);
}
if (x.isZero()) {
if (this.isZero()) {
return NaN; // 0 or -0 / 0 = NaN
} else if (this.isNegative()) {
return NEGATIVE_INFINITY;// -N / 0 = -INF
} else {
return POSITIVE_INFINITY;// N / 0 = +INF
}
}
Context c = max(context, x.context);
return c.valueOf(value.divide(x.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>this / x</code>.
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#divide(BigDecimal, MathContext)
*/
public BigFloat divide(BigDecimal x) {
return divide(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this / x</code>.
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#divide(BigDecimal, MathContext)
*/
public BigFloat divide(int x) {
return divide(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this / x</code>.
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#divide(BigDecimal, MathContext)
*/
public BigFloat divide(long x) {
return divide(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this / x</code>.
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#divide(BigDecimal, MathContext)
*/
public BigFloat divide(double x) {
return divide(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is the remainder when dividing <code>this</code> by <code>x</code>.
*
* <p>If the two values do not have the same {@link Context}, the result will contain the {@link Context} with the larger precision.</p>
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#remainder(BigDecimal, MathContext)
*/
public BigFloat remainder(BigFloat x) {
if (x.isSpecial()) {
if (x == NaN) {
return NaN;
} else {
return this;
}
}
if (this.isZero() && !x.isZero()) {
return context.valueOf(0);
}
if (x.isZero()) {
return NaN;
}
Context c = max(context, x.context);
return c.valueOf(value.remainder(x.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is the remainder when dividing <code>this</code> by <code>x</code>.
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#remainder(BigDecimal, MathContext)
*/
public BigFloat remainder(BigDecimal x) {
return remainder(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is the remainder when dividing <code>this</code> by <code>x</code>.
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#remainder(BigDecimal, MathContext)
*/
public BigFloat remainder(int x) {
return remainder(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is the remainder when dividing <code>this</code> by <code>x</code>.
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#remainder(BigDecimal, MathContext)
*/
public BigFloat remainder(long x) {
return remainder(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is the remainder when dividing <code>this</code> by <code>x</code>.
*
* @param x the value to divide with
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#remainder(BigDecimal, MathContext)
*/
public BigFloat remainder(double x) {
return remainder(context.valueOf(x));
}
/**
* Returns the {@link BigFloat} that is <code>this</code> to the power of <code>y</code>.
*
* <p>If the two values do not have the same {@link Context}, the result will contain the {@link Context} with the larger precision.</p>
*
* @param y the value of the power
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#pow(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat pow(BigFloat y) {
if (y.isSpecial()) {
if (this.isZero()) {
if (y == POSITIVE_INFINITY) {
return this;
}
if (y == NEGATIVE_INFINITY) {
return POSITIVE_INFINITY;
}
}
if (y == NEGATIVE_INFINITY) {
return context.ZERO;
}
return y;
}
if (this.isZero()) {
if (y.isNegative()) {
return POSITIVE_INFINITY;
}
}
Context c = max(context, y.context);
return c.valueOf(BigDecimalMath.pow(this.value, y.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>this</code> to the power of <code>y</code>.
*
* @param y the value of the power
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#pow(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat pow(BigDecimal y) {
return pow(context.valueOf(y));
}
/**
* Returns the {@link BigFloat} that is <code>this</code> to the power of <code>y</code>.
*
* @param y the value of the power
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#pow(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat pow(int y) {
return pow(context.valueOf(y));
}
/**
* Returns the {@link BigFloat} that is <code>this</code> to the power of <code>y</code>.
*
* @param y the value of the power
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#pow(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat pow(long y) {
return pow(context.valueOf(y));
}
/**
* Returns the {@link BigFloat} that is <code>this</code> to the power of <code>y</code>.
*
* @param y the value of the power
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#pow(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat pow(double y) {
return pow(context.valueOf(y));
}
/**
* Returns the {@link BigFloat} that is the <code>y</code>th root of <code>this</code>.
*
* <p>If the two values do not have the same {@link Context}, the result will contain the {@link Context} with the larger precision.</p>
*
* @param y the value of the root
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#root(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat root(BigFloat y) {
if (y.isSpecial())
return y;
Context c = max(context, y.context);
return c.valueOf(BigDecimalMath.root(this.value, y.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is the <code>y</code>th root of <code>this</code>.
*
* @param y the value of the root
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#root(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat root(BigDecimal y) {
return root(context.valueOf(y));
}
/**
* Returns the {@link BigFloat} that is the <code>y</code>th root of <code>this</code>.
*
* @param y the value of the root
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#root(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat root(int y) {
return root(context.valueOf(y));
}
/**
* Returns the {@link BigFloat} that is the <code>y</code>th root of <code>this</code>.
*
* @param y the value of the root
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#root(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat root(long y) {
return root(context.valueOf(y));
}
/**
* Returns the {@link BigFloat} that is the <code>y</code>th root of <code>this</code>.
*
* @param y the value of the root
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#root(BigDecimal, BigDecimal, MathContext)
*/
public BigFloat root(double y) {
return root(context.valueOf(y));
}
@Override
public int hashCode() {
return value.stripTrailingZeros().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BigFloat other = (BigFloat) obj;
return value.compareTo(other.value) == 0;
//return Objects.equals(value, other.value) && Objects.equals(context, other.context);
}
/**
* Returns the signum function of this {@link BigFloat}.
*
* @return -1, 0, or 1 as the value of this {@link BigDecimal} is negative, zero, or positive.
*/
public int signum() {
return value.signum();
}
/**
* Returns whether this {@link BigFloat} is negative.
*
* @return <code>true</code> if negative, <code>false</code> if 0 or positive
*/
public boolean isNegative() {
return value.signum() < 0;
}
/**
* Returns whether this {@link BigFloat} is 0.
*
* @return <code>true</code> if 0, <code>false</code> if negative or positive
*/
public boolean isZero() {
return value.signum() == 0;
}
/**
* Returns whether this {@link BigFloat} is positive.
*
* @return <code>true</code> if positive, <code>false</code> if 0 or negative
*/
public boolean isPositive() {
return value.signum() > 0;
}
@Override
public int compareTo(BigFloat other) {
if (other.isSpecial()) {
return -other.compareTo(this);
}
return value.compareTo(other.value);
}
/**
* Returns whether <code>this</code> value is mathematically equal to the <code>other</code> value.
*
* @param other the other {@link BigFloat} to compare with
*
* @return <code>true</code> if both values are mathematically equal (equivalent to <code>this.compareTo(other) == 0</code>
*
* @see #compareTo(BigFloat)
*/
public boolean isEqual(BigFloat other) {
if (this == NaN || other == NaN) {
return false;
}
return compareTo(other) == 0;
}
/**
* Returns whether <code>this</code> value is mathematically less than to the <code>other</code> value.
*
* @param other the other {@link BigFloat} to compare with
*
* @return <code>true</code> <code>this</code> value is mathematically less than to the <code>other</code> value (equivalent to <code>this.compareTo(other) < 0</code>
*
* @see #compareTo(BigFloat)
*/
public boolean isLessThan(BigFloat other) {
if (this == NaN || other == NaN) {
return false;
}
return compareTo(other) < 0;
}
/**
* Returns whether <code>this</code> value is mathematically greater than to the <code>other</code> value.
*
* @param other the other {@link BigFloat} to compare with
*
* @return <code>true</code> <code>this</code> value is mathematically greater than to the <code>other</code> value (equivalent to <code>this.compareTo(other) > 0</code>
*
* @see #compareTo(BigFloat)
*/
public boolean isGreaterThan(BigFloat other) {
if (this == NaN || other == NaN) {
return false;
}
return compareTo(other) > 0;
}
/**
* Returns whether <code>this</code> value is mathematically less than or equal to the <code>other</code> value.
*
* @param other the other {@link BigFloat} to compare with
*
* @return <code>true</code> <code>this</code> value is mathematically less than or equal to the <code>other</code> value (equivalent to <code>this.compareTo(other) <= 0</code>
*
* @see #compareTo(BigFloat)
* @see #isLessThan(BigFloat)
* @see #isEqual(BigFloat)
*/
public boolean isLessThanOrEqual(BigFloat other) {
if (this == NaN || other == NaN) {
return false;
}
return compareTo(other) <= 0;
}
/**
* Returns whether <code>this</code> value is mathematically greater than or equal to the <code>other</code> value.
*
* @param other the other {@link BigFloat} to compare with
*
* @return <code>true</code> <code>this</code> value is mathematically greater than or equal to the <code>other</code> value (equivalent to <code>this.compareTo(other) >= 0</code>
*
* @see #compareTo(BigFloat)
* @see #isGreaterThan(BigFloat)
* @see #isEqual(BigFloat)
*/
public boolean isGreaterThanOrEqual(BigFloat other) {
if (this == NaN || other == NaN) {
return false;
}
return compareTo(other) >= 0;
}
/**
* Returns whether <code>this</code> value can be represented as <code>int</code>.
*
* @return <code>true</code> if the value can be represented as <code>int</code> value
*
* @see BigDecimalMath#isIntValue(BigDecimal)
*/
public boolean isIntValue() {
return BigDecimalMath.isIntValue(value);
}
/**
* Returns whether <code>this</code> specified {@link BigDecimal} value can be represented as <code>double</code>.
*
* @return <code>true</code> if the value can be represented as <code>double</code> value
*
* @see BigDecimalMath#isDoubleValue(BigDecimal)
*/
public boolean isDoubleValue() {
return BigDecimalMath.isDoubleValue(value);
}
/**
* Returns the mantissa of <code>this</code> value written as <em>mantissa * 10<sup>exponent</sup></em>.
*
* <p>The mantissa is defined as having exactly 1 digit before the decimal point.</p>
*
* @return the mantissa
*
* @see #getExponent()
* @see BigDecimalMath#mantissa(BigDecimal)
*/
public BigFloat getMantissa() {
return context.valueOf(BigDecimalMath.mantissa(value));
}
/**
* Returns the exponent of <code>this</code> value written as <em>mantissa * 10<sup>exponent</sup></em>.
*
* <p>The mantissa is defined as having exactly 1 digit before the decimal point.</p>
*
* @return the exponent
*
* @see #getMantissa()
* @see BigDecimalMath#exponent(BigDecimal)
*/
public BigFloat getExponent() {
return context.valueOf(BigDecimalMath.exponent(value));
}
/**
* Returns the integral part of <code>this</code> value (left of the decimal point).
*
* @return the integral part
*
* @see #getFractionalPart()
* @see BigDecimalMath#fractionalPart(BigDecimal)
*/
public BigFloat getIntegralPart() {
return context.valueOf(BigDecimalMath.integralPart(value));
}
/**
* Returns the fractional part of <code>this</code> value (right of the decimal point).
*
* @return the fractional part
*
* @see #getIntegralPart()
* @see BigDecimalMath#fractionalPart(BigDecimal)
*/
public BigFloat getFractionalPart() {
return context.valueOf(BigDecimalMath.fractionalPart(value));
}
/**
* Returns the {@link Context} of <code>this</code> value.
*
* @return the {@link Context}
*/
public Context getContext() {
return context;
}
/**
* Returns <code>this</code> value as a {@link BigDecimal} value.
*
* @return the {@link BigDecimal} value
*/
public BigDecimal toBigDecimal() {
return value;
}
/**
* Returns <code>this</code> value as a <code>double</code> value.
*
* @return the <code>double</code> value
*
* @see BigDecimal#doubleValue()
*/
public double toDouble() {
return value.doubleValue();
}
/**
* Returns <code>this</code> value as a <code>long</code> value.
*
* @return the <code>long</code> value
*
* @see BigDecimal#longValue()
*/
public long toLong() {
return value.longValue();
}
/**
* Returns <code>this</code> value as a <code>int</code> value.
*
* @return the <code>int</code> value
*
* @see BigDecimal#intValue()
*/
public int toInt() {
return value.intValue();
}
@Override
public String toString() {
return value.toString();
}
protected boolean isSpecial() {
return false;
}
/**
* return special type of a value
* @return {@link SpecialBigFloat.Type}
*/
protected SpecialBigFloat.Type type() {
return SpecialBigFloat.Type.NORMAL;
}
public boolean isNaN() {
return this == NaN;
}
public boolean isInfinity() {
return this == POSITIVE_INFINITY || this == NEGATIVE_INFINITY;
}
/**
* this class handle unrepresentable value in floating-point arithmetic
*
* @author Wireless4024
*/
private static final class SpecialBigFloat extends BigFloat {
private static final Context DUMMY_CONTEXT = BigFloat.context(MathContext.DECIMAL32);
private final Type type;
private SpecialBigFloat(Type type) {
super(null, DUMMY_CONTEXT);
this.type = type;
}
@Override
protected boolean isSpecial() {
return true;
}
@Override
protected Type type() {
return type;
}
@Override
public BigFloat add(BigFloat x) {
if (!x.isSpecial()) {
return this;
}
if (this == POSITIVE_INFINITY && x == POSITIVE_INFINITY) {
return POSITIVE_INFINITY;
}
if (this == NEGATIVE_INFINITY && x == NEGATIVE_INFINITY) {
return NEGATIVE_INFINITY;
}
return NaN;
}
@Override
public BigFloat subtract(BigFloat x) {
if (!x.isSpecial()) {
return this;
}
if (this == POSITIVE_INFINITY && x == NEGATIVE_INFINITY) {
return POSITIVE_INFINITY;
}
if (this == NEGATIVE_INFINITY && x == POSITIVE_INFINITY) {
return NEGATIVE_INFINITY;
}
return NaN;
}
@Override
public BigFloat subtract(BigDecimal x) {
return this;
}
@Override
public BigFloat multiply(BigFloat x) {
if (x.isZero() || x == NaN) {
return NaN;
} else if (x.isNegative()) {
return negate(this);
} else {
return this;
}
}
@Override
public BigFloat divide(BigFloat x) {
if (x == NaN || (this.isInfinity() && x.isInfinity())) {
return NaN;
} else if (x.isNegative()) {
return negate(this);
} else {
return this;
}
}
@Override
public BigFloat remainder(BigFloat x) {
return NaN;
}
@Override
public BigFloat pow(BigFloat y) {
if (y.isZero()) {
return y.context.ONE;
}
if (y == NaN) {
return NaN;
}
if (this.isInfinity() && y.isNegative()) {
return y.context.ZERO;
}
if (this == NEGATIVE_INFINITY && y.isPositive()) {
return POSITIVE_INFINITY;
}
return this;
}
@Override
public BigFloat root(BigFloat y) {
return this;
}
@Override
public int hashCode() {
return type.hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
return obj instanceof BigFloat && ((BigFloat) obj).isSpecial() && ((BigFloat) obj).type() == this.type;
}
@Override
public int signum() {
return type == Type.POSITIVE_INFINITY ? 1 : -1;
}
@Override
public boolean isNegative() {
return signum() < 0;
}
@Override
public boolean isZero() {
return false;//nan or infinity is not a zero
}
@Override
public boolean isPositive() {
return signum() > 0;
}
@Override
public int compareTo(BigFloat other) {
return Type.compare(type, other.type());
}
@Override
public boolean isIntValue() {
return false;
}
@Override
public boolean isDoubleValue() {
return false;
}
@Override
public BigFloat getMantissa() {
return this;
}
@Override
public BigFloat getExponent() {
return this;
}
@Override
public BigFloat getIntegralPart() {
return this;
}
@Override
public BigFloat getFractionalPart() {
return this;
}
@Override
public Context getContext() {
throw new UnsupportedOperationException(type + " has no context");
}
@Override
public BigDecimal toBigDecimal() {
throw new UnsupportedOperationException(type + " has no corresponding BigDecimal representation");
}
@Override
public double toDouble() {
return type.toDouble();
}
@Override
public long toLong() {
return (long) toDouble();
}
@Override
public int toInt() {
return (int) toDouble();
}
@Override
public String toString() {
return type.toString();
}
//optional static
enum Type {
NaN(Objects.hashCode(Double.NaN)),
POSITIVE_INFINITY(Objects.hashCode(Double.POSITIVE_INFINITY)),
NORMAL(Objects.hashCode(0)),
NEGATIVE_INFINITY(Objects.hashCode(Double.NEGATIVE_INFINITY));
final int hashCode;
Type(int hashCode){
this.hashCode=hashCode;
}
public static int compare(Type a, Type b) {
//we can use double to compare
//if (a == NaN && b == NaN)
// return 0;//cuz NaN equals nothing even itself
return Double.compare(a.toDouble(),b.toDouble());
}
/**
* convert type to double
* @return double value that equivalent to {@link Type}
*/
public double toDouble() {
switch (this) {
case POSITIVE_INFINITY:
return Double.POSITIVE_INFINITY;
case NEGATIVE_INFINITY:
return Double.NEGATIVE_INFINITY;
case NaN:
return Double.NaN;
default:
return 0;
}
}
}
}
/**
* Manages the {@link MathContext} and provides factory methods for {@link BigFloat} values.
*/
public static class Context implements Serializable{
private static final long serialVersionUID = -5787473786808803161L;
public final BigFloat NEGATIVE_ONE;
public final BigFloat ZERO;
public final BigFloat ONE;
private final MathContext mathContext;
private Context(MathContext mathContext) {
this.mathContext = mathContext;
NEGATIVE_ONE = this.valueOf(-1);
ZERO = this.valueOf(0);
ONE = this.valueOf(1);
}
/**
* Returns the {@link MathContext} of this context.
*
* @return the {@link MathContext}
*/
public MathContext getMathContext() {
return mathContext;
}
/**
* Returns the precision of this context.
* <p>
* This is equivalent to calling <code>getMathContext().getPrecision()</code>.
*
* @return the precision
*/
public int getPrecision() {
return mathContext.getPrecision();
}
/**
* Returns the {@link RoundingMode} of this context.
* <p>
* This is equivalent to calling <code>getMathContext().getRoundingMode()</code>.
*
* @return the {@link RoundingMode}
*/
public RoundingMode getRoundingMode() {
return mathContext.getRoundingMode();
}
/**
* Creates a {@link BigFloat} value with this context.
*
* @param value the source {@link BigFloat} value
*
* @return the {@link BigFloat} value with this context (rounded to the precision of this context)
*/
public BigFloat valueOf(BigFloat value) {
return value.isSpecial() ? value : new BigFloat(value.value.round(mathContext), this);//they are final
}
/**
* Creates a {@link BigFloat} value with this context.
*
* @param value the source {@link BigDecimal} value
*
* @return the {@link BigFloat} value with this context (rounded to the precision of this context)
*/
public BigFloat valueOf(BigDecimal value) {
return new BigFloat(value.round(mathContext), this);
}
/**
* Creates a {@link BigFloat} value with this context.
*
* @param value the source int value
*
* @return the {@link BigFloat} value with this context (rounded to the precision of this context)
*/
public BigFloat valueOf(int value) {
return new BigFloat(new BigDecimal(value, mathContext), this);
}
/**
* parse unsigned value with this logic <pre><code>value & 4294967295</code></pre>
* @param value an int value
* @param unsigned if true value will parse as unsigned integer
* @return the {@link BigFloat} value with this context (rounded to the precision of this context)
*/
public BigFloat valueOf(int value, boolean unsigned) {
if (!unsigned) {
return new BigFloat(new BigDecimal(value, mathContext), this);
} else {
if (value > -1)
return valueOf(value, false);
return new BigFloat(new BigDecimal(Integer.MAX_VALUE)
.add(new BigDecimal(value & Integer.MAX_VALUE))
.add(BigDecimal.ONE), this);
}
}
/**
* Creates a {@link BigFloat} value with this context.
*
* @param value the source long value
*
* @return the {@link BigFloat} value with this context (rounded to the precision of this context)
*/
public BigFloat valueOf(long value) {
return new BigFloat(new BigDecimal(value, mathContext), this);
}
/**
* parse unsigned value with this logic <pre><code>value & 18446744073709551615</code></pre>
* @param value an int value
* @param unsigned if true value will parse as unsigned integer
* @return the {@link BigFloat} value with this context (rounded to the precision of this context)
*/
public BigFloat valueOf(long value, boolean unsigned) {
if (!unsigned) {
return new BigFloat(new BigDecimal(value, mathContext), this);
} else {
if (value > -1)
return valueOf(value, false);
return new BigFloat(new BigDecimal(Long.MAX_VALUE)
.add(new BigDecimal(value & Long.MAX_VALUE))
.add(BigDecimal.ONE), this);
}
}
/**
* Creates a {@link BigFloat} value with this context.
*
* @param value the source double value
*
* @return the {@link BigFloat} value with this context (rounded to the precision of this context)
*/
public BigFloat valueOf(double value) {
if (Double.isInfinite(value))
return value == Double.POSITIVE_INFINITY ? POSITIVE_INFINITY : NEGATIVE_INFINITY;
else if (Double.isNaN(value))
return NaN;
return new BigFloat(new BigDecimal(String.valueOf(value), mathContext), this);
}
/**
* Creates a {@link BigFloat} value with this context.
*
* @param value the source String value
*
* @return the {@link BigFloat} value with this context (rounded to the precision of this context)
*
* @throws NumberFormatException if the value is not a valid number.
*/
public BigFloat valueOf(String value) {
return new BigFloat(new BigDecimal(value, mathContext), this);
}
/**
* Returns the constant pi with this context.
*
* @return pi with this context (rounded to the precision of this context)
*
* @see BigDecimalMath#pi(MathContext)
*/
public BigFloat pi() {
return valueOf(BigDecimalMath.pi(mathContext));
}
/**
* Returns the constant e with this context.
*
* @return e with this context (rounded to the precision of this context)
*
* @see BigDecimalMath#e(MathContext)
*/
public BigFloat e() {
return valueOf(BigDecimalMath.e(mathContext));
}
/**
* Returns the factorial of n with this context.
*
* @param n the value to calculate
*
* @return the factorial of n with this context (rounded to the precision of this context)
*
* @see BigDecimalMath#factorial(int)
*/
public BigFloat factorial(int n) {
return valueOf(BigDecimalMath.factorial(n));
}
@Override
public int hashCode() {
return mathContext.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Context other = (Context) obj;
return mathContext.equals(other.mathContext);
}
@Override
public String toString() {
return mathContext.toString();
}
}
/**
* Returns the {@link BigFloat} that is <code>- this</code>.
*
* @param x the value to negate
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#negate(MathContext)
*/
public static BigFloat negate(BigFloat x) {
if (x.isSpecial())
if (x.isInfinity())
return x == POSITIVE_INFINITY ? NEGATIVE_INFINITY : POSITIVE_INFINITY;
else
return NaN;
return x.context.valueOf(x.value.negate());
}
/**
* Returns the {@link BigFloat} that is the <code>abs(this)</code> (absolute value).
*
* @param x the value to make absolute
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimal#abs(MathContext)
*/
public static BigFloat abs(BigFloat x) {
if (x.isSpecial())
return x.isInfinity() ? POSITIVE_INFINITY : NaN;
return x.context.valueOf(x.value.abs());
}
/**
* Returns the the maximum of two {@link BigFloat} values.
*
* @param value1 the first {@link BigFloat} value to compare
* @param value2 the second {@link BigFloat} value to compare
*
* @return the maximum {@link BigFloat} value
*/
public static BigFloat max(BigFloat value1, BigFloat value2) {
return value1.compareTo(value2) >= 0 ? value1 : value2;
}
/**
* Returns the the maximum of n {@link BigFloat} values.
*
* @param value1 the first {@link BigFloat} value to compare
* @param values the other {@link BigFloat}s value to compare
*
* @return the maximum {@link BigFloat} value
*/
public static BigFloat max(BigFloat value1, BigFloat... values) {
BigFloat result = value1;
for (BigFloat other : values) {
result = max(result, other);
}
return result;
}
/**
* Returns the the minimum of two {@link BigFloat} values.
*
* @param value1 the first {@link BigFloat} value to compare
* @param value2 the second {@link BigFloat} value to compare
*
* @return the minimum {@link BigFloat} value
*/
public static BigFloat min(BigFloat value1, BigFloat value2) {
return value1.compareTo(value2) < 0 ? value1 : value2;
}
/**
* Returns the the minimum of n {@link BigFloat} values.
*
* @param value1 the first {@link BigFloat} value to compare
* @param values the other {@link BigFloat}s value to compare
*
* @return the minimum {@link BigFloat} value
*/
public static BigFloat min(BigFloat value1, BigFloat... values) {
BigFloat result = value1;
for (BigFloat other : values) {
result = min(result, other);
}
return result;
}
private static BigFloat logSpecial(BigFloat val){
if (val.isNaN() || val.isNegative())
return NaN;
if (val == POSITIVE_INFINITY)
return POSITIVE_INFINITY;
if (val.isZero())
return NEGATIVE_INFINITY;
return null;
}
/**
* Returns the {@link BigFloat} that is <code>log(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#log(BigDecimal, MathContext)
*/
public static BigFloat log(BigFloat x) {
BigFloat temp = logSpecial(x);
return temp != null ? temp : x.context.valueOf(BigDecimalMath.log(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>log2(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#log2(BigDecimal, MathContext)
*/
public static BigFloat log2(BigFloat x) {
BigFloat temp = logSpecial(x);
return temp != null ? temp : x.context.valueOf(BigDecimalMath.log2(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>log10(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#log10(BigDecimal, MathContext)
*/
public static BigFloat log10(BigFloat x) {
BigFloat temp = logSpecial(x);
return temp != null ? temp : x.context.valueOf(BigDecimalMath.log10(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>exp(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#exp(BigDecimal, MathContext)
*/
public static BigFloat exp(BigFloat x) {
if(x.isSpecial())
return x != NEGATIVE_INFINITY ? x : x.context.ZERO;
return x.context.valueOf(BigDecimalMath.exp(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>sqrt(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#sqrt(BigDecimal, MathContext)
*/
public static BigFloat sqrt(BigFloat x) {
if (x.isNaN() || x.isNegative())
return NaN;
if (x.isZero() || x.isInfinity())
return x;
return x.context.valueOf(BigDecimalMath.sqrt(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>pow(x, y)</code>.
*
* <p>If the two values do not have the same {@link Context}, the result will contain the {@link Context} with the larger precision.</p>
*
* @param x the {@link BigFloat} value to take to the power
* @param y the {@link BigFloat} value to serve as exponent
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#pow(BigDecimal, BigDecimal, MathContext)
*/
public static BigFloat pow(BigFloat x, BigFloat y) {
Context c = max(x.context, y.context);
return c.valueOf(BigDecimalMath.pow(x.value, y.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>root(x, y)</code>.
*
* <p>If the two values do not have the same {@link Context}, the result will contain the {@link Context} with the larger precision.</p>
*
* @param x the {@link BigFloat} value to calculate the n'th root
* @param y the {@link BigFloat} defining the root
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#pow(BigDecimal, BigDecimal, MathContext)
*/
public static BigFloat root(BigFloat x, BigFloat y) {
Context c = max(x.context, y.context);
return c.valueOf(BigDecimalMath.root(x.value, y.value, c.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>sin(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#sin(BigDecimal, MathContext)
*/
public static BigFloat sin(BigFloat x) {
if(x.isSpecial())
return NaN;
if(x.isZero())
return x;
return x.context.valueOf(BigDecimalMath.sin(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>cos(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#cos(BigDecimal, MathContext)
*/
public static BigFloat cos(BigFloat x) {
if(x.isSpecial())
return NaN;
return x.context.valueOf(BigDecimalMath.cos(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>tan(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#tan(BigDecimal, MathContext)
*/
public static BigFloat tan(BigFloat x) {
if(x.isSpecial())
return NaN;
if(x.isZero())
return x;
return x.context.valueOf(BigDecimalMath.tan(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>cot(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#cot(BigDecimal, MathContext)
*/
public static BigFloat cot(BigFloat x) {
if(x.isSpecial())
return x;
if(x.isZero())
return POSITIVE_INFINITY;
return x.context.valueOf(BigDecimalMath.cot(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>asin(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#asin(BigDecimal, MathContext)
*/
public static BigFloat asin(BigFloat x) {
if (x.isZero())
return x;
return x.isNaN() || (!isRangeAbs1(x)) ? NaN :
x.context.valueOf(BigDecimalMath.asin(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>acos(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#acos(BigDecimal, MathContext)
*/
public static BigFloat acos(BigFloat x) {
return x.isNaN() || (!isRangeAbs1(x)) ? NaN :
x.context.valueOf(BigDecimalMath.acos(x.value, x.context.mathContext));
}
/**
* @param x a bigfloat
* @return if abs(x) <= 1
*/
private static boolean isRangeAbs1(BigFloat x) {
return isBetween(x.context.NEGATIVE_ONE, x.context.ONE, x);
}
/**
* Returns the {@link BigFloat} that is <code>atan(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#atan(BigDecimal, MathContext)
*/
public static BigFloat atan(BigFloat x) {
return x.isSpecial() || x.isZero() ? x : x.context.valueOf(BigDecimalMath.atan(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>acot(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#acot(BigDecimal, MathContext)
*/
public static BigFloat acot(BigFloat x) {
return x.isSpecial() ? x : x.context.valueOf(BigDecimalMath.acot(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>sinh(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#sinh(BigDecimal, MathContext)
*/
public static BigFloat sinh(BigFloat x) {
if (x.isSpecial() || x.isZero())
return x;
return x.context.valueOf(BigDecimalMath.sinh(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>cosh(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#cosh(BigDecimal, MathContext)
*/
public static BigFloat cosh(BigFloat x) {
if (x.isNaN())
return NaN;
if (x.isInfinity())
return POSITIVE_INFINITY;
if (x.isZero())
return x.context.ONE;
return x.context.valueOf(BigDecimalMath.cosh(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>tanh(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#tanh(BigDecimal, MathContext)
*/
public static BigFloat tanh(BigFloat x) {
if (x.isNaN() || x.isZero())
return x;
if (x.isInfinity())
return x == POSITIVE_INFINITY ? x.context.ONE : x.context.NEGATIVE_ONE;
return x.context.valueOf(BigDecimalMath.tanh(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>coth(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#coth(BigDecimal, MathContext)
*/
public static BigFloat coth(BigFloat x) {
if(x.isSpecial())
return x;
return x.context.valueOf(BigDecimalMath.coth(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>asinh(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#asinh(BigDecimal, MathContext)
*/
public static BigFloat asinh(BigFloat x) {
if(x.isSpecial())
return x;
return x.context.valueOf(BigDecimalMath.asinh(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>acosh(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#acosh(BigDecimal, MathContext)
*/
public static BigFloat acosh(BigFloat x) {
return x.context.valueOf(BigDecimalMath.acosh(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>atanh(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#atanh(BigDecimal, MathContext)
*/
public static BigFloat atanh(BigFloat x) {
if(x.isSpecial())
return x;
return x.context.valueOf(BigDecimalMath.atanh(x.value, x.context.mathContext));
}
/**
* Returns the {@link BigFloat} that is <code>acoth(x)</code>.
*
* @param x the value
*
* @return the resulting {@link BigFloat}
*
* @see BigDecimalMath#acoth(BigDecimal, MathContext)
*/
public static BigFloat acoth(BigFloat x) {
if(x.isSpecial())
return x;
return x.context.valueOf(BigDecimalMath.acoth(x.value, x.context.mathContext));
}
public static boolean isBetween(BigFloat min, BigFloat max, BigFloat value) {
return value.compareTo(min) >= 0 && value.compareTo(max) <= 0;
}
private static Context max(Context left, Context right) {
return left.mathContext.getPrecision() > right.mathContext.getPrecision() ? left : right;
}
}
================================================
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigRational.java
================================================
package ch.obermuhlner.math.big;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
/**
* A rational number represented as a quotient of two values.
*
* <p>Basic calculations with rational numbers (+ - * /) have no loss of precision.
* This allows to use {@link BigRational} as a replacement for {@link BigDecimal} if absolute accuracy is desired.</p>
*
* <p><a href="http://en.wikipedia.org/wiki/Rational_number">Wikipedia: Rational number</a></p>
*
* <p>The values are internally stored as {@link BigDecimal} (for performance optimizations) but represented
* as {@link BigInteger} (for mathematical correctness)
* when accessed with {@link #getNumeratorBigInteger()} and {@link #getDenominatorBigInteger()}.</p>
*
* <p>The following basic calculations have no loss of precision:</p>
* <ul>
* <li>{@link #add(BigRational)}</li>
* <li>{@link #subtract(BigRational)}</li>
* <li>{@link #multiply(BigRational)}</li>
* <li>{@link #divide(BigRational)}</li>
* <li>{@link #pow(int)}</li>
* </ul>
*
* <p>The following calculations are special cases of the ones listed above and have no loss of precision:</p>
* <ul>
* <li>{@link #negate()}</li>
* <li>{@link #reciprocal()}</li>
* <li>{@link #increment()}</li>
* <li>{@link #decrement()}</li>
* </ul>
*
* <p>Any {@link BigRational} value can be converted into an arbitrary {@link #withPrecision(int) precision} (number of significant digits)
* or {@link #withScale(int) scale} (number of digits after the decimal point).</p>
*/
public class BigRational extends Number implements Comparable<BigRational>, Serializable {
/**
* The value 0 as {@link BigRational}.
*/
public static final BigRational ZERO = new BigRational(0);
/**
* The value 1 as {@link BigRational}.
*/
public static final BigRational ONE = new BigRational(1);
/**
* The value 2 as {@link BigRational}.
*/
public static final BigRational TWO = new BigRational(2);
/**
* The value 10 as {@link BigRational}.
*/
public static final BigRational TEN = new BigRational(10);
private final BigDecimal numerator;
private final BigDecimal denominator;
private BigRational(int value) {
this(BigDecimal.valueOf(value), BigDecimal.ONE);
}
private BigRational(BigDecimal num, BigDecimal denom) {
BigDecimal n = num;
BigDecimal d = denom;
if (d.signum() == 0) {
throw new ArithmeticException("Divide by zero");
}
if (d.signum() < 0) {
n = n.negate();
d = d.negate();
}
numerator = n;
denominator = d;
}
/**
* Returns the numerator of this rational number as BigInteger.
*
* @return the numerator as BigInteger
*/
public BigInteger getNumeratorBigInteger() {
return numerator.toBigInteger();
}
/**
* Returns the numerator of this rational number as BigDecimal.
*
* @return the numerator as BigDecimal
*/
public BigDecimal getNumerator() {
return numerator;
}
/**
* Returns the denominator of this rational number as BigInteger.
*
* <p>Guaranteed to not be 0.</p>
* <p>Guaranteed to be positive.</p>
*
* @return the denominator as BigInteger
*/
public BigInteger getDenominatorBigInteger() {
return denominator.toBigInteger();
}
/**
* Returns the denominator of this rational number as BigDecimal.
*
* <p>Guaranteed to not be 0.</p>
* <p>Guaranteed to be positive.</p>
*
* @return the denominator as BigDecimal
*/
public BigDecimal getDenominator() {
return denominator;
}
/**
* Reduces this rational number to the smallest numerator/denominator with the same value.
*
* @return the reduced rational number
*/
public BigRational reduce() {
BigInteger n = numerator.toBigInteger();
BigInteger d = denominator.toBigInteger();
BigInteger gcd = n.gcd(d);
n = n.divide(gcd);
d = d.divide(gcd);
return valueOf(n, d);
}
/**
* Returns the integer part of this rational number.
*
* <p>Examples:</p>
* <ul>
* <li><code>BigRational.valueOf(3.5).integerPart()</code> returns <code>BigRational.valueOf(3)</code></li>
* </ul>
*
* @return the integer part of this rational number
*/
public BigRational integerPart() {
return of(numerator.subtract(numerator.remainder(denominator)), denominator);
}
/**
* Returns the fraction part of this rational number.
*
* <p>Examples:</p>
* <ul>
* <li><code>BigRational.valueOf(3.5).integerPart()</code> returns <code>BigRational.valueOf(0.5)</code></li>
* </ul>
*
* @return the fraction part of this rational number
*/
public BigRational fractionPart() {
return of(numerator.remainder(denominator), denominator);
}
/**
* Negates this rational number (inverting the sign).
*
* <p>The result has no loss of precision.</p>
*
* <p>Examples:</p>
* <ul>
* <li><code>BigRational.valueOf(3.5).negate()</code> returns <code>BigRational.valueOf(-3.5)</code></li>
* </ul>
*
* @return the negated rational number
*/
public BigRational negate() {
if (isZero()) {
return this;
}
return of(numerator.negate(), denominator);
}
/**
* Calculates the reciprocal of this rational number (1/x).
*
* <p>The result has no loss of precision.</p>
*
* <p>Examples:</p>
* <ul>
* <li><code>BigRational.valueOf(0.5).reciprocal()</code> returns <code>BigRational.valueOf(2)</code></li>
* <li><code>BigRational.valueOf(-2).reciprocal()</code> returns <code>BigRational.valueOf(-0.5)</code></li>
* </ul>
*
* @return the reciprocal rational number
* @throws ArithmeticException if this number is 0 (division by zero)
*/
public BigRational reciprocal() {
return of(denominator, numerator);
}
/**
* Returns the absolute value of this rational number.
*
* <p>The result has no loss of precision.</p>
*
* <p>Examples:</p>
* <ul>
* <li><code>BigRational.valueOf(-2).abs()</code> returns <code>BigRational.valueOf(2)</code></li>
* <li><code>BigRational.valueOf(2).abs()</code> returns <code>BigRational.valueOf(2)</code></li>
* </ul>
*
* @return the absolute rational number (positive, or 0 if this rational is 0)
*/
public BigRational abs() {
return isPositive() ? this : negate();
}
/**
* Returns the signum function of this rational number.
*
* @return -1, 0 or 1 as the value of this rational number is negative, zero or positive.
*/
public int signum() {
return numerator.signum();
}
/**
* Calculates the increment of this rational number (+ 1).
*
* <p>This is functionally identical to
* <code>this.add(BigRational.ONE)</code>
* but slightly faster.</p>
*
* <p>The result has no loss of precision.</p>
*
* @return the incremented rational number
*/
public BigRational increment() {
return of(numerator.add(denominator), denominator);
}
/**
* Calculates the decrement of this rational number (- 1).
*
* <p>This is functionally identical to
* <code>this.subtract(BigRational.ONE)</code>
* but slightly faster.</p>
*
* <p>The result has no loss of precision.</p>
*
* @return the decremented rational number
*/
public BigRational decrement() {
return of(numerator.subtract(denominator), denominator);
}
/**
* Calculates the addition (+) of this rational number and the specified argument.
*
* <p>The result has no loss of precision.</p>
*
* @param value the rational number to add
* @return the resulting rational number
*/
public BigRational add(BigRational value) {
if (denominator.compareTo(value.denominator) == 0) {
return of(numerator.add(value.numerator), denominator);
}
BigDecimal n = numerator.multiply(value.denominator).add(value.numerator.multiply(denominator));
BigDecimal d = denominator.multiply(value.denominator);
return of(n, d);
}
private BigRational add(BigDecimal value) {
return of(numerator.add(value.multiply(denominator)), denominator);
}
/**
* Calculates the addition (+) of this rational number and the specified argument.
*
* <p>This is functionally identical to
* <code>this.add(BigRational.valueOf(value))</code>
* but slightly faster.</p>
*
* <p>The result has no loss of precision.</p>
*
* @param value the {@link BigInteger} to add
* @return the resulting rational number
*/
public BigRational add(BigInteger value) {
if (value.equals(BigInteger.ZERO)) {
return this;
}
return add(new BigDecimal(value));
}
/**
* Calculates the addition (+) of this rational number and the specified argument.
*
* <p>This is functionally identical to
* <code>this.add(BigRational.valueOf(value))</code>
* but slightly faster.</p>
*
* <p>The result has no loss of precision.</p>
*
* @param value the int value to add
* @return the resulting rational number
*/
public BigRational add(int value) {
if (value == 0) {
return this;
}
return add(BigInteger.valueOf(value));
}
/**
* Calculates the subtraction (-) of this rational number and the specified argument.
*
* <p>The result has no loss of precision.</p>
*
* @param value the rational number to subtract
* @return the resulting rational number
*/
public BigRational subtract(BigRational value) {
if (denominator.compareTo(value.denominator) == 0) {
return of(numerator.subtract(value.numerator), denominator);
}
BigDecimal n = numerator.multiply(value.denominator).subtract(value.numerator.multiply(denominator));
BigDecimal d = denominator.multiply(value.denominator);
return of(n, d);
}
private BigRational subtract(BigDecimal value) {
return of(numerator.subtract(value.multiply(denominator)), denominator);
}
/**
* Calculates the subtraction (-) of this rational number and the specified argument.
*
* <p>This is functionally identical to
* <code>this.subtract(BigRational.valueOf(value))</code>
* but slightly faster.</p>
*
* <p>The result has no loss of precision.</p>
*
* @param value the {@link BigInteger} to subtract
* @return the resulting rational number
*/
public BigRational subtract(BigInteger value) {
if (value.equals(BigInteger.ZERO)) {
return this;
}
return subtract(new BigDecimal(value));
}
/**
* Calculates the subtraction (-) of this rational number and the specified argument.
*
* <p>This is functionally identical to
* <code>this.subtract(BigRational.valueOf(value))</code>
* but slightly faster.</p>
*
* <p>The result has no loss of precision.</p>
*
* @param value the int value to subtract
* @return the resulting rational number
*/
public BigRational subtract(int value) {
if (value == 0) {
return this;
}
return subtract(BigInteger.valueOf(value));
}
/**
* Calculates the multiplication (*) of this rational number and the specified argument.
*
* <p>The result has no loss of precision.</p>
*
* @param value the rational number to multiply
* @return the resulting rational number
*/
public BigRational multiply(BigRational value) {
if (isZero() || value.isZero()) {
return ZERO;
}
if (equals(ONE)) {
return value;
}
if (value.equals(ONE)) {
return this;
}
BigDecimal n = numerator.multiply(value.numerator);
BigDecimal d = denominator.multiply(value.denominator);
return of(n, d);
}
// private, because we want to hide that we use BigDecimal internally
private BigRational multiply(BigDecimal value) {
BigDecimal n = numerator.multiply(value);
BigDecimal d = denominator;
return of(n, d);
}
/**
* Calculates the multiplication (*) of this rational number and the specified argument.
*
* <p>This is functionally identical to
* <code>this.multiply(BigRational.valueOf(value))</code>
* but slightly faster.</p>
*
* <p>The result has no loss of precision.</p>
*
* @param value the {@link BigInteger} to multiply
* @return the resulting rational number
*/
public BigRational multiply(BigInteger value) {
if (isZero() || value.signum() == 0) {
return ZERO;
}
if (equals(ONE)) {
return valueOf(value);
}
if (value.equals(BigInteger.ONE)) {
return this;
}
return multiply(new BigDecimal(value));
}
/**
* Calculates the multiplication (*) of this rational number and the specified argument.
*
* <p>This is functionally identical to
* <code>this.multiply(BigRational.valueOf(value))</code>
* but slightly faster.</p>
*
* <p>The result has no loss of precision.</p>
*
* @param value the int value to multiply
* @return the resulting rational number
*/
public BigRational multiply(int value) {
return multiply(BigInteger.valueOf(value));
}
/**
* Calculates the division (/) of this rational number and the specified argument.
*
* <p>The result has no loss of precision.</p>
*
* @param value the rational number to divide (0 is not allowed)
* @return the resulting rational number
* @throws ArithmeticException if the argument is 0 (division by zero)
*/
public BigRational divide(BigRational value) {
if (value.equals(ONE)) {
return this;
}
BigDecimal n = numerator.multiply(value.denominator);
BigDecimal d = denominator.multiply(value.numerator);
return of(n, d);
}
private BigRational divide(BigDecimal value)
gitextract_36f9jpuf/ ├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── README.md ├── build.gradle ├── ch.obermuhlner.math.big/ │ ├── build.gradle │ └── src/ │ ├── main/ │ │ └── java/ │ │ └── ch/ │ │ └── obermuhlner/ │ │ └── math/ │ │ └── big/ │ │ ├── BigComplex.java │ │ ├── BigComplexMath.java │ │ ├── BigDecimalMath.java │ │ ├── BigFloat.java │ │ ├── BigRational.java │ │ ├── DefaultBigDecimalMath.java │ │ ├── internal/ │ │ │ ├── AsinCalculator.java │ │ │ ├── AtanhCalculator.java │ │ │ ├── CosCalculator.java │ │ │ ├── CoshCalculator.java │ │ │ ├── ExpCalculator.java │ │ │ ├── PowerIterator.java │ │ │ ├── PowerNIterator.java │ │ │ ├── PowerTwoNIterator.java │ │ │ ├── PowerTwoNMinusOneIterator.java │ │ │ ├── PowerTwoNPlusOneIterator.java │ │ │ ├── SeriesCalculator.java │ │ │ ├── SinCalculator.java │ │ │ └── SinhCalculator.java │ │ └── stream/ │ │ ├── BigDecimalStream.java │ │ └── BigFloatStream.java │ └── test/ │ └── java/ │ └── ch/ │ └── obermuhlner/ │ ├── math/ │ │ └── big/ │ │ ├── BigComplexMathTest.java │ │ ├── BigComplexTest.java │ │ ├── BigDecimalMathTest.java │ │ ├── BigFloatTest.java │ │ ├── BigRationalTest.java │ │ ├── DefaultBigDecimalMathTest.java │ │ └── stream/ │ │ ├── BigDecimalStreamTest.java │ │ └── BigFloatStreamTest.java │ └── util/ │ └── ThreadUtil.java ├── ch.obermuhlner.math.big.example/ │ ├── build.gradle │ ├── docu/ │ │ ├── benchmarks/ │ │ │ ├── csv2chart.properties │ │ │ ├── perf_adaptive_log_precisions_to_1000.csv │ │ │ ├── perf_atan2_y_5_x_from_-10_to_10.csv │ │ │ ├── perf_atan2_y_from_-10_to_10_x_5.csv │ │ │ ├── perf_atan2_yx_from_-10_to_10.csv │ │ │ ├── perf_atan2_yx_from_-10_to_10.properties │ │ │ ├── perf_atanh_funcs_from_-1_to_1_impl.csv │ │ │ ├── perf_basic_operations_fast_precisions_to_10000.csv │ │ │ ├── perf_basic_operations_fast_precisions_to_100000.csv │ │ │ ├── perf_basic_operations_slow2_precisions_to_10000.csv │ │ │ ├── perf_basic_operations_slow2_precisions_to_100000.csv │ │ │ ├── perf_basic_operations_slow_precisions_to_10000.csv │ │ │ ├── perf_basic_operations_slow_precisions_to_100000.csv │ │ │ ├── perf_bigdec_string_impl_precisions_to_10000.csv │ │ │ ├── perf_bigdec_string_impl_precisions_to_100000.csv │ │ │ ├── perf_bigdec_string_impl_precisions_to_2000.csv │ │ │ ├── perf_bigdec_string_precisions_to_10000.csv │ │ │ ├── perf_bigdec_string_precisions_to_100000.csv │ │ │ ├── perf_bigdec_string_precisions_to_1000000.csv │ │ │ ├── perf_bigdec_string_precisions_to_2000.csv │ │ │ ├── perf_cos_funcs_from_0_to_3.csv │ │ │ ├── perf_exp_funcs_from_0_to_1.csv │ │ │ ├── perf_exp_funcs_from_0_to_10.csv │ │ │ ├── perf_exp_funcs_from_0_to_3.csv │ │ │ ├── perf_factorial_impl_loops_values_to_1000.csv │ │ │ ├── perf_factorial_impl_recursion_values_to_100.csv │ │ │ ├── perf_factorial_impl_recursion_values_to_1000.csv │ │ │ ├── perf_factorial_impl_values_to_100.csv │ │ │ ├── perf_factorial_impl_values_to_1000.csv │ │ │ ├── perf_factorial_impl_values_to_200.csv │ │ │ ├── perf_factorial_impl_values_to_500.csv │ │ │ ├── perf_fast_funcs_from_-10_to_10.csv │ │ │ ├── perf_fast_funcs_from_0_to_10.csv │ │ │ ├── perf_fast_funcs_from_0_to_100.csv │ │ │ ├── perf_fast_funcs_from_0_to_2.csv │ │ │ ├── perf_fast_funcs_precisions_to_1000.csv │ │ │ ├── perf_hyperbolic_funcs_from_0_to_2.csv │ │ │ ├── perf_java9_sqrt_from_0_to_10.csv │ │ │ ├── perf_java9_sqrt_from_0_to_100.csv │ │ │ ├── perf_java9_sqrt_from_0_to_10000.csv │ │ │ ├── perf_java9_sqrt_precisions_to_1000.csv │ │ │ ├── perf_java9_sqrt_precisions_to_10000.csv │ │ │ ├── perf_java9_sqrt_precisions_to_200.csv │ │ │ ├── perf_log_from_0_to_100000.csv │ │ │ ├── perf_pow_frac_from_0_to_1000.csv │ │ │ ├── perf_pow_from_0_to_100.csv │ │ │ ├── perf_pow_int_from_0_to_10000.csv │ │ │ ├── perf_pow_int_from_0_to_100000.csv │ │ │ ├── perf_sin_funcs_from_0_to_3.csv │ │ │ ├── perf_slow_funcs_from_-10_to_10.csv │ │ │ ├── perf_slow_funcs_from_0_to_10.csv │ │ │ ├── perf_slow_funcs_from_0_to_100.csv │ │ │ ├── perf_slow_funcs_from_0_to_1000.csv │ │ │ ├── perf_slow_funcs_from_0_to_2.csv │ │ │ ├── perf_slow_funcs_precisions_to_1000.csv │ │ │ ├── perf_trigo_funcs_from_0_to_1.csv │ │ │ ├── regression/ │ │ │ │ ├── after_fewer_mc.csv │ │ │ │ ├── before after fewer mc optimization.csv │ │ │ │ ├── before_fewer_mc.csv │ │ │ │ ├── v1.0.0.csv │ │ │ │ ├── v1.1.0.csv │ │ │ │ └── v1.2.0.csv │ │ │ ├── test_asin_impl_from_0_to_1.csv │ │ │ ├── test_exp_impl_from_0_to_4.csv │ │ │ ├── test_log_adaptive_impl_from_0_to_10.csv │ │ │ ├── test_log_impl_from_0_to_10.csv │ │ │ ├── test_log_impl_from_0_to_100.csv │ │ │ ├── test_root_impl_from_0_to_10.csv │ │ │ ├── test_sqrt_impl_from_0_to_1.csv │ │ │ ├── test_sqrt_impl_from_0_to_100.csv │ │ │ ├── test_sqrt_impl_from_0_to_1000.csv │ │ │ ├── values_atan2_yx_from_-10_to_10.csv │ │ │ └── values_atan2_yx_from_-10_to_10.properties │ │ ├── tables/ │ │ │ └── bernoulli.csv │ │ └── wordpress/ │ │ ├── AdaptiveNewton.txt │ │ └── BigDecimalMath.txt │ └── src/ │ └── main/ │ └── java/ │ └── ch/ │ └── obermuhlner/ │ └── math/ │ └── big/ │ └── example/ │ ├── BernoulliTable.java │ ├── BigDecimalMathExample.java │ ├── BigFloatExample.java │ ├── DefaultBigDecimalMathExample.java │ ├── FunctionTable.java │ ├── HighPrecisionMath.java │ ├── PiExample.java │ ├── StopWatch.java │ ├── internal/ │ │ ├── AggregateCsv.java │ │ ├── BigDecimalExperiments.java │ │ ├── BigDecimalMathExperimental.java │ │ ├── GammaExperiments.java │ │ ├── PerformanceBigDecimalMath.java │ │ ├── PerformanceRegressionBigDecimalMath.java │ │ └── SqrtExperiments.java │ └── stream/ │ ├── BigDecimalStreamExample.java │ └── BigFloatStreamExample.java ├── docs/ │ ├── _config.yml │ ├── index.md │ ├── javadoc/ │ │ ├── v1.3.0/ │ │ │ ├── META-INF/ │ │ │ │ └── MANIFEST.MF │ │ │ ├── allclasses-frame.html │ │ │ ├── allclasses-noframe.html │ │ │ ├── ch/ │ │ │ │ └── obermuhlner/ │ │ │ │ └── math/ │ │ │ │ └── big/ │ │ │ │ ├── BigDecimalMath.html │ │ │ │ ├── BigFloat.Context.html │ │ │ │ ├── BigFloat.html │ │ │ │ ├── BigRational.html │ │ │ │ ├── internal/ │ │ │ │ │ ├── AsinCalculator.html │ │ │ │ │ ├── CosCalculator.html │ │ │ │ │ ├── CoshCalculator.html │ │ │ │ │ ├── ExpCalculator.html │ │ │ │ │ ├── PowerIterator.html │ │ │ │ │ ├── PowerNIterator.html │ │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ │ ├── SeriesCalculator.html │ │ │ │ │ ├── SinCalculator.html │ │ │ │ │ ├── SinhCalculator.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── stream/ │ │ │ │ ├── BigDecimalStream.html │ │ │ │ ├── BigFloatStream.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── constant-values.html │ │ │ ├── deprecated-list.html │ │ │ ├── help-doc.html │ │ │ ├── index-all.html │ │ │ ├── index.html │ │ │ ├── overview-frame.html │ │ │ ├── overview-summary.html │ │ │ ├── overview-tree.html │ │ │ ├── package-list │ │ │ ├── script.js │ │ │ └── stylesheet.css │ │ ├── v2.0.0/ │ │ │ ├── allclasses-frame.html │ │ │ ├── allclasses-noframe.html │ │ │ ├── ch/ │ │ │ │ └── obermuhlner/ │ │ │ │ └── math/ │ │ │ │ └── big/ │ │ │ │ ├── BigComplex.html │ │ │ │ ├── BigComplexMath.html │ │ │ │ ├── BigDecimalMath.html │ │ │ │ ├── BigFloat.Context.html │ │ │ │ ├── BigFloat.html │ │ │ │ ├── BigRational.html │ │ │ │ ├── internal/ │ │ │ │ │ ├── AsinCalculator.html │ │ │ │ │ ├── CosCalculator.html │ │ │ │ │ ├── CoshCalculator.html │ │ │ │ │ ├── ExpCalculator.html │ │ │ │ │ ├── PowerIterator.html │ │ │ │ │ ├── PowerNIterator.html │ │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ │ ├── SeriesCalculator.html │ │ │ │ │ ├── SinCalculator.html │ │ │ │ │ ├── SinhCalculator.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── stream/ │ │ │ │ ├── BigDecimalStream.html │ │ │ │ ├── BigFloatStream.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── constant-values.html │ │ │ ├── deprecated-list.html │ │ │ ├── help-doc.html │ │ │ ├── index-all.html │ │ │ ├── index.html │ │ │ ├── overview-frame.html │ │ │ ├── overview-summary.html │ │ │ ├── overview-tree.html │ │ │ ├── package-list │ │ │ ├── script.js │ │ │ └── stylesheet.css │ │ ├── v2.0.1/ │ │ │ ├── allclasses-frame.html │ │ │ ├── allclasses-noframe.html │ │ │ ├── ch/ │ │ │ │ └── obermuhlner/ │ │ │ │ └── math/ │ │ │ │ └── big/ │ │ │ │ ├── BigComplex.html │ │ │ │ ├── BigComplexMath.html │ │ │ │ ├── BigDecimalMath.html │ │ │ │ ├── BigFloat.Context.html │ │ │ │ ├── BigFloat.html │ │ │ │ ├── BigRational.html │ │ │ │ ├── internal/ │ │ │ │ │ ├── AsinCalculator.html │ │ │ │ │ ├── CosCalculator.html │ │ │ │ │ ├── CoshCalculator.html │ │ │ │ │ ├── ExpCalculator.html │ │ │ │ │ ├── PowerIterator.html │ │ │ │ │ ├── PowerNIterator.html │ │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ │ ├── SeriesCalculator.html │ │ │ │ │ ├── SinCalculator.html │ │ │ │ │ ├── SinhCalculator.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── stream/ │ │ │ │ ├── BigDecimalStream.html │ │ │ │ ├── BigFloatStream.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── constant-values.html │ │ │ ├── deprecated-list.html │ │ │ ├── help-doc.html │ │ │ ├── index-all.html │ │ │ ├── index.html │ │ │ ├── overview-frame.html │ │ │ ├── overview-summary.html │ │ │ ├── overview-tree.html │ │ │ ├── package-list │ │ │ ├── script.js │ │ │ └── stylesheet.css │ │ ├── v2.1.0/ │ │ │ ├── allclasses-frame.html │ │ │ ├── allclasses-noframe.html │ │ │ ├── ch/ │ │ │ │ └── obermuhlner/ │ │ │ │ └── math/ │ │ │ │ └── big/ │ │ │ │ ├── BigComplex.html │ │ │ │ ├── BigComplexMath.html │ │ │ │ ├── BigDecimalMath.html │ │ │ │ ├── BigFloat.Context.html │ │ │ │ ├── BigFloat.html │ │ │ │ ├── BigRational.html │ │ │ │ ├── DefaultBigDecimalMath.html │ │ │ │ ├── internal/ │ │ │ │ │ ├── AsinCalculator.html │ │ │ │ │ ├── AtanhCalculator.html │ │ │ │ │ ├── CosCalculator.html │ │ │ │ │ ├── CoshCalculator.html │ │ │ │ │ ├── ExpCalculator.html │ │ │ │ │ ├── PowerIterator.html │ │ │ │ │ ├── PowerNIterator.html │ │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ │ ├── PowerTwoNMinusOneIterator.html │ │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ │ ├── SeriesCalculator.html │ │ │ │ │ ├── SinCalculator.html │ │ │ │ │ ├── SinhCalculator.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── stream/ │ │ │ │ ├── BigDecimalStream.html │ │ │ │ ├── BigFloatStream.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── constant-values.html │ │ │ ├── deprecated-list.html │ │ │ ├── help-doc.html │ │ │ ├── index-all.html │ │ │ ├── index.html │ │ │ ├── overview-frame.html │ │ │ ├── overview-summary.html │ │ │ ├── overview-tree.html │ │ │ ├── package-list │ │ │ ├── script.js │ │ │ └── stylesheet.css │ │ ├── v2.2.0/ │ │ │ ├── allclasses-frame.html │ │ │ ├── allclasses-noframe.html │ │ │ ├── ch/ │ │ │ │ └── obermuhlner/ │ │ │ │ └── math/ │ │ │ │ └── big/ │ │ │ │ ├── BigComplex.html │ │ │ │ ├── BigComplexMath.html │ │ │ │ ├── BigDecimalMath.html │ │ │ │ ├── BigFloat.Context.html │ │ │ │ ├── BigFloat.html │ │ │ │ ├── BigRational.html │ │ │ │ ├── DefaultBigDecimalMath.html │ │ │ │ ├── internal/ │ │ │ │ │ ├── AsinCalculator.html │ │ │ │ │ ├── AtanhCalculator.html │ │ │ │ │ ├── CosCalculator.html │ │ │ │ │ ├── CoshCalculator.html │ │ │ │ │ ├── ExpCalculator.html │ │ │ │ │ ├── PowerIterator.html │ │ │ │ │ ├── PowerNIterator.html │ │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ │ ├── PowerTwoNMinusOneIterator.html │ │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ │ ├── SeriesCalculator.html │ │ │ │ │ ├── SinCalculator.html │ │ │ │ │ ├── SinhCalculator.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── stream/ │ │ │ │ ├── BigDecimalStream.html │ │ │ │ ├── BigFloatStream.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── constant-values.html │ │ │ ├── deprecated-list.html │ │ │ ├── help-doc.html │ │ │ ├── index-all.html │ │ │ ├── index.html │ │ │ ├── overview-frame.html │ │ │ ├── overview-summary.html │ │ │ ├── overview-tree.html │ │ │ ├── package-list │ │ │ ├── script.js │ │ │ ├── serialized-form.html │ │ │ └── stylesheet.css │ │ ├── v2.2.1/ │ │ │ ├── META-INF/ │ │ │ │ └── MANIFEST.MF │ │ │ ├── allclasses-frame.html │ │ │ ├── allclasses-noframe.html │ │ │ ├── ch/ │ │ │ │ └── obermuhlner/ │ │ │ │ └── math/ │ │ │ │ └── big/ │ │ │ │ ├── BigComplex.html │ │ │ │ ├── BigComplexMath.html │ │ │ │ ├── BigDecimalMath.html │ │ │ │ ├── BigFloat.Context.html │ │ │ │ ├── BigFloat.html │ │ │ │ ├── BigRational.html │ │ │ │ ├── DefaultBigDecimalMath.html │ │ │ │ ├── internal/ │ │ │ │ │ ├── AsinCalculator.html │ │ │ │ │ ├── AtanhCalculator.html │ │ │ │ │ ├── CosCalculator.html │ │ │ │ │ ├── CoshCalculator.html │ │ │ │ │ ├── ExpCalculator.html │ │ │ │ │ ├── PowerIterator.html │ │ │ │ │ ├── PowerNIterator.html │ │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ │ ├── PowerTwoNMinusOneIterator.html │ │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ │ ├── SeriesCalculator.html │ │ │ │ │ ├── SinCalculator.html │ │ │ │ │ ├── SinhCalculator.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── stream/ │ │ │ │ ├── BigDecimalStream.html │ │ │ │ ├── BigFloatStream.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── constant-values.html │ │ │ ├── deprecated-list.html │ │ │ ├── help-doc.html │ │ │ ├── index-all.html │ │ │ ├── index.html │ │ │ ├── overview-frame.html │ │ │ ├── overview-summary.html │ │ │ ├── overview-tree.html │ │ │ ├── package-list │ │ │ ├── script.js │ │ │ ├── serialized-form.html │ │ │ └── stylesheet.css │ │ ├── v2.3.0/ │ │ │ ├── allclasses-frame.html │ │ │ ├── allclasses-noframe.html │ │ │ ├── ch/ │ │ │ │ └── obermuhlner/ │ │ │ │ └── math/ │ │ │ │ └── big/ │ │ │ │ ├── BigComplex.html │ │ │ │ ├── BigComplexMath.html │ │ │ │ ├── BigDecimalMath.html │ │ │ │ ├── BigFloat.Context.html │ │ │ │ ├── BigFloat.html │ │ │ │ ├── BigRational.html │ │ │ │ ├── DefaultBigDecimalMath.LocalMathContext.html │ │ │ │ ├── DefaultBigDecimalMath.html │ │ │ │ ├── internal/ │ │ │ │ │ ├── AsinCalculator.html │ │ │ │ │ ├── AtanhCalculator.html │ │ │ │ │ ├── CosCalculator.html │ │ │ │ │ ├── CoshCalculator.html │ │ │ │ │ ├── ExpCalculator.html │ │ │ │ │ ├── PowerIterator.html │ │ │ │ │ ├── PowerNIterator.html │ │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ │ ├── PowerTwoNMinusOneIterator.html │ │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ │ ├── SeriesCalculator.html │ │ │ │ │ ├── SinCalculator.html │ │ │ │ │ ├── SinhCalculator.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── stream/ │ │ │ │ ├── BigDecimalStream.html │ │ │ │ ├── BigFloatStream.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── constant-values.html │ │ │ ├── deprecated-list.html │ │ │ ├── help-doc.html │ │ │ ├── index-all.html │ │ │ ├── index.html │ │ │ ├── overview-frame.html │ │ │ ├── overview-summary.html │ │ │ ├── overview-tree.html │ │ │ ├── package-list │ │ │ ├── script.js │ │ │ ├── serialized-form.html │ │ │ └── stylesheet.css │ │ ├── v2.3.1/ │ │ │ ├── allclasses-frame.html │ │ │ ├── allclasses-noframe.html │ │ │ ├── ch/ │ │ │ │ └── obermuhlner/ │ │ │ │ └── math/ │ │ │ │ └── big/ │ │ │ │ ├── BigComplex.html │ │ │ │ ├── BigComplexMath.html │ │ │ │ ├── BigDecimalMath.html │ │ │ │ ├── BigFloat.Context.html │ │ │ │ ├── BigFloat.html │ │ │ │ ├── BigRational.html │ │ │ │ ├── DefaultBigDecimalMath.LocalMathContext.html │ │ │ │ ├── DefaultBigDecimalMath.html │ │ │ │ ├── analysis/ │ │ │ │ │ └── solver/ │ │ │ │ │ ├── BisectionSolver.html │ │ │ │ │ ├── NewtonRaphsonSolver.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── internal/ │ │ │ │ │ ├── AsinCalculator.html │ │ │ │ │ ├── AtanhCalculator.html │ │ │ │ │ ├── CosCalculator.html │ │ │ │ │ ├── CoshCalculator.html │ │ │ │ │ ├── ExpCalculator.html │ │ │ │ │ ├── PowerIterator.html │ │ │ │ │ ├── PowerNIterator.html │ │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ │ ├── PowerTwoNMinusOneIterator.html │ │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ │ ├── SeriesCalculator.html │ │ │ │ │ ├── SinCalculator.html │ │ │ │ │ ├── SinhCalculator.html │ │ │ │ │ ├── package-frame.html │ │ │ │ │ ├── package-summary.html │ │ │ │ │ └── package-tree.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── stream/ │ │ │ │ ├── BigDecimalStream.html │ │ │ │ ├── BigFloatStream.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── constant-values.html │ │ │ ├── deprecated-list.html │ │ │ ├── help-doc.html │ │ │ ├── index-all.html │ │ │ ├── index.html │ │ │ ├── overview-frame.html │ │ │ ├── overview-summary.html │ │ │ ├── overview-tree.html │ │ │ ├── package-list │ │ │ ├── script.js │ │ │ ├── serialized-form.html │ │ │ └── stylesheet.css │ │ └── v2.3.2/ │ │ ├── allclasses-frame.html │ │ ├── allclasses-noframe.html │ │ ├── ch/ │ │ │ └── obermuhlner/ │ │ │ └── math/ │ │ │ └── big/ │ │ │ ├── BigComplex.html │ │ │ ├── BigComplexMath.html │ │ │ ├── BigDecimalMath.html │ │ │ ├── BigFloat.Context.html │ │ │ ├── BigFloat.html │ │ │ ├── BigRational.html │ │ │ ├── DefaultBigDecimalMath.LocalMathContext.html │ │ │ ├── DefaultBigDecimalMath.html │ │ │ ├── internal/ │ │ │ │ ├── AsinCalculator.html │ │ │ │ ├── AtanhCalculator.html │ │ │ │ ├── CosCalculator.html │ │ │ │ ├── CoshCalculator.html │ │ │ │ ├── ExpCalculator.html │ │ │ │ ├── PowerIterator.html │ │ │ │ ├── PowerNIterator.html │ │ │ │ ├── PowerTwoNIterator.html │ │ │ │ ├── PowerTwoNMinusOneIterator.html │ │ │ │ ├── PowerTwoNPlusOneIterator.html │ │ │ │ ├── SeriesCalculator.html │ │ │ │ ├── SinCalculator.html │ │ │ │ ├── SinhCalculator.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ └── package-tree.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── stream/ │ │ │ ├── BigDecimalStream.html │ │ │ ├── BigFloatStream.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ └── package-tree.html │ │ ├── constant-values.html │ │ ├── deprecated-list.html │ │ ├── help-doc.html │ │ ├── index-all.html │ │ ├── index.html │ │ ├── overview-frame.html │ │ ├── overview-summary.html │ │ ├── overview-tree.html │ │ ├── package-list │ │ ├── script.js │ │ ├── serialized-form.html │ │ └── stylesheet.css │ ├── markdown/ │ │ ├── atan2.md │ │ └── gamma/ │ │ ├── csv2chart.properties │ │ ├── factorial_calculating_spouge_constants.csv │ │ ├── factorial_calculating_spouge_constants.properties │ │ ├── factorial_spouge_cached_prec200.csv │ │ ├── factorial_spouge_cached_prec200.properties │ │ ├── factorial_spouge_cached_precisions.csv │ │ ├── factorial_spouge_cached_precisions.properties │ │ ├── factorial_spouge_prec200.csv │ │ ├── factorial_spouge_prec200.properties │ │ ├── factorial_spouge_precision.csv │ │ ├── factorial_spouge_precision.properties │ │ └── gamma.md │ └── releases/ │ ├── next_release_note.md │ ├── template_release_note.md │ ├── v1.0-beta1.md │ ├── v1.0-beta2.md │ ├── v1.0.0.md │ ├── v1.1.0.md │ ├── v1.2.0.md │ ├── v1.2.1.md │ ├── v1.3.0.md │ ├── v2.0.0.md │ ├── v2.0.1.md │ ├── v2.1.0.md │ ├── v2.2.0.md │ ├── v2.2.1.md │ ├── v2.3.0.md │ ├── v2.3.1.md │ └── v2.3.2.md ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pom.xml ├── regression/ │ ├── README.md │ ├── analysis/ │ │ ├── build.gradle │ │ ├── fast functions performance over releases.csv │ │ ├── medium functions performance over releases.csv │ │ ├── multi threading fix.csv │ │ ├── performance over releases.csv │ │ ├── selected functions performance over releases.csv │ │ ├── slow functions performance over releases.csv │ │ └── very slow functions performance over releases.csv │ ├── v1_0_0/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v1_1_0/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v1_2_0/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v1_2_1/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v1_3_0/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v2_0_0/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v2_0_1/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v2_1_0/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v2_2_0/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v2_2_1/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v2_3_0/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v2_3_1/ │ │ ├── build.gradle │ │ └── performance.csv │ ├── v2_3_2/ │ │ ├── build.gradle │ │ └── performance.csv │ └── v_current/ │ ├── build.gradle │ └── performance.csv ├── run_regression_analysis.sh └── settings.gradle
SYMBOL INDEX (1218 symbols across 56 files)
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/BernoulliTable.java
class BernoulliTable (line 5) | public class BernoulliTable {
method main (line 7) | public static void main(String[] args) {
method printBernoulliTableSimple (line 12) | private static void printBernoulliTableSimple(int n) {
method printBernoulliTableHtml (line 20) | private static void printBernoulliTableHtml(int n) {
method printBernoulliTableHtml2 (line 37) | private static void printBernoulliTableHtml2(int n) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/BigDecimalMathExample.java
class BigDecimalMathExample (line 8) | public class BigDecimalMathExample {
method main (line 10) | public static void main(String[] args) {
method exampleForDocu (line 16) | public static void exampleForDocu() {
method exampleForJavaDoc_roundTrailingZeroes (line 59) | private static void exampleForJavaDoc_roundTrailingZeroes() {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/BigFloatExample.java
class BigFloatExample (line 8) | public class BigFloatExample {
method main (line 10) | public static void main(String[] args) {
method examplePi (line 14) | private static void examplePi() {
method piChudnovski (line 18) | private static BigFloat piChudnovski(int precision) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/DefaultBigDecimalMathExample.java
class DefaultBigDecimalMathExample (line 11) | public class DefaultBigDecimalMathExample {
method main (line 12) | public static void main(String[] args) {
method runDefaultExample (line 22) | private static void runDefaultExample() {
method runPiChudnovskyExample (line 26) | private static void runPiChudnovskyExample() {
method piChudnovsky (line 37) | private static BigDecimal piChudnovsky() {
method piChudnovskyMixedArithmetic (line 76) | private static BigDecimal piChudnovskyMixedArithmetic() {
method runCreateLocalMathContextExample (line 115) | private static void runCreateLocalMathContextExample() {
method runWithLocalMathContextExample (line 127) | private static void runWithLocalMathContextExample() {
method runWithLocalMathContextCompactExample (line 139) | private static void runWithLocalMathContextCompactExample() {
method runWithLocalMathContextParallelBadExample (line 151) | private static void runWithLocalMathContextParallelBadExample() {
method runWithLocalMathContextParallelGoodExample (line 166) | private static void runWithLocalMathContextParallelGoodExample() {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/FunctionTable.java
class FunctionTable (line 14) | public class FunctionTable {
method main (line 16) | public static void main(String[] args) {
method printTableLog (line 26) | public static void printTableLog() {
method printTableLog10 (line 41) | public static void printTableLog10() {
method printTableExp (line 56) | public static void printTableExp() {
method printTableSin (line 71) | public static void printTableSin() {
method printTableAsin (line 86) | public static void printTableAsin() {
method printTableAcos (line 101) | public static void printTableAcos() {
method printTableAtan (line 116) | public static void printTableAtan() {
method printTable (line 131) | private static void printTable(
method printTable (line 140) | private static void printTable(
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/HighPrecisionMath.java
class HighPrecisionMath (line 11) | public class HighPrecisionMath {
method pow (line 16) | public static BigDecimal pow(BigDecimal x, BigDecimal y) {
method sin (line 20) | public static BigDecimal sin(BigDecimal x) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/PiExample.java
class PiExample (line 11) | public class PiExample {
method main (line 13) | public static void main(String[] args) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/StopWatch.java
class StopWatch (line 3) | public class StopWatch {
method StopWatch (line 6) | public StopWatch() {
method start (line 10) | public void start() {
method getElapsedSeconds (line 15) | public double getElapsedSeconds() {
method getElapsedMillis (line 19) | public long getElapsedMillis() {
method getElapsedNanos (line 23) | public long getElapsedNanos() {
method toString (line 28) | @Override
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/AggregateCsv.java
class AggregateCsv (line 7) | public class AggregateCsv {
method run (line 8) | public void run(String outFileName, String filePattern, List<String> r...
method main (line 68) | public static void main(String[] args) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/BigDecimalExperiments.java
class BigDecimalExperiments (line 9) | public class BigDecimalExperiments {
method main (line 10) | public static void main(String[] args) {
method experimentExponents (line 15) | private static void experimentExponents() {
method experimentRounding (line 26) | public static void experimentRounding() {
method print (line 102) | public static void print(BigDecimal value) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/BigDecimalMathExperimental.java
class BigDecimalMathExperimental (line 21) | public class BigDecimalMathExperimental {
method BigDecimalMathExperimental (line 32) | private BigDecimalMathExperimental() {
method main (line 36) | public static void main(String[] args) {
method printFactorial (line 41) | private static void printFactorial() {
method printSqrtConvergence (line 47) | private static void printSqrtConvergence() {
method exp (line 65) | public static BigDecimal exp(BigDecimal x, MathContext mathContext) {
method expReducing (line 73) | public static BigDecimal expReducing(BigDecimal x, MathContext mathCon...
method asinUsingNewton (line 85) | public static BigDecimal asinUsingNewton(BigDecimal x, MathContext mat...
method asin (line 129) | public static BigDecimal asin(BigDecimal x, MathContext mathContext) {
method acos (line 152) | public static BigDecimal acos(BigDecimal x, MathContext mathContext) {
method acosUsingNewton (line 166) | public static BigDecimal acosUsingNewton(BigDecimal x, MathContext mat...
method sqrtUsingNewtonPrint (line 182) | public static BigDecimal sqrtUsingNewtonPrint(BigDecimal x, MathContex...
method sqrtUsingNewtonAdaptivePrecisionPrint (line 205) | public static BigDecimal sqrtUsingNewtonAdaptivePrecisionPrint(BigDeci...
method countSameCharacters (line 235) | private static Object countSameCharacters(String string1, String strin...
method sqrtUsingNewton (line 245) | public static BigDecimal sqrtUsingNewton(BigDecimal x, MathContext mat...
method sqrtUsingNewtonAdaptivePrecision (line 267) | public static BigDecimal sqrtUsingNewtonAdaptivePrecision(BigDecimal x...
method sqrtUsingNewtonAdaptivePrecisionImproved (line 295) | public static BigDecimal sqrtUsingNewtonAdaptivePrecisionImproved(BigD...
method sqrtUsingHalley (line 328) | public static BigDecimal sqrtUsingHalley(BigDecimal x, MathContext mat...
method sqrtUsingHalleyPrint (line 354) | public static BigDecimal sqrtUsingHalleyPrint(BigDecimal x, MathContex...
method rootFixPrecision (line 383) | public static BigDecimal rootFixPrecision(BigDecimal n, BigDecimal x, ...
method rootAdaptivePrecision (line 408) | public static BigDecimal rootAdaptivePrecision(BigDecimal n, BigDecima...
method rootAdaptivePrecision (line 412) | public static BigDecimal rootAdaptivePrecision(BigDecimal n, BigDecima...
method logRangeTen (line 444) | public static BigDecimal logRangeTen(BigDecimal x, MathContext mathCon...
method logUsingRoot (line 464) | public static BigDecimal logUsingRoot(BigDecimal x, MathContext mathCo...
method logUsingSqrt (line 476) | public static BigDecimal logUsingSqrt(BigDecimal x, MathContext mathCo...
method logUsingPowerTwo (line 485) | public static BigDecimal logUsingPowerTwo(BigDecimal x, MathContext ma...
method logUsingPrimes (line 526) | public static BigDecimal logUsingPrimes(BigDecimal x, MathContext math...
method logUsingExponent (line 630) | public static BigDecimal logUsingExponent(BigDecimal x, MathContext ma...
method logTen (line 643) | private static BigDecimal logTen(MathContext mathContext) {
method logTwo (line 650) | private static BigDecimal logTwo(MathContext mathContext) {
method logThree (line 657) | private static BigDecimal logThree(MathContext mathContext) {
method logUsingNewtonFixPrecision (line 664) | public static BigDecimal logUsingNewtonFixPrecision(BigDecimal x, Math...
method logUsingNewtonAdaptivePrecision (line 683) | public static BigDecimal logUsingNewtonAdaptivePrecision(BigDecimal x,...
method logUsingNewtonAdaptivePrecision (line 687) | public static BigDecimal logUsingNewtonAdaptivePrecision(BigDecimal x,...
method logAreaHyperbolicTangent (line 713) | public static BigDecimal logAreaHyperbolicTangent(BigDecimal x, MathCo...
method toBigDecimalSplitCount (line 737) | public static BigDecimal toBigDecimalSplitCount(String string, MathCon...
method toBigDecimalSplitLength (line 747) | public static BigDecimal toBigDecimalSplitLength(String string, MathCo...
method adjustScale (line 854) | private static int adjustScale(int scale, long exp) {
method toBigDecimalRecursive (line 861) | private static BigDecimal toBigDecimalRecursive(char[] chars, int offs...
method factorialSimple (line 874) | public static BigDecimal factorialSimple(int n) {
method factorialLoop (line 884) | public static BigDecimal factorialLoop(int n) {
method factorialLoopDivLimit (line 888) | public static BigDecimal factorialLoopDivLimit(int n) {
method factorialSwitchLoop (line 892) | public static BigDecimal factorialSwitchLoop(int n) {
method factorialRecursion (line 896) | public static BigDecimal factorialRecursion(int n) {
method factorialRecursionAdaptive (line 900) | public static BigDecimal factorialRecursionAdaptive(int n, int adaptSp...
method fastLoop (line 904) | private static long fastLoop(final int n1, int n2) {
method loopShiftLimit (line 913) | private static BigDecimal loopShiftLimit(int n1, final int n2) {
method loopDivLimit (line 929) | private static BigDecimal loopDivLimit(int n1, final int n2) {
method recursion (line 945) | private static BigDecimal recursion(final int n1, final int n2, int ad...
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/GammaExperiments.java
class GammaExperiments (line 18) | public class GammaExperiments {
method factorialUsingEuler (line 24) | public static BigDecimal factorialUsingEuler(BigDecimal x, int steps, ...
method factorialUsingSpouge (line 36) | public static BigDecimal factorialUsingSpouge(BigDecimal x, MathContex...
method errorOfFactorialUsingSpouge (line 65) | public static BigDecimal errorOfFactorialUsingSpouge(int a, MathContex...
method factorialUsingSpougeCached (line 70) | public static BigDecimal factorialUsingSpougeCached(BigDecimal x, Math...
method getSpougeFactorialConstants (line 95) | private static List<BigDecimal> getSpougeFactorialConstants(int a) {
method main (line 122) | public static void main(String[] args) {
method runFactorialUsingEuler (line 131) | private static void runFactorialUsingEuler() {
method runFactorialUsingSpouge (line 143) | private static void runFactorialUsingSpouge() {
method runFactorialCalculatingSpougeConstants (line 164) | private static void runFactorialCalculatingSpougeConstants() {
method runFactorialUsingSpougeCached (line 181) | private static void runFactorialUsingSpougeCached() {
method runFactorialUsingSpougeCachedOverPrecision (line 204) | private static void runFactorialUsingSpougeCachedOverPrecision() {
method runErrorOfFactorialUsingSpouge (line 223) | private static void runErrorOfFactorialUsingSpouge() {
method withPrintWriter (line 238) | private static void withPrintWriter(String filename, Consumer<PrintWri...
method inMilliseconds (line 246) | private static long inMilliseconds(Runnable block) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/PerformanceBigDecimalMath.java
class PerformanceBigDecimalMath (line 20) | public class PerformanceBigDecimalMath {
method main (line 37) | public static void main(String[] args) {
method createStringNumber (line 53) | private static String createStringNumber(int length) {
method createStringNumber (line 66) | private static String createStringNumber(int length, Random random) {
method fullReport (line 80) | public static void fullReport() {
method fullOptimizationReport (line 115) | public static void fullOptimizationReport() {
method performanceReport_Fast_0_to_2 (line 147) | private static void performanceReport_Fast_0_to_2() {
method performanceReport_Fast_neg10_to_10 (line 165) | private static void performanceReport_Fast_neg10_to_10() {
method performanceReport_Fast_0_to_10 (line 183) | private static void performanceReport_Fast_0_to_10() {
method performanceReport_Fast_0_to_100 (line 201) | private static void performanceReport_Fast_0_to_100() {
method performanceReport_Trigo_0_to_1 (line 219) | private static void performanceReport_Trigo_0_to_1() {
method performanceReport_Hyperbolic_0_to_2 (line 236) | private static void performanceReport_Hyperbolic_0_to_2() {
method performanceReport_Slow_0_to_2 (line 253) | private static void performanceReport_Slow_0_to_2() {
method performanceReport_Slow_neg10_to_10 (line 267) | private static void performanceReport_Slow_neg10_to_10() {
method performanceReport_Slow_0_to_10 (line 281) | private static void performanceReport_Slow_0_to_10() {
method performanceReport_Slow_0_to_100 (line 295) | private static void performanceReport_Slow_0_to_100() {
method performanceReport_Slow_0_to_1000 (line 309) | private static void performanceReport_Slow_0_to_1000() {
method performanceReport_pow_0_to_100 (line 323) | private static void performanceReport_pow_0_to_100() {
method performanceReport_pow_frac_0_to_1000 (line 335) | private static void performanceReport_pow_frac_0_to_1000() {
method performanceReport_pow_int_0_to_10000 (line 347) | private static void performanceReport_pow_int_0_to_10000() {
method performanceReport_pow_int_0_to_100000 (line 359) | private static void performanceReport_pow_int_0_to_100000() {
method performanceReport_Fast_precision (line 371) | private static void performanceReport_Fast_precision() {
method performanceReport_Slow_precision (line 388) | private static void performanceReport_Slow_precision() {
method performanceReportExpOptimization_0_to_4 (line 402) | private static void performanceReportExpOptimization_0_to_4() {
method performanceReportAsinOptimization_0_to_1 (line 417) | private static void performanceReportAsinOptimization_0_to_1() {
method performanceReportSqrtOptimization_0_to_1 (line 431) | private static void performanceReportSqrtOptimization_0_to_1() {
method performanceReportSqrtOptimization_0_to_100 (line 452) | private static void performanceReportSqrtOptimization_0_to_100() {
method performanceReportSqrtOptimization_0_to_1000 (line 473) | private static void performanceReportSqrtOptimization_0_to_1000() {
method performanceReportRootOptimization_0_to_10 (line 494) | private static void performanceReportRootOptimization_0_to_10() {
method performanceReportLogNewtonAdaptive_0_to_10 (line 507) | private static void performanceReportLogNewtonAdaptive_0_to_10() {
method performanceReportAtan2_y_neg10_to_10_x_5 (line 520) | private static void performanceReportAtan2_y_neg10_to_10_x_5() {
method performanceReportAtan2_y_5_x_neg10_to_10 (line 533) | private static void performanceReportAtan2_y_5_x_neg10_to_10() {
method performanceReportAtan2_yx_neg10_to_10 (line 546) | private static void performanceReportAtan2_yx_neg10_to_10() {
method functionValueAtan2_yx_neg10_to_10 (line 605) | private static void functionValueAtan2_yx_neg10_to_10() {
method performanceReportLogOptimizationNewton_0_to_10 (line 735) | private static void performanceReportLogOptimizationNewton_0_to_10() {
method performanceReportLogOptimizationNewton_0_to_100 (line 755) | private static void performanceReportLogOptimizationNewton_0_to_100() {
class OperationInfo (line 775) | private static class OperationInfo {
method OperationInfo (line 780) | OperationInfo(BigDecimal b1, BigDecimal b2, MathContext mc) {
method performanceReport_BasicOperations (line 787) | private static void performanceReport_BasicOperations() {
method performanceReport_toBigDecimal_optimization (line 882) | private static void performanceReport_toBigDecimal_optimization() {
method performanceReport_toBigDecimal (line 921) | private static void performanceReport_toBigDecimal() {
method performanceReport_factorial_optimization (line 963) | private static void performanceReport_factorial_optimization() {
method performanceReport_Java9_sqrt (line 1044) | private static void performanceReport_Java9_sqrt() {
method performanceReportOverValue (line 1120) | @SafeVarargs
method performanceReportOverValue (line 1125) | @SafeVarargs
method performanceReportOverValue (line 1139) | @SafeVarargs
method median (line 1225) | private static long median(long[] values) {
method averagePercentile (line 1235) | private static double averagePercentile(double percentile, long[] valu...
method performanceReportOverPrecision (line 1250) | @SafeVarargs
method performanceReportOverPrecision (line 1264) | @SafeVarargs
method performanceReportOverLambda (line 1352) | public static <T, U> void performanceReportOverLambda(String name, int...
method performanceReportOverLambda (line 1356) | public static <T, U> void performanceReportOverLambda(String name, int...
method performanceReportOverLambda (line 1369) | public static <T, U> void performanceReportOverLambda(PrintWriter writ...
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/PerformanceRegressionBigDecimalMath.java
class PerformanceRegressionBigDecimalMath (line 14) | public class PerformanceRegressionBigDecimalMath {
method main (line 32) | public static void main(String[] args) {
method performanceRegression (line 41) | private static void performanceRegression(PrintStream out, int precisi...
method measurePerformance (line 95) | private static void measurePerformance(PrintStream out, String name, M...
method median (line 133) | private static double median(List<Double> values) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/SqrtExperiments.java
class SqrtExperiments (line 8) | public class SqrtExperiments {
method main (line 9) | public static void main(String[] args) {
method java9Sqrt (line 13) | private static void java9Sqrt() {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/stream/BigDecimalStreamExample.java
class BigDecimalStreamExample (line 8) | public class BigDecimalStreamExample {
method main (line 10) | public static void main(String[] args) {
FILE: ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/stream/BigFloatStreamExample.java
class BigFloatStreamExample (line 7) | public class BigFloatStreamExample {
method main (line 9) | public static void main(String[] args) {
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigComplex.java
class BigComplex (line 21) | public final class BigComplex {
method BigComplex (line 48) | private BigComplex(BigDecimal re, BigDecimal im) {
method add (line 61) | public BigComplex add(BigComplex value) {
method add (line 76) | public BigComplex add(BigComplex value, MathContext mathContext) {
method add (line 91) | public BigComplex add(BigDecimal value, MathContext mathContext) {
method add (line 105) | public BigComplex add(BigDecimal value) {
method add (line 119) | public BigComplex add(double value) {
method subtract (line 131) | public BigComplex subtract(BigComplex value) {
method subtract (line 146) | public BigComplex subtract(BigComplex value, MathContext mathContext) {
method subtract (line 161) | public BigComplex subtract(BigDecimal value, MathContext mathContext) {
method subtract (line 175) | public BigComplex subtract(BigDecimal value) {
method subtract (line 189) | public BigComplex subtract(double value) {
method multiply (line 201) | public BigComplex multiply(BigComplex value) {
method multiply (line 216) | public BigComplex multiply(BigComplex value, MathContext mathContext) {
method multiply (line 231) | public BigComplex multiply(BigDecimal value, MathContext mathContext) {
method multiply (line 245) | public BigComplex multiply(BigDecimal value) {
method multiply (line 259) | public BigComplex multiply(double value) {
method divide (line 272) | public BigComplex divide(BigComplex value, MathContext mathContext) {
method divide (line 285) | public BigComplex divide(BigDecimal value, MathContext mathContext) {
method divide (line 300) | public BigComplex divide(double value, MathContext mathContext) {
method reciprocal (line 312) | public BigComplex reciprocal(MathContext mathContext) {
method conjugate (line 326) | public BigComplex conjugate() {
method negate (line 337) | public BigComplex negate() {
method abs (line 352) | public BigDecimal abs(MathContext mathContext) {
method angle (line 364) | public BigDecimal angle(MathContext mathContext) {
method absSquare (line 379) | public BigDecimal absSquare(MathContext mathContext) {
method isReal (line 388) | public boolean isReal() {
method re (line 397) | public BigComplex re() {
method im (line 406) | public BigComplex im() {
method round (line 418) | public BigComplex round(MathContext mathContext) {
method hashCode (line 422) | @Override
method equals (line 436) | @Override
method strictEquals (line 460) | public boolean strictEquals(Object obj) {
method toString (line 472) | @Override
method valueOf (line 487) | public static BigComplex valueOf(BigDecimal real) {
method valueOf (line 497) | public static BigComplex valueOf(double real) {
method valueOf (line 508) | public static BigComplex valueOf(double real, double imaginary) {
method valueOf (line 519) | public static BigComplex valueOf(BigDecimal real, BigDecimal imaginary) {
method valueOfPolar (line 543) | public static BigComplex valueOfPolar(BigDecimal radius, BigDecimal an...
method valueOfPolar (line 553) | public static BigComplex valueOfPolar(double radius, double angle, Mat...
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigComplexMath.java
class BigComplexMath (line 12) | public class BigComplexMath {
method reciprocal (line 24) | public static BigComplex reciprocal(BigComplex x, MathContext mathCont...
method conjugate (line 35) | public static BigComplex conjugate(BigComplex x) {
method abs (line 47) | public static BigDecimal abs(BigComplex x, MathContext mathContext) {
method absSquare (line 59) | public static BigDecimal absSquare(BigComplex x, MathContext mathConte...
method angle (line 71) | public static BigDecimal angle(BigComplex x, MathContext mathContext) {
method factorial (line 99) | public static BigComplex factorial(BigComplex x, MathContext mathConte...
method gamma (line 142) | public static BigComplex gamma(BigComplex x, MathContext mathContext) {
method exp (line 156) | public static BigComplex exp(BigComplex x, MathContext mathContext) {
method sin (line 174) | public static BigComplex sin(BigComplex x, MathContext mathContext) {
method cos (line 189) | public static BigComplex cos(BigComplex x, MathContext mathContext) {
method tan (line 207) | public static BigComplex tan(BigComplex x, MathContext mathContext) {
method atan (line 222) | public static BigComplex atan(BigComplex x, MathContext mathContext) {
method acot (line 237) | public static BigComplex acot(BigComplex x, MathContext mathContext) {
method asin (line 252) | public static BigComplex asin(BigComplex x, MathContext mathContext) {
method acos (line 267) | public static BigComplex acos(BigComplex x, MathContext mathContext) {
method sqrt (line 282) | public static BigComplex sqrt(BigComplex x, MathContext mathContext) {
method log (line 301) | public static BigComplex log(BigComplex x, MathContext mathContext) {
method pow (line 323) | public static BigComplex pow(BigComplex x, long y, MathContext mathCon...
method pow (line 357) | public static BigComplex pow(BigComplex x, BigDecimal y, MathContext m...
method pow (line 374) | public static BigComplex pow(BigComplex x, BigComplex y, MathContext m...
method root (line 390) | public static BigComplex root(BigComplex x, BigDecimal n, MathContext ...
method root (line 406) | public static BigComplex root(BigComplex x, BigComplex n, MathContext ...
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigDecimalMath.java
class BigDecimalMath (line 22) | public class BigDecimalMath {
method BigDecimalMath (line 66) | private BigDecimalMath() {
method toBigDecimal (line 82) | public static BigDecimal toBigDecimal(String string) {
method toBigDecimal (line 100) | public static BigDecimal toBigDecimal(String string, MathContext mathC...
method toBigDecimal (line 110) | static BigDecimal toBigDecimal(String string, MathContext mathContext,...
method adjustScale (line 217) | private static int adjustScale(int scale, long exp) {
method toBigDecimalRecursive (line 224) | private static BigDecimal toBigDecimalRecursive(char[] chars, int offs...
method isIntValue (line 245) | public static boolean isIntValue(BigDecimal value) {
method isLongValue (line 264) | public static boolean isLongValue(BigDecimal value) {
method isDoubleValue (line 297) | public static boolean isDoubleValue(BigDecimal value) {
method mantissa (line 317) | public static BigDecimal mantissa(BigDecimal value) {
method exponent (line 335) | public static int exponent(BigDecimal value) {
method significantDigits (line 360) | public static int significantDigits(BigDecimal value) {
method integralPart (line 376) | public static BigDecimal integralPart(BigDecimal value) {
method fractionalPart (line 387) | public static BigDecimal fractionalPart(BigDecimal value) {
method round (line 402) | public static BigDecimal round(BigDecimal value, MathContext mathConte...
method roundWithTrailingZeroes (line 430) | public static BigDecimal roundWithTrailingZeroes(BigDecimal value, Mat...
method reciprocal (line 466) | public static BigDecimal reciprocal(BigDecimal x, MathContext mathCont...
method factorial (line 479) | public static BigDecimal factorial(int n) {
method factorialLoop (line 491) | private static BigDecimal factorialLoop(int n1, final int n2) {
method factorialRecursion (line 507) | private static BigDecimal factorialRecursion(final int n1, final int n...
method factorial (line 541) | public static BigDecimal factorial(BigDecimal x, MathContext mathConte...
method getSpougeFactorialConstants (line 570) | static List<BigDecimal> getSpougeFactorialConstants(int a) {
method gamma (line 614) | public static BigDecimal gamma(BigDecimal x, MathContext mathContext) {
method bernoulli (line 634) | public static BigDecimal bernoulli(int n, MathContext mathContext) {
method pow (line 653) | public static BigDecimal pow(BigDecimal x, BigDecimal y, MathContext m...
method pow (line 701) | public static BigDecimal pow(BigDecimal x, long y, MathContext mathCon...
method powInteger (line 741) | private static BigDecimal powInteger(BigDecimal x, BigDecimal integerY...
method sqrt (line 785) | public static BigDecimal sqrt(BigDecimal x, MathContext mathContext) {
method root (line 842) | public static BigDecimal root(BigDecimal x, BigDecimal n, MathContext ...
method rootUsingNewtonRaphson (line 870) | private static BigDecimal rootUsingNewtonRaphson(BigDecimal x, BigDeci...
method log (line 911) | public static BigDecimal log(BigDecimal x, MathContext mathContext) {
method log2 (line 944) | public static BigDecimal log2(BigDecimal x, MathContext mathContext) {
method log10 (line 961) | public static BigDecimal log10(BigDecimal x, MathContext mathContext) {
method logUsingNewton (line 969) | private static BigDecimal logUsingNewton(BigDecimal x, MathContext mat...
method logUsingExponent (line 1006) | private static BigDecimal logUsingExponent(BigDecimal x, MathContext m...
method logUsingTwoThree (line 1021) | private static BigDecimal logUsingTwoThree(BigDecimal x, MathContext m...
method pi (line 1143) | public static BigDecimal pi(MathContext mathContext) {
method piChudnovski (line 1159) | private static BigDecimal piChudnovski(MathContext mathContext) {
method e (line 1210) | public static BigDecimal e(MathContext mathContext) {
method logTen (line 1226) | private static BigDecimal logTen(MathContext mathContext) {
method logTwo (line 1241) | private static BigDecimal logTwo(MathContext mathContext) {
method logThree (line 1256) | private static BigDecimal logThree(MathContext mathContext) {
method exp (line 1281) | public static BigDecimal exp(BigDecimal x, MathContext mathContext) {
method expIntegralFractional (line 1290) | private static BigDecimal expIntegralFractional(BigDecimal x, MathCont...
method expTaylor (line 1309) | private static BigDecimal expTaylor(BigDecimal x, MathContext mathCont...
method sin (line 1329) | public static BigDecimal sin(BigDecimal x, MathContext mathContext) {
method asin (line 1354) | public static BigDecimal asin(BigDecimal x, MathContext mathContext) {
method cos (line 1388) | public static BigDecimal cos(BigDecimal x, MathContext mathContext) {
method acos (line 1413) | public static BigDecimal acos(BigDecimal x, MathContext mathContext) {
method tan (line 1438) | public static BigDecimal tan(BigDecimal x, MathContext mathContext) {
method atan (line 1459) | public static BigDecimal atan(BigDecimal x, MathContext mathContext) {
method atan2 (line 1484) | public static BigDecimal atan2(BigDecimal y, BigDecimal x, MathContext...
method cot (line 1520) | public static BigDecimal cot(BigDecimal x, MathContext mathContext) {
method acot (line 1541) | public static BigDecimal acot(BigDecimal x, MathContext mathContext) {
method sinh (line 1558) | public static BigDecimal sinh(BigDecimal x, MathContext mathContext) {
method cosh (line 1575) | public static BigDecimal cosh(BigDecimal x, MathContext mathContext) {
method tanh (line 1592) | public static BigDecimal tanh(BigDecimal x, MathContext mathContext) {
method coth (line 1609) | public static BigDecimal coth(BigDecimal x, MathContext mathContext) {
method asinh (line 1626) | public static BigDecimal asinh(BigDecimal x, MathContext mathContext) {
method acosh (line 1643) | public static BigDecimal acosh(BigDecimal x, MathContext mathContext) {
method atanh (line 1660) | public static BigDecimal atanh(BigDecimal x, MathContext mathContext) {
method acoth (line 1684) | public static BigDecimal acoth(BigDecimal x, MathContext mathContext) {
method toDegrees (line 1699) | public static BigDecimal toDegrees(BigDecimal x, MathContext mathConte...
method toRadians (line 1716) | public static BigDecimal toRadians(BigDecimal x, MathContext mathConte...
method checkMathContext (line 1723) | private static void checkMathContext (MathContext mathContext) {
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigFloat.java
class BigFloat (line 124) | @SuppressWarnings("WeakerAccess")
method BigFloat (line 149) | private BigFloat(BigDecimal value, Context context) {
method context (line 161) | public static Context context(int precision) {
method context (line 172) | public static Context context(MathContext mathContext) {
method add (line 187) | public BigFloat add(BigFloat x) {
method add (line 203) | public BigFloat add(BigDecimal x) {
method add (line 216) | public BigFloat add(int x) {
method add (line 229) | public BigFloat add(long x) {
method add (line 242) | public BigFloat add(double x) {
method subtract (line 257) | public BigFloat subtract(BigFloat x) {
method subtract (line 273) | public BigFloat subtract(BigDecimal x) {
method subtract (line 286) | public BigFloat subtract(int x) {
method subtract (line 299) | public BigFloat subtract(long x) {
method subtract (line 312) | public BigFloat subtract(double x) {
method multiply (line 327) | public BigFloat multiply(BigFloat x) {
method multiply (line 343) | public BigFloat multiply(BigDecimal x) {
method multiply (line 356) | public BigFloat multiply(int x) {
method multiply (line 369) | public BigFloat multiply(long x) {
method multiply (line 382) | public BigFloat multiply(double x) {
method divide (line 398) | public BigFloat divide(BigFloat x) {
method divide (line 432) | public BigFloat divide(BigDecimal x) {
method divide (line 445) | public BigFloat divide(int x) {
method divide (line 458) | public BigFloat divide(long x) {
method divide (line 471) | public BigFloat divide(double x) {
method remainder (line 486) | public BigFloat remainder(BigFloat x) {
method remainder (line 514) | public BigFloat remainder(BigDecimal x) {
method remainder (line 527) | public BigFloat remainder(int x) {
method remainder (line 540) | public BigFloat remainder(long x) {
method remainder (line 553) | public BigFloat remainder(double x) {
method pow (line 568) | public BigFloat pow(BigFloat y) {
method pow (line 602) | public BigFloat pow(BigDecimal y) {
method pow (line 615) | public BigFloat pow(int y) {
method pow (line 628) | public BigFloat pow(long y) {
method pow (line 641) | public BigFloat pow(double y) {
method root (line 656) | public BigFloat root(BigFloat y) {
method root (line 672) | public BigFloat root(BigDecimal y) {
method root (line 685) | public BigFloat root(int y) {
method root (line 698) | public BigFloat root(long y) {
method root (line 711) | public BigFloat root(double y) {
method hashCode (line 715) | @Override
method equals (line 720) | @Override
method signum (line 739) | public int signum() {
method isNegative (line 748) | public boolean isNegative() {
method isZero (line 757) | public boolean isZero() {
method isPositive (line 766) | public boolean isPositive() {
method compareTo (line 770) | @Override
method isEqual (line 787) | public boolean isEqual(BigFloat other) {
method isLessThan (line 804) | public boolean isLessThan(BigFloat other) {
method isGreaterThan (line 821) | public boolean isGreaterThan(BigFloat other) {
method isLessThanOrEqual (line 840) | public boolean isLessThanOrEqual(BigFloat other) {
method isGreaterThanOrEqual (line 859) | public boolean isGreaterThanOrEqual(BigFloat other) {
method isIntValue (line 874) | public boolean isIntValue() {
method isDoubleValue (line 885) | public boolean isDoubleValue() {
method getMantissa (line 899) | public BigFloat getMantissa() {
method getExponent (line 913) | public BigFloat getExponent() {
method getIntegralPart (line 925) | public BigFloat getIntegralPart() {
method getFractionalPart (line 937) | public BigFloat getFractionalPart() {
method getContext (line 946) | public Context getContext() {
method toBigDecimal (line 955) | public BigDecimal toBigDecimal() {
method toDouble (line 966) | public double toDouble() {
method toLong (line 977) | public long toLong() {
method toInt (line 988) | public int toInt() {
method toString (line 992) | @Override
method isSpecial (line 997) | protected boolean isSpecial() {
method type (line 1005) | protected SpecialBigFloat.Type type() {
method isNaN (line 1009) | public boolean isNaN() {
method isInfinity (line 1013) | public boolean isInfinity() {
class SpecialBigFloat (line 1022) | private static final class SpecialBigFloat extends BigFloat {
method SpecialBigFloat (line 1028) | private SpecialBigFloat(Type type) {
method isSpecial (line 1033) | @Override
method type (line 1038) | @Override
method add (line 1043) | @Override
method subtract (line 1057) | @Override
method subtract (line 1071) | @Override
method multiply (line 1076) | @Override
method divide (line 1087) | @Override
method remainder (line 1098) | @Override
method pow (line 1103) | @Override
method root (line 1120) | @Override
method hashCode (line 1125) | @Override
method equals (line 1130) | @Override
method signum (line 1137) | @Override
method isNegative (line 1142) | @Override
method isZero (line 1147) | @Override
method isPositive (line 1152) | @Override
method compareTo (line 1157) | @Override
method isIntValue (line 1162) | @Override
method isDoubleValue (line 1167) | @Override
method getMantissa (line 1172) | @Override
method getExponent (line 1177) | @Override
method getIntegralPart (line 1182) | @Override
method getFractionalPart (line 1187) | @Override
method getContext (line 1192) | @Override
method toBigDecimal (line 1197) | @Override
method toDouble (line 1202) | @Override
method toLong (line 1207) | @Override
method toInt (line 1212) | @Override
method toString (line 1217) | @Override
type Type (line 1223) | enum Type {
method Type (line 1231) | Type(int hashCode){
method compare (line 1235) | public static int compare(Type a, Type b) {
method toDouble (line 1246) | public double toDouble() {
class Context (line 1264) | public static class Context implements Serializable{
method Context (line 1272) | private Context(MathContext mathContext) {
method getMathContext (line 1284) | public MathContext getMathContext() {
method getPrecision (line 1295) | public int getPrecision() {
method getRoundingMode (line 1306) | public RoundingMode getRoundingMode() {
method valueOf (line 1317) | public BigFloat valueOf(BigFloat value) {
method valueOf (line 1328) | public BigFloat valueOf(BigDecimal value) {
method valueOf (line 1339) | public BigFloat valueOf(int value) {
method valueOf (line 1349) | public BigFloat valueOf(int value, boolean unsigned) {
method valueOf (line 1368) | public BigFloat valueOf(long value) {
method valueOf (line 1378) | public BigFloat valueOf(long value, boolean unsigned) {
method valueOf (line 1397) | public BigFloat valueOf(double value) {
method valueOf (line 1414) | public BigFloat valueOf(String value) {
method pi (line 1425) | public BigFloat pi() {
method e (line 1436) | public BigFloat e() {
method factorial (line 1449) | public BigFloat factorial(int n) {
method hashCode (line 1453) | @Override
method equals (line 1458) | @Override
method toString (line 1470) | @Override
method negate (line 1484) | public static BigFloat negate(BigFloat x) {
method abs (line 1502) | public static BigFloat abs(BigFloat x) {
method max (line 1516) | public static BigFloat max(BigFloat value1, BigFloat value2) {
method max (line 1528) | public static BigFloat max(BigFloat value1, BigFloat... values) {
method min (line 1546) | public static BigFloat min(BigFloat value1, BigFloat value2) {
method min (line 1558) | public static BigFloat min(BigFloat value1, BigFloat... values) {
method logSpecial (line 1568) | private static BigFloat logSpecial(BigFloat val){
method log (line 1587) | public static BigFloat log(BigFloat x) {
method log2 (line 1601) | public static BigFloat log2(BigFloat x) {
method log10 (line 1615) | public static BigFloat log10(BigFloat x) {
method exp (line 1629) | public static BigFloat exp(BigFloat x) {
method sqrt (line 1644) | public static BigFloat sqrt(BigFloat x) {
method pow (line 1664) | public static BigFloat pow(BigFloat x, BigFloat y) {
method root (line 1681) | public static BigFloat root(BigFloat x, BigFloat y) {
method sin (line 1695) | public static BigFloat sin(BigFloat x) {
method cos (line 1712) | public static BigFloat cos(BigFloat x) {
method tan (line 1727) | public static BigFloat tan(BigFloat x) {
method cot (line 1744) | public static BigFloat cot(BigFloat x) {
method asin (line 1761) | public static BigFloat asin(BigFloat x) {
method acos (line 1777) | public static BigFloat acos(BigFloat x) {
method isRangeAbs1 (line 1786) | private static boolean isRangeAbs1(BigFloat x) {
method atan (line 1799) | public static BigFloat atan(BigFloat x) {
method acot (line 1812) | public static BigFloat acot(BigFloat x) {
method sinh (line 1825) | public static BigFloat sinh(BigFloat x) {
method cosh (line 1840) | public static BigFloat cosh(BigFloat x) {
method tanh (line 1859) | public static BigFloat tanh(BigFloat x) {
method coth (line 1876) | public static BigFloat coth(BigFloat x) {
method asinh (line 1891) | public static BigFloat asinh(BigFloat x) {
method acosh (line 1906) | public static BigFloat acosh(BigFloat x) {
method atanh (line 1919) | public static BigFloat atanh(BigFloat x) {
method acoth (line 1934) | public static BigFloat acoth(BigFloat x) {
method isBetween (line 1940) | public static boolean isBetween(BigFloat min, BigFloat max, BigFloat v...
method max (line 1944) | private static Context max(Context left, Context right) {
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigRational.java
class BigRational (line 44) | public class BigRational extends Number implements Comparable<BigRationa...
method BigRational (line 67) | private BigRational(int value) {
method BigRational (line 71) | private BigRational(BigDecimal num, BigDecimal denom) {
method getNumeratorBigInteger (line 93) | public BigInteger getNumeratorBigInteger() {
method getNumerator (line 102) | public BigDecimal getNumerator() {
method getDenominatorBigInteger (line 114) | public BigInteger getDenominatorBigInteger() {
method getDenominator (line 126) | public BigDecimal getDenominator() {
method reduce (line 135) | public BigRational reduce() {
method integerPart (line 156) | public BigRational integerPart() {
method fractionPart (line 170) | public BigRational fractionPart() {
method negate (line 186) | public BigRational negate() {
method reciprocal (line 208) | public BigRational reciprocal() {
method abs (line 225) | public BigRational abs() {
method signum (line 234) | public int signum() {
method increment (line 249) | public BigRational increment() {
method decrement (line 264) | public BigRational decrement() {
method add (line 276) | public BigRational add(BigRational value) {
method add (line 286) | private BigRational add(BigDecimal value) {
method add (line 302) | public BigRational add(BigInteger value) {
method add (line 321) | public BigRational add(int value) {
method subtract (line 336) | public BigRational subtract(BigRational value) {
method subtract (line 346) | private BigRational subtract(BigDecimal value) {
method subtract (line 362) | public BigRational subtract(BigInteger value) {
method subtract (line 381) | public BigRational subtract(int value) {
method multiply (line 396) | public BigRational multiply(BigRational value) {
method multiply (line 413) | private BigRational multiply(BigDecimal value) {
method multiply (line 431) | public BigRational multiply(BigInteger value) {
method multiply (line 457) | public BigRational multiply(int value) {
method divide (line 470) | public BigRational divide(BigRational value) {
method divide (line 480) | private BigRational divide(BigDecimal value) {
method divide (line 499) | public BigRational divide(BigInteger value) {
method divide (line 520) | public BigRational divide(int value) {
method isZero (line 529) | public boolean isZero() {
method isPositive (line 533) | private boolean isPositive() {
method isInteger (line 542) | public boolean isInteger() {
method isIntegerInternal (line 554) | private boolean isIntegerInternal() {
method pow (line 566) | public BigRational pow(int exponent) {
method min (line 593) | private BigRational min(BigRational value) {
method max (line 603) | private BigRational max(BigRational value) {
method withPrecision (line 613) | public BigRational withPrecision(int precision) {
method withScale (line 623) | public BigRational withScale(int scale) {
method countDigits (line 627) | private static int countDigits(BigInteger number) {
method precision (line 637) | private int precision() {
method toDouble (line 654) | public double toDouble() {
method toFloat (line 671) | public float toFloat() {
method toBigDecimal (line 680) | public BigDecimal toBigDecimal() {
method toBigDecimal (line 691) | public BigDecimal toBigDecimal(MathContext mc) {
method compareTo (line 695) | @Override
method hashCode (line 703) | @Override
method equals (line 711) | @Override
method toString (line 728) | @Override
method toPlainString (line 745) | public String toPlainString() {
method toRationalString (line 771) | public String toRationalString() {
method toIntegerRationalString (line 793) | public String toIntegerRationalString() {
method valueOf (line 825) | public static BigRational valueOf(int value) {
method valueOf (line 843) | public static BigRational valueOf(int numerator, int denominator) {
method valueOf (line 862) | public static BigRational valueOf(int integer, int fractionNumerator, ...
method valueOf (line 880) | public static BigRational valueOf(BigInteger numerator, BigInteger den...
method valueOf (line 890) | public static BigRational valueOf(BigInteger value) {
method valueOf (line 907) | public static BigRational valueOf(double value) {
method valueOf (line 929) | public static BigRational valueOf(BigDecimal value) {
method valueOf (line 966) | public static BigRational valueOf(String string) {
method valueOfSimple (line 975) | private static BigRational valueOfSimple(String string) {
method valueOf (line 979) | public static BigRational valueOf(boolean positive, String integerPart...
method valueOf (line 1017) | public static BigRational valueOf(BigDecimal numerator, BigDecimal den...
method of (line 1021) | private static BigRational of(BigDecimal numerator, BigDecimal denomin...
method min (line 1037) | public static BigRational min(BigRational... values) {
method max (line 1055) | public static BigRational max(BigRational... values) {
method bernoulli (line 1079) | public static BigRational bernoulli(int n) {
method calculateBernoulli (line 1103) | private static BigRational calculateBernoulli(int n) {
method intValue (line 1121) | @Override
method longValue (line 1126) | @Override
method floatValue (line 1131) | @Override
method doubleValue (line 1136) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/DefaultBigDecimalMath.java
class DefaultBigDecimalMath (line 94) | public class DefaultBigDecimalMath {
method createDefaultMathContext (line 99) | private static MathContext createDefaultMathContext () {
method pushMathContext (line 106) | private static void pushMathContext(MathContext mathContext) {
method popMathContext (line 115) | private static MathContext popMathContext() {
method getIntSystemProperty (line 124) | private static int getIntSystemProperty(String propertyKey, int defaul...
method getRoundingModeSystemProperty (line 133) | private static RoundingMode getRoundingModeSystemProperty(String prope...
method propertyException (line 142) | private static <T> T propertyException(String propertyKey,String prope...
method setDefaultMathContext (line 156) | public static void setDefaultMathContext(MathContext defaultMathContex...
method getDefaultMathContext (line 166) | public static MathContext getDefaultMathContext() {
method withLocalMathContext (line 176) | public static void withLocalMathContext(int precision, Runnable runnab...
method withLocalMathContext (line 187) | public static void withLocalMathContext(int precision, RoundingMode ro...
method withLocalMathContext (line 197) | public static void withLocalMathContext(MathContext mathContext, Runna...
method createLocalMathContext (line 209) | public static LocalMathContext createLocalMathContext(int precision) {
method createLocalMathContext (line 220) | public static LocalMathContext createLocalMathContext(int precision, R...
method createLocalMathContext (line 230) | public static LocalMathContext createLocalMathContext(MathContext math...
method currentMathContext (line 247) | public static MathContext currentMathContext() {
method round (line 264) | public static BigDecimal round(BigDecimal value) {
method roundWithTrailingZeroes (line 276) | public static BigDecimal roundWithTrailingZeroes(BigDecimal value) {
method add (line 289) | public static BigDecimal add(BigDecimal x, BigDecimal y) {
method subtract (line 302) | public static BigDecimal subtract(BigDecimal x, BigDecimal y) {
method multiply (line 315) | public static BigDecimal multiply(BigDecimal x, BigDecimal y) {
method divide (line 328) | public static BigDecimal divide(BigDecimal x, BigDecimal y) {
method remainder (line 341) | public static BigDecimal remainder(BigDecimal x, BigDecimal y) {
method reciprocal (line 353) | public static BigDecimal reciprocal(BigDecimal x) {
method factorial (line 365) | public static BigDecimal factorial(BigDecimal x) {
method gamma (line 377) | public static BigDecimal gamma(BigDecimal x) {
method bernoulli (line 389) | public static BigDecimal bernoulli(int n) {
method pow (line 402) | public static BigDecimal pow(BigDecimal x, BigDecimal y) {
method pow (line 415) | public static BigDecimal pow(BigDecimal x, long y) {
method sqrt (line 427) | public static BigDecimal sqrt(BigDecimal x) {
method root (line 441) | public static BigDecimal root(BigDecimal x, BigDecimal n) {
method log (line 453) | public static BigDecimal log(BigDecimal x) {
method log2 (line 465) | public static BigDecimal log2(BigDecimal x) {
method log10 (line 477) | public static BigDecimal log10(BigDecimal x) {
method pi (line 488) | public static BigDecimal pi() {
method e (line 499) | public static BigDecimal e() {
method exp (line 511) | public static BigDecimal exp(BigDecimal x) {
method sin (line 523) | public static BigDecimal sin(BigDecimal x) {
method asin (line 535) | public static BigDecimal asin(BigDecimal x) {
method cos (line 545) | public static BigDecimal cos(BigDecimal x) {
method acos (line 557) | public static BigDecimal acos(BigDecimal x) {
method tan (line 569) | public static BigDecimal tan(BigDecimal x) {
method atan (line 581) | public static BigDecimal atan(BigDecimal x) {
method atan2 (line 594) | public static BigDecimal atan2(BigDecimal y, BigDecimal x) {
method cot (line 606) | public static BigDecimal cot(BigDecimal x) {
method acot (line 618) | public static BigDecimal acot(BigDecimal x) {
method sinh (line 630) | public static BigDecimal sinh(BigDecimal x) {
method cosh (line 642) | public static BigDecimal cosh(BigDecimal x) {
method tanh (line 654) | public static BigDecimal tanh(BigDecimal x) {
method coth (line 666) | public static BigDecimal coth(BigDecimal x) {
method asinh (line 678) | public static BigDecimal asinh(BigDecimal x) {
method acosh (line 690) | public static BigDecimal acosh(BigDecimal x) {
method atanh (line 702) | public static BigDecimal atanh(BigDecimal x) {
method acoth (line 714) | public static BigDecimal acoth(BigDecimal x) {
class LocalMathContext (line 723) | public static class LocalMathContext implements AutoCloseable {
method LocalMathContext (line 726) | LocalMathContext(MathContext mathContext) {
method close (line 731) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/AsinCalculator.java
class AsinCalculator (line 16) | public class AsinCalculator extends SeriesCalculator {
method AsinCalculator (line 25) | private AsinCalculator() {
method getCurrentFactor (line 28) | @Override
method calculateNextFactor (line 34) | @Override
method createPowerIterator (line 42) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/AtanhCalculator.java
class AtanhCalculator (line 16) | public class AtanhCalculator extends SeriesCalculator {
method AtanhCalculator (line 22) | private AtanhCalculator() {
method getCurrentFactor (line 26) | @Override
method calculateNextFactor (line 31) | @Override
method createPowerIterator (line 36) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/CosCalculator.java
class CosCalculator (line 16) | public class CosCalculator extends SeriesCalculator {
method CosCalculator (line 24) | private CosCalculator() {
method getCurrentFactor (line 28) | @Override
method calculateNextFactor (line 37) | @Override
method createPowerIterator (line 44) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/CoshCalculator.java
class CoshCalculator (line 16) | public class CoshCalculator extends SeriesCalculator {
method CoshCalculator (line 24) | private CoshCalculator() {
method getCurrentFactor (line 28) | @Override
method calculateNextFactor (line 33) | @Override
method createPowerIterator (line 39) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/ExpCalculator.java
class ExpCalculator (line 16) | public class ExpCalculator extends SeriesCalculator {
method ExpCalculator (line 23) | private ExpCalculator() {
method getCurrentFactor (line 27) | @Override
method calculateNextFactor (line 32) | @Override
method createPowerIterator (line 38) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerIterator.java
type PowerIterator (line 15) | public interface PowerIterator {
method getCurrentPower (line 22) | BigDecimal getCurrentPower();
method calculateNextPower (line 27) | void calculateNextPower();
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerNIterator.java
class PowerNIterator (line 9) | public class PowerNIterator implements PowerIterator {
method PowerNIterator (line 17) | public PowerNIterator(BigDecimal x, MathContext mathContext) {
method getCurrentPower (line 24) | @Override
method calculateNextPower (line 29) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerTwoNIterator.java
class PowerTwoNIterator (line 9) | public class PowerTwoNIterator implements PowerIterator {
method PowerTwoNIterator (line 17) | public PowerTwoNIterator(BigDecimal x, MathContext mathContext) {
method getCurrentPower (line 24) | @Override
method calculateNextPower (line 29) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerTwoNMinusOneIterator.java
class PowerTwoNMinusOneIterator (line 11) | public class PowerTwoNMinusOneIterator implements PowerIterator {
method PowerTwoNMinusOneIterator (line 19) | public PowerTwoNMinusOneIterator(BigDecimal x, MathContext mathContext) {
method getCurrentPower (line 26) | @Override
method calculateNextPower (line 31) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerTwoNPlusOneIterator.java
class PowerTwoNPlusOneIterator (line 9) | public class PowerTwoNPlusOneIterator implements PowerIterator {
method PowerTwoNPlusOneIterator (line 17) | public PowerTwoNPlusOneIterator(BigDecimal x, MathContext mathContext) {
method getCurrentPower (line 24) | @Override
method calculateNextPower (line 29) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/SeriesCalculator.java
class SeriesCalculator (line 17) | public abstract class SeriesCalculator {
method SeriesCalculator (line 26) | protected SeriesCalculator() {
method SeriesCalculator (line 38) | protected SeriesCalculator(boolean calculateInPairs) {
method calculate (line 49) | public BigDecimal calculate(BigDecimal x, MathContext mathContext) {
method createPowerIterator (line 90) | protected abstract PowerIterator createPowerIterator(BigDecimal x, Mat...
method getFactor (line 101) | protected synchronized BigRational getFactor(int index) {
method addFactor (line 110) | private void addFactor(BigRational factor){
method getCurrentFactor (line 121) | protected abstract BigRational getCurrentFactor();
method calculateNextFactor (line 126) | protected abstract void calculateNextFactor();
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/SinCalculator.java
class SinCalculator (line 16) | public class SinCalculator extends SeriesCalculator {
method SinCalculator (line 24) | private SinCalculator() {
method getCurrentFactor (line 28) | @Override
method calculateNextFactor (line 37) | @Override
method createPowerIterator (line 45) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/SinhCalculator.java
class SinhCalculator (line 16) | public class SinhCalculator extends SeriesCalculator {
method SinhCalculator (line 24) | private SinhCalculator() {
method getCurrentFactor (line 28) | @Override
method calculateNextFactor (line 33) | @Override
method createPowerIterator (line 40) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/stream/BigDecimalStream.java
class BigDecimalStream (line 17) | public class BigDecimalStream {
method range (line 35) | public static Stream<BigDecimal> range(BigDecimal startInclusive, BigD...
method range (line 58) | public static Stream<BigDecimal> range(long startInclusive, long endEx...
method range (line 75) | public static Stream<BigDecimal> range(double startInclusive, double e...
method rangeClosed (line 96) | public static Stream<BigDecimal> rangeClosed(BigDecimal startInclusive...
method rangeClosed (line 119) | public static Stream<BigDecimal> rangeClosed(long startInclusive, long...
method rangeClosed (line 136) | public static Stream<BigDecimal> rangeClosed(double startInclusive, do...
class BigDecimalSpliterator (line 140) | private static class BigDecimalSpliterator extends AbstractSpliterator...
method BigDecimalSpliterator (line 147) | public BigDecimalSpliterator(BigDecimal startInclusive, BigDecimal s...
method BigDecimalSpliterator (line 157) | public BigDecimalSpliterator(BigDecimal startInclusive, BigDecimal e...
method estimatedCount (line 161) | private static long estimatedCount(BigDecimal startInclusive, BigDec...
method getComparator (line 174) | @Override
method tryAdvance (line 182) | @Override
method forEachRemaining (line 194) | @Override
method trySplit (line 203) | @Override
FILE: ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/stream/BigFloatStream.java
class BigFloatStream (line 16) | public class BigFloatStream {
method range (line 33) | public static Stream<BigFloat> range(BigFloat startInclusive, BigFloat...
method range (line 56) | public static Stream<BigFloat> range(long startInclusive, long endExcl...
method range (line 73) | public static Stream<BigFloat> range(double startInclusive, double end...
method rangeClosed (line 93) | public static Stream<BigFloat> rangeClosed(BigFloat startInclusive, Bi...
method rangeClosed (line 116) | public static Stream<BigFloat> rangeClosed(long startInclusive, long e...
method rangeClosed (line 133) | public static Stream<BigFloat> rangeClosed(double startInclusive, doub...
class BigFloatSpliterator (line 137) | private static class BigFloatSpliterator extends AbstractSpliterator<B...
method BigFloatSpliterator (line 143) | public BigFloatSpliterator(BigFloat startInclusive, BigFloat step, l...
method BigFloatSpliterator (line 152) | public BigFloatSpliterator(BigFloat startInclusive, BigFloat end, bo...
method estimatedCount (line 156) | private static long estimatedCount(BigFloat startInclusive, BigFloat...
method getComparator (line 169) | @Override
method tryAdvance (line 177) | @Override
method forEachRemaining (line 189) | @Override
method trySplit (line 198) | @Override
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigComplexMathTest.java
class BigComplexMathTest (line 11) | public class BigComplexMathTest {
method testReciprocal (line 15) | @Test
method testConjugate (line 20) | @Test
method testAngle (line 25) | @Test
method testAbs (line 30) | @Test
method testAbsSquare (line 35) | @Test
method testFactorial (line 40) | @Test
method testFactorialHighPrecision (line 46) | @Test
method testExp (line 57) | @Test
method testSin (line 65) | @Test
method testCos (line 73) | @Test
method testTan (line 81) | @Test
method testLog (line 89) | @Test
method testSqrt (line 97) | @Test
method testPowInt (line 105) | @Test
method testPow (line 118) | @Test
method testPowComplex (line 126) | @Test
method testRoot (line 134) | @Test
method testRootComplex (line 142) | @Test
method testAsin (line 150) | @Test
method testAcos (line 158) | @Test
method testAtan (line 166) | @Test
method testAcot (line 174) | @Test
method assertPrecisionCalculation (line 182) | private void assertPrecisionCalculation(BigComplex expected, Function<...
method assertPrecisionCalculation (line 186) | private void assertPrecisionCalculation(BigComplex expected, Function<...
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigComplexTest.java
class BigComplexTest (line 12) | public class BigComplexTest {
method testConstants (line 18) | @Test
method testValueOf (line 30) | @Test
method testValueOfConstants (line 45) | @Test
method testValueOfPolar (line 59) | @Test
method testValueOfPolarConstants (line 65) | @Test
method testRe (line 71) | @Test
method testIm (line 76) | @Test
method testAdd (line 81) | @Test
method testSubtract (line 91) | @Test
method testMultiply (line 101) | @Test
method testDivide (line 113) | @Test
method testReciprocal (line 120) | @Test public void testReciprocal () {
method testConjugate (line 124) | @Test
method testNegate (line 135) | @Test
method testAbs (line 143) | @Test
method testAbsSquare (line 151) | @Test
method testAngleFailZero (line 159) | @Test(expected = ArithmeticException.class)
method testAngle (line 164) | @Test
method testIsReal (line 170) | @Test
method testEquals (line 177) | @Test
method testStrictEquals (line 191) | @Test
method testHashCode (line 206) | @Test
method testToString (line 217) | @Test
method assertCompareTo (line 227) | private void assertCompareTo(BigDecimal expected, BigDecimal actual) {
method assertDelta (line 231) | private void assertDelta(BigDecimal expected, BigDecimal actual, BigDe...
method assertDelta (line 236) | private void assertDelta(BigComplex expected, BigComplex actual, BigDe...
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigDecimalMathTest.java
class BigDecimalMathTest (line 22) | public class BigDecimalMathTest {
type TestLevel (line 24) | public enum TestLevel {
method testInternals (line 39) | @Test
method testInternalsAssertBigDecimalFail1 (line 56) | @Test(expected = java.lang.AssertionError.class)
method testInternalsBigDecimalFail2 (line 61) | @Test(expected = java.lang.AssertionError.class)
method testInternalsAssertThrowsFail1 (line 66) | @Test(expected = java.lang.AssertionError.class)
method testInternalsAssertThrowsFail2 (line 71) | @Test(expected = java.lang.AssertionError.class)
method testInternalsAssertThrowsFail3 (line 76) | @Test(expected = java.lang.AssertionError.class)
method testToBigDecimalFails (line 81) | @Test
method testToBigDecimal (line 118) | @Test
method assertToBigDecimal (line 164) | private static void assertToBigDecimal(String string) {
method assertToBigDecimalThrows (line 175) | private static void assertToBigDecimalThrows(String string) {
method testIsIntValue (line 181) | @Test
method testIsLongValue (line 198) | @Test
method testIsDoubleValue (line 215) | @Test
method testMantissa (line 235) | @Test
method testExponent (line 255) | @Test
method testSignificantDigits (line 271) | @Test
method testIntegralPart (line 304) | @Test
method testFractionalPart (line 320) | @Test
method testRound (line 337) | @Test
method testRoundWithTrailingZeroes (line 347) | @Test
method testE (line 375) | @Test
method testEUnlimitedFail (line 385) | @Test(expected = UnsupportedOperationException.class)
method testPi (line 390) | @Test
method testPiUnlimitedFail (line 400) | @Test(expected = UnsupportedOperationException.class)
method testBernoulli (line 405) | @Test
method testBernoulliNegative (line 428) | @Test(expected = ArithmeticException.class)
method testBernoulliUnlimited (line 433) | @Test
method testBernoulliUnlimitedFail (line 440) | @Test(expected = ArithmeticException.class)
method testReciprocal (line 445) | @Test
method testReciprocalUnlimited (line 451) | @Test
method testReciprocalUnlimitedFail (line 457) | @Test(expected = ArithmeticException.class)
method testReciprocalFail (line 462) | @Test(expected = ArithmeticException.class)
method testFactorialInt (line 467) | @Test
method testFactorialIntNegative (line 487) | @Test(expected = ArithmeticException.class)
method testFactorial (line 492) | @Test
method testFactorialNegative (line 502) | @Test
method testFactorialIntegerValues (line 512) | @Test
method testFactorialNegative1 (line 522) | @Test(expected = ArithmeticException.class)
method testFactorialNegative2 (line 527) | @Test(expected = ArithmeticException.class)
method testGamma (line 532) | @Test
method testGammaSlightlyPositive (line 542) | @Test
method testGammaNegative (line 552) | @Test
method testGammaIntegerValues (line 562) | @Test
method testPowIntZeroPowerNegative (line 572) | @Test(expected = ArithmeticException.class)
method testPowIntPositiveY (line 577) | @Test
method testPowIntUnlimited (line 590) | @Test
method testPowIntUnnecessary (line 596) | @Test
method testPowIntUnnecessaryFail (line 602) | @Test(expected = ArithmeticException.class)
method testPowIntUnlimitedFail (line 607) | @Test(expected = ArithmeticException.class)
method testPowIntHighAccuracy (line 612) | @Test
method testPowIntNegativeY (line 622) | @Test
method testPowIntSpecialCases (line 635) | @Test
method testPowInt0NegativeY (line 647) | @Test(expected = ArithmeticException.class)
method testPowPositiveX (line 653) | @Test
method testPowNegativeX (line 675) | @Test
method testPowSpecialCases (line 688) | @Test
method testPow0NegativeY (line 700) | @Test(expected = ArithmeticException.class)
method testPowHighAccuracy1 (line 706) | @Test
method testPowHighAccuracy2 (line 717) | public void testPowHighAccuracy2() {
method testPowLargeInt (line 726) | @Test
method testPowVeryLargeInt (line 741) | @Test
method testPowRandom (line 755) | @Test
method testPowOverflow (line 766) | @Test(expected = ArithmeticException.class)
method testPowUnlimitedFail (line 771) | @Test(expected = UnsupportedOperationException.class)
method testSqrt (line 776) | @Test
method testSqrtUnlimitedFail (line 787) | @Test(expected = UnsupportedOperationException.class)
method testSqrtHighAccuracy (line 792) | @Test
method testSqrtHuge (line 802) | @Test
method testSqrtRandom (line 809) | @Test
method testSqrtNegative (line 832) | @Test(expected = ArithmeticException.class)
method testRootSqrtCbrt (line 837) | @Test
method testRoot (line 853) | @Test
method testRootZeroN (line 867) | @Test(expected = ArithmeticException.class)
method testRootNegativeN (line 872) | @Test(expected = ArithmeticException.class)
method testRootNegativeX (line 877) | @Test(expected = ArithmeticException.class)
method testRootUnlimitedFail (line 882) | @Test(expected = UnsupportedOperationException.class)
method testRootHighAccuracy1 (line 887) | @Test
method testRootHighAccuracy2 (line 897) | @Test
method testRootRandom (line 907) | @Test
method testRootNegative (line 918) | @Test(expected = ArithmeticException.class)
method testLogRange10 (line 923) | @Test
method testLogRange100 (line 940) | @Test
method testLogHighAccuracy1 (line 957) | @Test
method testLogHighAccuracy2 (line 967) | @Test
method testLogHighAccuracy3 (line 977) | @Test
method testLogNotorious1 (line 987) | @Test
method testLogSmall (line 998) | @Test
method testLogHuge (line 1005) | @Test
method testLog10WithPositivePowersOfTen (line 1012) | @Test
method testLog10WithNegativePowersOfTen (line 1026) | @Test
method testLog10UnlimitedFail (line 1040) | @Test(expected = UnsupportedOperationException.class)
method testLogRandom (line 1045) | @Test
method testLog2Random (line 1055) | @Test
method testLog2UnlimitedFail (line 1065) | @Test(expected = UnsupportedOperationException.class)
method testLogNegative (line 1070) | @Test(expected = ArithmeticException.class)
method testLogUnlimitedFail (line 1075) | @Test(expected = UnsupportedOperationException.class)
method testExp (line 1080) | @Test
method testExpHuge (line 1090) | @Test
method testExp1E (line 1099) | @Test
method testExpHighAccuracy1 (line 1109) | @Test
method testExpHighAccuracy2 (line 1119) | @Test
method testExpRandom (line 1129) | @Test
method testExpUnlimitedFail (line 1139) | @Test(expected = UnsupportedOperationException.class)
method testSin (line 1144) | @Test
method testSinHighAccuracy (line 1154) | @Test
method testSinRandom (line 1164) | @Test
method testSinRandom (line 1168) | public void testSinRandom(int count) {
method testSinRandomMultiThreaded (line 1177) | @Test
method testSinUnlimitedFail (line 1182) | @Test(expected = UnsupportedOperationException.class)
method testAsin (line 1187) | @Test
method testAsinRandom (line 1197) | @Test
method testAsinRandom (line 1202) | public void testAsinRandom(int count) {
method testAsinRandomMultiThreaded (line 1211) | @Test
method testAsinGreaterOne (line 1217) | @Test(expected = ArithmeticException.class)
method testAsinSmallerMinusOne (line 1222) | @Test(expected = ArithmeticException.class)
method testAsinUnlimitedFail (line 1227) | @Test(expected = UnsupportedOperationException.class)
method testCos (line 1232) | @Test
method testCosHighAccuracy (line 1242) | @Test
method testCosRandom (line 1252) | @Test
method testCosRandom (line 1257) | public void testCosRandom(int count) {
method testCosRandomMultiThreaded (line 1266) | @Test
method testCosUnlimitedFail (line 1272) | @Test(expected = UnsupportedOperationException.class)
method testAcosRandom (line 1277) | @Test
method testAcosRandom (line 1282) | public void testAcosRandom(int count) {
method testAcosRandomMultiThreaded (line 1291) | @Test
method testAcosMinusOne (line 1296) | @Test
method testAcosGreaterOne (line 1306) | @Test(expected = ArithmeticException.class)
method testAcosSmallerMinusOne (line 1311) | @Test(expected = ArithmeticException.class)
method testAcosUnlimitedFail (line 1316) | @Test(expected = UnsupportedOperationException.class)
method testTan (line 1321) | @Test
method testTanRandom (line 1331) | @Test
method testTanRandom (line 1336) | public void testTanRandom(int count) {
method testTanRandomMultiThreaded (line 1345) | @Test
method testTanUnlimitedFail (line 1350) | @Test(expected = UnsupportedOperationException.class)
method testAtanRandom (line 1355) | @Test
method testAtanRandom (line 1360) | public void testAtanRandom(int count) {
method testAtanRandomMultiThreaded (line 1369) | @Test
method testAtan2ZeroZero (line 1374) | @Test(expected = ArithmeticException.class)
method testAtan2 (line 1379) | @Test
method testAtan2HighAccuracy (line 1389) | @Test
method testAtan2Random (line 1399) | @Test
method testAtan2Random (line 1404) | public void testAtan2Random(int count) {
method testAtan2RandomMultiThreaded (line 1421) | @Test
method testAtanUnlimitedFail (line 1426) | @Test(expected = UnsupportedOperationException.class)
method testCot (line 1431) | @Test
method cot (line 1441) | private double cot(double x) {
method testCotUnlimitedFail (line 1445) | @Test(expected = UnsupportedOperationException.class)
method testSinhRandom (line 1450) | @Test
method testSinhRandom (line 1455) | public void testSinhRandom(int count) {
method testSinhRandomMultiThreaded (line 1464) | @Test
method testAsinhRandom (line 1469) | @Test
method testAsinhRandom (line 1474) | public void testAsinhRandom(int count) {
method testAsinhRandomMultiThreaded (line 1483) | @Test
method testAsinhUnlimitedFail (line 1488) | @Test(expected = UnsupportedOperationException.class)
method asinh (line 1493) | public static double asinh(double x) {
method testAcoshRandom (line 1497) | @Test
method testAcoshRandom (line 1502) | public void testAcoshRandom(int count) {
method testAcoshRandomMultiThreaded (line 1511) | @Test
method testAcoshUnlimitedFail (line 1516) | @Test(expected = UnsupportedOperationException.class)
method acosh (line 1521) | public static double acosh(double x) {
method testAtanhRandom (line 1525) | @Test
method testAtanhRandom (line 1530) | public void testAtanhRandom(int count) {
method testAtanhRandomMultiThreaded (line 1539) | @Test
method testAtanhFailOne (line 1544) | @Test(expected = ArithmeticException.class)
method testAtanhFailMinusOne (line 1549) | @Test(expected = ArithmeticException.class)
method testAtanhUnlimitedFail (line 1554) | @Test(expected = UnsupportedOperationException.class)
method atanh (line 1559) | public static double atanh(double x) {
method testAcothRandom (line 1563) | @Test
method testAcothRandom (line 1568) | public void testAcothRandom(int count) {
method testAcothRandomMultiThreaded (line 1584) | @Test
method testAcothUnlimitedFail (line 1589) | @Test(expected = UnsupportedOperationException.class)
method acoth (line 1594) | public static double acoth(double x) {
method testCoshRandom (line 1598) | @Test
method testCoshRandom (line 1603) | public void testCoshRandom(int count) {
method testCoshRandomMultiThreaded (line 1612) | @Test
method testCoshUnlimitedFail (line 1617) | @Test(expected = UnsupportedOperationException.class)
method testTanhRandom (line 1622) | @Test
method testTanhRandom (line 1627) | public void testTanhRandom(int count) {
method testTanhRandomMultiThreaded (line 1636) | @Test
method testTanhUnlimitedFail (line 1641) | @Test(expected = UnsupportedOperationException.class)
method testCothHighAccuracy (line 1646) | @Test
method testCothRandom (line 1656) | @Test
method testCothRandom (line 1661) | public void testCothRandom(int count) {
method testCothRandomMultiThreaded (line 1670) | @Test
method testCothUnlimitedFail (line 1675) | @Test(expected = UnsupportedOperationException.class)
method coth (line 1680) | private static double coth(double x) {
method testSinAsinRandom (line 1684) | @Test
method testCosAcosRandom (line 1695) | @Test
method testTanAtanRandom (line 1706) | @Test
method testCotAcotRandom (line 1717) | @Test
method testCotEqualZero (line 1734) | @Test(expected = ArithmeticException.class)
method testSinhAsinhRandom (line 1739) | @Test
method testCoshAcoshRandom (line 1750) | @Test
method testTanhAtanhRandom (line 1761) | @Test
method testCothAcothRandom (line 1772) | @Test
method testPow2Random (line 1783) | @Test
method testSqrtPow2Random (line 1794) | @Test
method testSqrtRootRandom (line 1805) | @Test
method testRootPowRandom (line 1817) | @Test
method testLogExpRandom (line 1830) | @Test
method testLog10PowRandom (line 1862) | @Test
method testToDegrees (line 1873) | @Test
method testToRadians (line 1881) | @Test
method assertPrecisionCalculation (line 1889) | private void assertPrecisionCalculation(Function<MathContext, BigDecim...
method assertPrecisionCalculation (line 1895) | private void assertPrecisionCalculation(BigDecimal expected, Function<...
method assertPrecisionCalculation (line 1899) | private void assertPrecisionCalculation(BigDecimal expected, Function<...
type Function3 (line 1913) | private static interface Function3<T1, T2, T3, R> {
method apply (line 1914) | R apply(T1 t1, T2 t2, T3 t3);
method assertRandomCalculation (line 1917) | void assertRandomCalculation(int count, String functionName, Function<...
method assertRandomCalculation (line 1946) | private static void assertRandomCalculation(int count, String function...
method assertRandomCalculation (line 1974) | private void assertRandomCalculation(int count, String function1Name, ...
method assertBigDecimal (line 1995) | private static boolean assertBigDecimal(BigDecimal expected, BigDecima...
method assertBigDecimal (line 1999) | private static boolean assertBigDecimal(String description, BigDecimal...
method randomBigDecimal (line 2009) | private static BigDecimal randomBigDecimal(Random random, MathContext ...
method randomBigDecimalWithExponent (line 2021) | private static BigDecimal randomBigDecimalWithExponent(Random random, ...
method assertThrows (line 2026) | public static Exception assertThrows(Class<? extends Exception> except...
method assertThrows (line 2030) | public static Exception assertThrows(Class<? extends Exception> except...
method toCheck (line 2047) | private static BigDecimal toCheck(double value) {
method toCheck (line 2060) | private static BigDecimal toCheck(BigDecimal value) {
method adaptCount (line 2064) | private int adaptCount(int count) {
method getTestLevel (line 2076) | private static TestLevel getTestLevel() {
method getMaxPrecision (line 2091) | private static int getMaxPrecision() {
method getPrecisionStep (line 2103) | private static int getPrecisionStep() {
method getRangeStep (line 2115) | private static double getRangeStep(double step) {
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigFloatTest.java
class BigFloatTest (line 18) | public class BigFloatTest {
method testContext (line 28) | @Test
method testValueOf (line 47) | @Test
method testValueOfRounding (line 63) | @Test
method testToDouble (line 76) | @Test
method testToLong (line 82) | @Test
method testToInt (line 88) | @Test
method testIsIntValue (line 94) | @Test
method testIsDoubleValue (line 105) | @Test
method testGetMantissa (line 119) | @Test
method testGetExponent (line 125) | @Test
method testGetIntegralPart (line 131) | @Test
method testGetFractionalPart (line 137) | @Test
method testEquals (line 143) | @Test
method testHashCode (line 171) | @Test
method testToString (line 188) | @Test
method testPi (line 197) | @Test
method testE (line 203) | @Test
method testSignum (line 209) | @Test
method testIsNegative (line 222) | @Test
method testIsZero (line 235) | @Test
method testIsPositive (line 248) | @Test
method testIsEqual (line 261) | @Test
method testIsLessThan (line 269) | @Test
method testIsLessThanOrEqual (line 277) | @Test
method testIsGreaterThan (line 285) | @Test
method testIsGreaterThanOrEqual (line 293) | @Test
method testCompareTo (line 301) | @Test
method testAdd (line 309) | @Test
method testAddBigFloat (line 319) | @Test
method testSubtract (line 330) | @Test
method testMultiply (line 340) | @Test
method testDivide (line 350) | @Test
method testRemainder (line 360) | @Test
method testPow (line 370) | @Test
method testRoot (line 380) | @Test
method testFactorial (line 390) | @Test
method testLog (line 396) | @Test
method testLog2 (line 403) | @Test
method testLog10 (line 410) | @Test
method testExp (line 417) | @Test
method testSqrt (line 424) | @Test
method testPow2 (line 431) | @Test
method testRoot2 (line 438) | @Test
method testPowStatic (line 445) | @Test
method testRootStatic (line 452) | @Test
method testSin (line 459) | @Test
method testCos (line 468) | @Test
method testTan (line 477) | @Test
method testCot (line 486) | @Test
method testAsin (line 493) | @Test
method testAcos (line 504) | @Test
method testAtan (line 511) | @Test
method testAcot (line 520) | @Test
method testSinh (line 529) | @Test
method testCosh (line 538) | @Test
method testCoth (line 547) | @Test
method testTanh (line 554) | @Test
method testAsinh (line 563) | @Test
method testAcosh (line 572) | @Test
method testAtanh (line 579) | @Test
method testAcoth (line 586) | @Test
method testAbs (line 593) | @Test
method testNegate (line 601) | @Test
method testMax (line 609) | @Test
method testMin (line 619) | @Test
method testSpecial (line 629) | @Test
method testSpecialMath (line 645) | @Test
method testParseUnsigned (line 793) | @Test
method testSerialize (line 823) | @Test
type Op (line 868) | enum Op {
method Op (line 878) | Op(String symbol) {
method testOperationsWithSpecial (line 1033) | @Test
method testCompareTo_Specials (line 1153) | @Test
method testComparisons_Specials (line 1382) | @Test
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigRationalTest.java
class BigRationalTest (line 29) | public class BigRationalTest {
method testSerialize (line 32) | @Test
method assertSerialize (line 39) | private void assertSerialize(Object object) throws IOException, ClassN...
method serialize (line 43) | private byte[] serialize(Object object) throws IOException {
method deserialize (line 51) | private Object deserialize(byte[] bytes) throws IOException, ClassNotF...
method testValueOfInt (line 60) | @Test
method testValueOfRationalInt (line 73) | @Test
method testValueOfIntegerRationalInt (line 93) | @Test
method testValueOfIntegerRationalIntDenominator0 (line 104) | @Test(expected = ArithmeticException.class)
method testValueOfIntegerRationalIntAll0 (line 112) | @Test(expected = ArithmeticException.class)
method testValueOfIntegerRationalIntNegativeFractionNumerator (line 120) | @Test(expected = ArithmeticException.class)
method testValueOfIntegerRationalIntNegativeFractionDenominator (line 128) | @Test(expected = ArithmeticException.class)
method testValueOfRationalBigInteger (line 136) | @Test
method testValueOfRationalIntDivideByZero (line 150) | @Test(expected = ArithmeticException.class)
method testValueOfDouble (line 158) | @Test
method testValueOfDoublePositiveInfinity (line 173) | @Test(expected=NumberFormatException.class)
method testValueOfDoubleNegativeInfinity (line 181) | @Test(expected=NumberFormatException.class)
method testValueOfDoubleNaN (line 189) | @Test(expected=NumberFormatException.class)
method testValueOfBigInteger (line 197) | @Test
method testValueOfBigDecimal (line 210) | @Test
method testValueOfRationalBigDecimal (line 225) | @Test
method testValueOfString (line 240) | @Test
method testValueOfString3 (line 261) | @Test
method testIsZero (line 283) | @Test
method testIsInteger (line 296) | @Test
method testToString (line 311) | @Test
method testToRationalString (line 324) | @Test
method testToIntegerRationalString (line 338) | @Test
method testToPlainString (line 354) | @Test
method testToDouble (line 369) | @Test
method testToFloat (line 398) | @Test
method testIntegerPart (line 426) | @Test
method testFractionPart (line 438) | @Test
method testWithPrecision (line 450) | @Test
method testWithPrecisionIllegalPrecision (line 466) | @Test(expected=IllegalArgumentException.class)
method testWithScale (line 474) | @Test
method testEquals (line 497) | @Test
method testCompareTo (line 514) | @Test
method testHashCode (line 526) | @Test
method testMin (line 537) | @Test
method testMax (line 550) | @Test
method testSameZERO (line 563) | @Test
method testSameONE (line 576) | @Test
method testNegate (line 592) | @Test
method testReciprocal (line 602) | @Test
method testReciprocalZero (line 612) | @Test(expected = ArithmeticException.class)
method testAbs (line 620) | @Test
method testAbsOptimized (line 629) | @Test
method testSignum (line 638) | @Test
method testIncrement (line 648) | @Test
method testDecrement (line 657) | @Test
method testAdd (line 666) | @Test
method testAddOptimized (line 677) | @Test
method testAddInt (line 685) | @Test
method testAddBigInteger (line 695) | @Test
method testSubtract (line 705) | @Test
method testSubtractOptimized (line 716) | @Test
method testSubtractInt (line 724) | @Test
method testSubtractBigInteger (line 734) | @Test
method testMultiply (line 744) | @Test
method testMultiplyOptimized (line 762) | @Test
method testMultiplyInt (line 776) | @Test
method testMultiplyBigInteger (line 784) | @Test
method testDivide (line 795) | @Test
method testDivideInt (line 805) | @Test
method testDivideBigInteger (line 813) | @Test
method testDivideByZero (line 823) | @Test(expected = ArithmeticException.class)
method testPowInt (line 831) | @Test
method testBernoulli (line 848) | @Test
method testBernoulliNegative (line 871) | @Test(expected = ArithmeticException.class)
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/DefaultBigDecimalMathTest.java
class DefaultBigDecimalMathTest (line 13) | public class DefaultBigDecimalMathTest {
method testDefaultMathContext (line 14) | @Test
method testRound (line 25) | @Test
method testRoundWithTrailingZeroes (line 32) | @Test
method testAdd (line 39) | @Test
method testSubtract (line 46) | @Test
method testMultiply (line 53) | @Test
method testDivide (line 60) | @Test
method testRemainder (line 67) | @Test
method testE (line 74) | @Test
method testPi (line 81) | @Test
method testBernoulli (line 88) | @Test
method testReciprocal (line 95) | @Test
method testFactorial (line 102) | @Test
method testGamma (line 109) | @Test
method testPowInt (line 116) | @Test
method testPow (line 123) | @Test
method testSqrt (line 130) | @Test
method testRoot (line 137) | @Test
method testLog (line 144) | @Test
method testLog2 (line 151) | @Test
method testLog10 (line 158) | @Test
method testExp (line 165) | @Test
method testSin (line 172) | @Test
method testAsin (line 179) | @Test
method testCos (line 186) | @Test
method testAcos (line 193) | @Test
method testTan (line 200) | @Test
method testAtan (line 207) | @Test
method testAtan2 (line 214) | @Test
method testCot (line 221) | @Test
method testAcot (line 228) | @Test
method testSinh (line 235) | @Test
method testAsinh (line 242) | @Test
method testCosh (line 249) | @Test
method testAcosh (line 256) | @Test
method testTanh (line 263) | @Test
method testAtanh (line 270) | @Test
method testCoth (line 277) | @Test
method testAcoth (line 284) | @Test
method testCreateLocalMathContext (line 291) | @Test
method testWithLocalMathContext (line 306) | @Test
method testNestedWithLocalMathContext (line 321) | @Test
method assertNestedWithLocalMathContext (line 326) | private void assertNestedWithLocalMathContext(int precision1, int prec...
method testNestedWithLocalMathContextMultiThreaded (line 345) | @Test
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/stream/BigDecimalStreamTest.java
class BigDecimalStreamTest (line 15) | public class BigDecimalStreamTest {
method testRangeStepZero (line 17) | @Test(expected = IllegalArgumentException.class)
method testRangeClosedStepZero (line 22) | @Test(expected = IllegalArgumentException.class)
method testRangeStep1 (line 27) | @Test
method testRangeStep3 (line 35) | @Test
method testRangeLongStep3 (line 62) | @Test
method testRangeDoubleStep3 (line 74) | @Test
method testRangeClosedStep3 (line 86) | @Test
method testRangeClosedLongStep3 (line 114) | @Test
method testRangeClosedDoubleStep3 (line 127) | @Test
method testRangeStepMinus1 (line 140) | @Test
method testRangeClosedStep1 (line 148) | @Test
method testRangeClosedStepMinus1 (line 156) | @Test
method testRangeParallel (line 164) | @Test
method testRangeDown (line 173) | @Test
method testRangeClosedDown (line 181) | @Test
method testSingleStep (line 189) | @Test
method assertList (line 200) | private void assertList(List<BigDecimal> list, long startInclusive, lo...
method assertListClosed (line 207) | private void assertListClosed(List<BigDecimal> list, long startInclusi...
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/stream/BigFloatStreamTest.java
class BigFloatStreamTest (line 18) | public class BigFloatStreamTest {
method testRangeStepZero (line 20) | @Test(expected = IllegalArgumentException.class)
method testRangeClosedStepZero (line 26) | @Test(expected = IllegalArgumentException.class)
method testRangeStep1 (line 32) | @Test
method testRangeStep3 (line 41) | @Test
method testRangeLongStep3 (line 69) | @Test
method testRangeDoubleStep3 (line 82) | @Test
method testRangeClosedStep3 (line 95) | @Test
method testRangeClosedLongStep3 (line 124) | @Test
method testRangeClosedDoubleStep3 (line 138) | @Test
method testRangeStepMinus1 (line 152) | @Test
method testRangeClosedStep1 (line 161) | @Test
method testRangeClosedStepMinus1 (line 170) | @Test
method testRangeParallel (line 179) | @Test
method testRangeDown (line 189) | @Test
method testRangeClosedDown (line 198) | @Test
method testSingleStep (line 207) | @Test
method assertList (line 219) | private void assertList(List<BigFloat> list, long startInclusive, long...
method assertListClosed (line 229) | private void assertListClosed(List<BigFloat> list, long startInclusive...
FILE: ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/util/ThreadUtil.java
class ThreadUtil (line 7) | public class ThreadUtil {
method runMultiThreaded (line 8) | public static void runMultiThreaded(Runnable runnable) throws Throwable {
method runMultiThreaded (line 12) | public static void runMultiThreaded(int threadCount, Runnable runnable...
FILE: docs/javadoc/v1.3.0/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
FILE: docs/javadoc/v2.0.0/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
FILE: docs/javadoc/v2.0.1/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
FILE: docs/javadoc/v2.1.0/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
FILE: docs/javadoc/v2.2.0/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
FILE: docs/javadoc/v2.2.1/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
FILE: docs/javadoc/v2.3.0/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
FILE: docs/javadoc/v2.3.1/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
FILE: docs/javadoc/v2.3.2/script.js
function show (line 1) | function show(type)
function updateTabs (line 16) | function updateTabs(type)
Copy disabled (too large)
Download .json
Condensed preview — 606 files, each showing path, character count, and a content snippet. Download the .json file for the full structured content (15,107K chars).
[
{
"path": ".gitignore",
"chars": 145,
"preview": "# gradle stuff\n\n.gradle\nbuild\ngradle.properties\n\n# Eclipse IDE stuff\n\n.project\n.classpath\nbin\nout\n.settings\n\n# IntelliJ "
},
{
"path": ".travis.yml",
"chars": 1284,
"preview": "env:\n - BIGDECIMALTEST_LEVEL=Medium\n\ndist: trusty\nlanguage: java\njdk:\n - oraclejdk11\n\nbefore_install:\n - chmod +x gra"
},
{
"path": "LICENSE.txt",
"chars": 1073,
"preview": "MIT License\n\nCopyright (c) 2017 Eric Obermühlner\n\nPermission is hereby granted, free of charge, to any person obtaining "
},
{
"path": "README.md",
"chars": 23696,
"preview": "[](https://travis-ci.org/eobermuhlner/"
},
{
"path": "build.gradle",
"chars": 344,
"preview": "buildscript {\r\n ext.kotlin_version = '1.1.3'\r\n ext.dokka_version = '0.9.15'\r\n\r\n repositories {\r\n mavenCe"
},
{
"path": "ch.obermuhlner.math.big/build.gradle",
"chars": 3354,
"preview": "\nplugins {\n id 'org.sonarqube' version '2.7'\n id 'java'\n id 'eclipse'\n id 'maven'\n id 'signing'\n id 'j"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigComplex.java",
"chars": 18694,
"preview": "package ch.obermuhlner.math.big;\n\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.util.Objects;\n\n"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigComplexMath.java",
"chars": 18913,
"preview": "package ch.obermuhlner.math.big;\n\nimport static ch.obermuhlner.math.big.BigComplex.I;\n\nimport java.math.BigDecimal;\nimpo"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigDecimalMath.java",
"chars": 66706,
"preview": "package ch.obermuhlner.math.big;\n\nimport static java.math.BigDecimal.ONE;\nimport static java.math.BigDecimal.TEN;\nimport"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigFloat.java",
"chars": 50350,
"preview": "package ch.obermuhlner.math.big;\n\nimport java.io.Serializable;\nimport java.math.BigDecimal;\nimport java.math.MathContext"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/BigRational.java",
"chars": 35286,
"preview": "package ch.obermuhlner.math.big;\r\n\r\nimport java.io.Serializable;\r\nimport java.math.BigDecimal;\r\nimport java.math.BigInte"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/DefaultBigDecimalMath.java",
"chars": 32197,
"preview": "package ch.obermuhlner.math.big;\n\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMo"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/AsinCalculator.java",
"chars": 1385,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport ch.ob"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/AtanhCalculator.java",
"chars": 979,
"preview": "package ch.obermuhlner.math.big.internal;\n\nimport ch.obermuhlner.math.big.BigRational;\n\nimport java.math.BigDecimal;\nimp"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/CosCalculator.java",
"chars": 1251,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport ch.ob"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/CoshCalculator.java",
"chars": 1124,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport ch.ob"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/ExpCalculator.java",
"chars": 1096,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport ch.ob"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerIterator.java",
"chars": 836,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\n\r\n/**\r\n * Iterator over the powers of a value"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerNIterator.java",
"chars": 675,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\n/**\r\n * {@li"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerTwoNIterator.java",
"chars": 727,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\n/**\r\n * {@li"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerTwoNMinusOneIterator.java",
"chars": 788,
"preview": "package ch.obermuhlner.math.big.internal;\n\nimport ch.obermuhlner.math.big.BigDecimalMath;\n\nimport java.math.BigDecimal;\n"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/PowerTwoNPlusOneIterator.java",
"chars": 730,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\n/**\r\n * {@li"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/SeriesCalculator.java",
"chars": 4084,
"preview": "package ch.obermuhlner.math.big.internal;\n\nimport ch.obermuhlner.math.big.BigRational;\n\nimport java.math.BigDecimal;\nimp"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/SinCalculator.java",
"chars": 1316,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport ch.ob"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/internal/SinhCalculator.java",
"chars": 1189,
"preview": "package ch.obermuhlner.math.big.internal;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport ch.ob"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/stream/BigDecimalStream.java",
"chars": 9396,
"preview": "package ch.obermuhlner.math.big.stream;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\nimport java.util"
},
{
"path": "ch.obermuhlner.math.big/src/main/java/ch/obermuhlner/math/big/stream/BigFloatStream.java",
"chars": 8404,
"preview": "package ch.obermuhlner.math.big.stream;\r\n\r\nimport java.util.Comparator;\r\nimport java.util.Spliterator;\r\nimport java.util"
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigComplexMathTest.java",
"chars": 7936,
"preview": "package ch.obermuhlner.math.big;\n\nimport static org.junit.Assert.assertEquals;\n\nimport java.math.BigDecimal;\nimport java"
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigComplexTest.java",
"chars": 10607,
"preview": "package ch.obermuhlner.math.big;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertNotE"
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigDecimalMathTest.java",
"chars": 105919,
"preview": "package ch.obermuhlner.math.big;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue"
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigFloatTest.java",
"chars": 47718,
"preview": "package ch.obermuhlner.math.big;\n\nimport ch.obermuhlner.math.big.BigFloat.*;\nimport org.junit.Test;\n\nimport java.io.Byte"
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/BigRationalTest.java",
"chars": 29814,
"preview": "package ch.obermuhlner.math.big;\r\n\r\nimport static ch.obermuhlner.math.big.BigRational.ONE;\r\nimport static ch.obermuhlner"
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/DefaultBigDecimalMathTest.java",
"chars": 13121,
"preview": "package ch.obermuhlner.math.big;\n\nimport org.junit.Test;\n\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimp"
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/stream/BigDecimalStreamTest.java",
"chars": 11869,
"preview": "package ch.obermuhlner.math.big.stream;\r\n\r\nimport static org.junit.Assert.assertEquals;\r\nimport static org.junit.Assert."
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/math/big/stream/BigFloatStreamTest.java",
"chars": 11236,
"preview": "package ch.obermuhlner.math.big.stream;\r\n\r\nimport static org.junit.Assert.assertEquals;\r\nimport static org.junit.Assert."
},
{
"path": "ch.obermuhlner.math.big/src/test/java/ch/obermuhlner/util/ThreadUtil.java",
"chars": 1367,
"preview": "package ch.obermuhlner.util;\n\nimport java.util.concurrent.Callable;\nimport java.util.concurrent.CountDownLatch;\nimport j"
},
{
"path": "ch.obermuhlner.math.big.example/build.gradle",
"chars": 391,
"preview": "apply plugin: 'java'\napply plugin: 'application'\napply plugin: 'eclipse'\n\nmainClassName = 'ch.obermuhlner.math.big.examp"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/csv2chart.properties",
"chars": 128,
"preview": "out.format=png\r\nout.dir=images\r\ny-axis=nanoseconds\r\ndata-color-saturation=1.0\r\ndata-color-brightness=0.6\r\ndata-color-alp"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_adaptive_log_precisions_to_1000.csv",
"chars": 5576,
"preview": "precision, logFix,logAdaptive10,logAdaptive17,logAdaptive20,logAdaptive25\r\n number, number, number, number, number"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_atan2_y_5_x_from_-10_to_10.csv",
"chars": 3810,
"preview": " x, atan2\n number, number\n -10.000,11353.000\n -9.900,11370.100\n -9.800,11605.300\n -9.700,11743.600\n -9.600"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_atan2_y_from_-10_to_10_x_5.csv",
"chars": 3808,
"preview": " x, atan2\n number, number\n -10.000,11757.000\n -9.900,11834.800\n -9.800,11907.000\n -9.700,12518.600\n -9.600"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_atan2_yx_from_-10_to_10.csv",
"chars": 2655,
"preview": ", -10, -9.0, -8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0\n-10,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_atan2_yx_from_-10_to_10.properties",
"chars": 124,
"preview": "chart=heat\r\ntitle=Performance atan2(y,x)\r\nmatrix-x-values=true\r\nmatrix-y-values=true\r\nx-axis=x\r\ny-axis=y\r\nz-axis=nanosec"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_atanh_funcs_from_-1_to_1_impl.csv",
"chars": 5545,
"preview": " x, atanh,atanhMaclaurin\n number, number, number\n -1.000, 0.000, 0.000\n -0.990,4042.400,188861.800\n -0"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_basic_operations_fast_precisions_to_10000.csv",
"chars": 2754,
"preview": " value, add,subtract\n number, number, number\n 0, 0.100, 0.100\n 100, 0.241, 0.100\n 200, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_basic_operations_fast_precisions_to_100000.csv",
"chars": 2754,
"preview": " value, add,subtract\n number, number, number\n 0, 0.100, 0.150\n 1000, 4.200, 1.800\n 2000, 1"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_basic_operations_slow2_precisions_to_10000.csv",
"chars": 2758,
"preview": " value,multiply 0.5,divide 2\n number, number, number\n 0, 0.056, 0.100\n 100, 0.370, 0.399\n 200"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_basic_operations_slow2_precisions_to_100000.csv",
"chars": 2758,
"preview": " value,multiply 0.5,divide 2\n number, number, number\n 0, 0.100, 0.100\n 1000, 5.270, 5.310\n 2000"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_basic_operations_slow_precisions_to_10000.csv",
"chars": 2754,
"preview": " value,multiply, divide\n number, number, number\n 0, 0.093, 0.209\n 100, 1.140, 1.100\n 200, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_basic_operations_slow_precisions_to_100000.csv",
"chars": 2874,
"preview": " value,multiply, divide\n number, number, number\n 0, 0.100, 0.200\n 1000, 32.310, 27.470\n 2000, 8"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_bigdec_string_impl_precisions_to_10000.csv",
"chars": 5538,
"preview": " value,toBigDecimal/3,toBigDecimal/4,toBigDecimal/5,toBigDecimal/6,toBigDecimal/8\n number, number, number, number,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_bigdec_string_impl_precisions_to_100000.csv",
"chars": 467,
"preview": " value,toBigDecimal/4,toBigDecimal/8,toBigDecimal/16\n number, number, number, number\n 0, 0.100, 0.100, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_bigdec_string_impl_precisions_to_2000.csv",
"chars": 108138,
"preview": " value,toBigDecimal/3,toBigDecimal/4,toBigDecimal/5,toBigDecimal/6,toBigDecimal/8\n number, number, number, number,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_bigdec_string_precisions_to_10000.csv",
"chars": 2776,
"preview": " value,BigDecimal(String),toBigDecimal(String)\n number, number, number\n 0, 0.100, 0.100\n 200, 3.700"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_bigdec_string_precisions_to_100000.csv",
"chars": 2942,
"preview": " value,BigDecimal(String),toBigDecimal(String)\n number, number, number\n 0, 0.100, 0.100\n 1000, 29.370"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_bigdec_string_precisions_to_1000000.csv",
"chars": 394,
"preview": " value,BigDecimal(String),toBigDecimal(String)\n number, number, number\n 0, 0.100, 0.100\n 100000,204422.8"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_bigdec_string_precisions_to_2000.csv",
"chars": 54076,
"preview": " value,BigDecimal(String),toBigDecimal(String)\n number, number, number\n 0, 0.000, 0.000\n 1, 0.000"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_cos_funcs_from_0_to_3.csv",
"chars": 8484,
"preview": " x, cos, cosNEW\r\n number, number, number\r\n 0.000, 128, 97\r\n 0.010, 519, 428\r\n 0.020"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_exp_funcs_from_0_to_1.csv",
"chars": 2884,
"preview": " x, exp, expNEW\r\n number, number, number\r\n 0.000, 2, 203\r\n 0.010, 906, 851\r\n 0.020"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_exp_funcs_from_0_to_10.csv",
"chars": 28084,
"preview": " x, exp, expNEW\r\n number, number, number\r\n 0.000, 7, 211\r\n 0.010, 972, 875\r\n 0.020"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_exp_funcs_from_0_to_3.csv",
"chars": 28084,
"preview": " x, exp, expNEW\r\n number, number, number\r\n 0.000, 1, 103\r\n 0.001, 765, 720\r\n 0.002"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_factorial_impl_loops_values_to_1000.csv",
"chars": 27058,
"preview": " value, loop,loopDivLimit\n number, number, number\n 0, 0.030, 0.050\n 1, 0.000, 0.000\n 2"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_factorial_impl_recursion_values_to_100.csv",
"chars": 2767,
"preview": " value,recursion,recursionAdaptive_65\n number, number, number\n 0, 0.000, 0.000\n 1, 0.000, 0.000"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_factorial_impl_recursion_values_to_1000.csv",
"chars": 54158,
"preview": " value,recursion,recursionAdaptive_40,recursionAdaptive_60,recursionAdaptive_80,recursionAdaptive_100\n number, numbe"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_factorial_impl_values_to_100.csv",
"chars": 3675,
"preview": " value, loop,switchloop,recursion\n number, number, number, number\n 0, 0.000, 0.000, 0.000\n 1,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_factorial_impl_values_to_1000.csv",
"chars": 54115,
"preview": " value, loop,switchloop,recursion, simple,loopDivLimit\n number, number, number, number, number, number\n "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_factorial_impl_values_to_200.csv",
"chars": 7275,
"preview": " value, loop,switchloop,recursion\n number, number, number, number\n 0, 0.100, 0.040, 0.050\n 1,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_factorial_impl_values_to_500.csv",
"chars": 3675,
"preview": " value, loop,switchloop,recursion\n number, number, number, number\n 0, 0.062, 0.000, 0.000\n 5,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_fast_funcs_from_-10_to_10.csv",
"chars": 14616,
"preview": " x, exp, sqrt, root2, root3, sin, cos, tan\n number, number, number, number, number, n"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_fast_funcs_from_0_to_10.csv",
"chars": 72216,
"preview": " x, exp, sqrt, root2, root3, sin, cos, tan\n number, number, number, number, number, n"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_fast_funcs_from_0_to_100.csv",
"chars": 72216,
"preview": " x, exp, sqrt, root2, root3, sin, cos, tan\n number, number, number, number, number, n"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_fast_funcs_from_0_to_2.csv",
"chars": 29016,
"preview": " x, exp, sqrt, root2, root3, sin, cos, tan\n number, number, number, number, number, n"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_fast_funcs_precisions_to_1000.csv",
"chars": 6440,
"preview": "precision, exp, sqrt, root2, root3, sin, cos\n number, number, number, number, number, number, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_hyperbolic_funcs_from_0_to_2.csv",
"chars": 12789,
"preview": " x, sinh, cosh, tanh, asinh, acosh, atanh\n number, number, number, number, number, number, n"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_java9_sqrt_from_0_to_10.csv",
"chars": 27083,
"preview": " x, sqrt,java9_sqrt\n number, number, number\n 0.000, 0.000, 0.000\n 0.010, 0.000, 0.000\n 0.020, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_java9_sqrt_from_0_to_100.csv",
"chars": 27083,
"preview": " x, sqrt,java9_sqrt\n number, number, number\n 0.000, 0.000, 0.000\n 0.100, 27.164, 26.180\n 0.200, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_java9_sqrt_from_0_to_10000.csv",
"chars": 27084,
"preview": " x, sqrt,java9_sqrt\n number, number, number\n 0.000, 0.000, 0.000\n 10.000, 25.076, 26.178\n 20.000, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_java9_sqrt_precisions_to_1000.csv",
"chars": 13449,
"preview": "precision, sqrt,java9_sqrt\n number, number, number\n 10, 8.436, 5.070\n 12, 2.472, 1.000\n 14,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_java9_sqrt_precisions_to_10000.csv",
"chars": 27057,
"preview": "precision, sqrt,java9_sqrt\n number, number, number\n 10, 8, 6\n 20, 5, 3\n 30,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_java9_sqrt_precisions_to_200.csv",
"chars": 5457,
"preview": "precision, sqrt,java9_sqrt\n number, number, number\n 1, 0.529, 1.350\n 2, 0.310, 1.006\n 3,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_log_from_0_to_100000.csv",
"chars": 2049,
"preview": " x, log\r\n number, number\r\n 0.000, 0\r\n1000.000, 12094\r\n2000.000, 12434\r\n3000.000, 11448\r\n4000.0"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_pow_frac_from_0_to_1000.csv",
"chars": 3636,
"preview": " x, pow\n number, number\n 0.500,3534.100\n 5.500,3490.900\n 10.500,3513.000\n 15.500,3497.000\n 20.500,348"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_pow_from_0_to_100.csv",
"chars": 18054,
"preview": " x, pow\n number, number\n 0.000, 0.000\n 0.100,3410.500\n 0.200,3393.500\n 0.300,3463.100\n 0.400,352"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_pow_int_from_0_to_10000.csv",
"chars": 180055,
"preview": " x, pow\n number, number\n 0.000, 0.000\n 1.000, 0.000\n 2.000, 0.000\n 3.000, 0.000\n 4.000, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_pow_int_from_0_to_100000.csv",
"chars": 1890056,
"preview": " x, pow\n number, number\n 0.000, 0.000\n 1.000, 0.000\n 2.000, 0.000\n 3.000, 0.000\n 4.000, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_sin_funcs_from_0_to_3.csv",
"chars": 8484,
"preview": " x, sin, sinNEW\r\n number, number, number\r\n 0.000, 20, 0\r\n 0.010, 473, 443\r\n 0.020"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_slow_funcs_from_-10_to_10.csv",
"chars": 7308,
"preview": " x, exp, log, pow\n number, number, number, number\n -10.000, 927.100, 0.000, 7.600\n -9.900,101"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_slow_funcs_from_0_to_10.csv",
"chars": 7308,
"preview": " x, exp, log, pow\n number, number, number, number\n 0.000, 0.000, 0.000, 0.000\n 0.050, 73"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_slow_funcs_from_0_to_100.csv",
"chars": 36108,
"preview": " x, exp, log, pow\n number, number, number, number\n 0.000, 0.000, 0.000, 0.000\n 0.100, 72"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_slow_funcs_from_0_to_1000.csv",
"chars": 7308,
"preview": " x, exp, log, pow\n number, number, number, number\n 0.000, 0.000, 0.000, 0.100\n 5.000, 89"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_slow_funcs_from_0_to_2.csv",
"chars": 14508,
"preview": " x, exp, log, pow\n number, number, number, number\n 0.000, 0.000, 0.000, 0.000\n 0.005, 67"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_slow_funcs_precisions_to_1000.csv",
"chars": 3777,
"preview": "precision, exp, log, pow\n number, number, number, number\n 10, 18.980, 34.880, 94.260\n 20, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/perf_trigo_funcs_from_0_to_1.csv",
"chars": 6628,
"preview": " x, sin, cos, tan, asin, acos, atan\n number, number, number, number, number, number, n"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/regression/after_fewer_mc.csv",
"chars": 4004,
"preview": "Name , Average [ns], Median [ns], Min [ns], Max [ns]\nlog(0.1) , "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/regression/before after fewer mc optimization.csv",
"chars": 844,
"preview": "Name \t,Before\t,After\nlog(0.1) \t,2947\t,2190\nlog2(2) \t,235\t,234\nlog10(2) "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/regression/before_fewer_mc.csv",
"chars": 4004,
"preview": "Name , Average [ns], Median [ns], Min [ns], Max [ns]\nlog(0.1) , "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/regression/v1.0.0.csv",
"chars": 2920,
"preview": "Name , Average [ns], Min [ns], Max [ns]\r\nlog(0.1) , 2831, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/regression/v1.1.0.csv",
"chars": 2993,
"preview": "Name , Average [ns], Min [ns], Max [ns]\r\nlog(0.1) , 2860, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/regression/v1.2.0.csv",
"chars": 3688,
"preview": "Name , Average [ns], Median [ns], Min [ns], Max [ns]\r\nlog(0.1) , "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_asin_impl_from_0_to_1.csv",
"chars": 3815,
"preview": " x, sin,asinTaylor,asinNewton\r\n number, number, number, number\r\n 0.000, 0, 0, 103\r\n 0."
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_exp_impl_from_0_to_4.csv",
"chars": 18136,
"preview": " x, exp, exp_256,exp_1024,exp_65536\n number, number, number, number, number\n 0.000, 99, 99, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_log_adaptive_impl_from_0_to_10.csv",
"chars": 5659,
"preview": " x, log,logAdaptive\r\n number, number, number\r\n 0.050, 6810, 3639\r\n 0.100, 6726, 3565\r\n 0."
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_log_impl_from_0_to_10.csv",
"chars": 11129,
"preview": " x,newtonFix, newton,root+newton,primes+newton,primes+root+newton\r\n number, number, number, number, number, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_log_impl_from_0_to_100.csv",
"chars": 45112,
"preview": " x, newton,root+newton,exp+primes+newton,primes+root+newton\n number, number, number, number, number\n 0.100"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_root_impl_from_0_to_10.csv",
"chars": 28088,
"preview": " x, root,rootAdaptive\r\n number, number, number\r\n 0.000, 0, 0\r\n 0.010, 773, 512\r\n 0"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_sqrt_impl_from_0_to_1.csv",
"chars": 4776,
"preview": " x,sqrtNewtonFix,sqrtNewtonAdaptive,sqrtNewtonAdaptiveImproved,sqrtHalleyFix\r\n number, number, number, number,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_sqrt_impl_from_0_to_100.csv",
"chars": 450173,
"preview": " x,sqrtNewtonFix,sqrtNewtonAdaptive,sqrtNewtonAdaptiveImproved,sqrtHalleyFix\n number, number, number, number, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/test_sqrt_impl_from_0_to_1000.csv",
"chars": 450173,
"preview": " x,sqrtNewtonFix,sqrtNewtonAdaptive,sqrtNewtonAdaptiveImproved,sqrtHalleyFix\n number, number, number, number, "
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/values_atan2_yx_from_-10_to_10.csv",
"chars": 204679,
"preview": ", -10, -9.8, -9.6, -9.4, -9.2, -9.0, -8.8, -8.6, -8.4, -8.2, -8.0, -7.8, -7.6, -7.4, -7.2, -7.0, -6.8, -6.6, -6.4, -6.2,"
},
{
"path": "ch.obermuhlner.math.big.example/docu/benchmarks/values_atan2_yx_from_-10_to_10.properties",
"chars": 102,
"preview": "chart=heat\r\ntitle=atan2(y,x)\r\nmatrix-x-values=true\r\nmatrix-y-values=true\r\nx-axis=x\r\ny-axis=y\r\nz-axis=z"
},
{
"path": "ch.obermuhlner.math.big.example/docu/tables/bernoulli.csv",
"chars": 82481,
"preview": " N,Bernoulli Nominator,Bernoulli Denominator\r\n 0,1,1\r\n 1,-1,2\r\n 2,1,6\r\n 4,-1,30\r\n 6,1,42\r\n 8,-1,30\r\n 10,5,66\r\n 12"
},
{
"path": "ch.obermuhlner.math.big.example/docu/wordpress/AdaptiveNewton.txt",
"chars": 4306,
"preview": "This describes a way to improve the performance of a BigDecimal based implementation of Newton's Method\r\nby adapting the"
},
{
"path": "ch.obermuhlner.math.big.example/docu/wordpress/BigDecimalMath.txt",
"chars": 11114,
"preview": "[latex]\\require{AMSmath}[/latex]\r\nJava 8 is out and there are still no Math functions for BigDecimal.\r\n\r\nAfter playing a"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/BernoulliTable.java",
"chars": 2059,
"preview": "package ch.obermuhlner.math.big.example;\r\n\r\nimport ch.obermuhlner.math.big.BigRational;\r\n\r\npublic class BernoulliTable {"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/BigDecimalMathExample.java",
"chars": 4986,
"preview": "package ch.obermuhlner.math.big.example;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport ch.obe"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/BigFloatExample.java",
"chars": 1687,
"preview": "package ch.obermuhlner.math.big.example;\r\n\r\nimport static ch.obermuhlner.math.big.BigFloat.*;\r\n\r\nimport ch.obermuhlner.m"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/DefaultBigDecimalMathExample.java",
"chars": 8334,
"preview": "package ch.obermuhlner.math.big.example;\n\nimport ch.obermuhlner.math.big.DefaultBigDecimalMath;\nimport ch.obermuhlner.ma"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/FunctionTable.java",
"chars": 4235,
"preview": "package ch.obermuhlner.math.big.example;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\nimport java.uti"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/HighPrecisionMath.java",
"chars": 635,
"preview": "package ch.obermuhlner.math.big.example;\n\nimport ch.obermuhlner.math.big.BigDecimalMath;\n\nimport java.math.BigDecimal;\ni"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/PiExample.java",
"chars": 553,
"preview": "package ch.obermuhlner.math.big.example;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport ch.obe"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/StopWatch.java",
"chars": 623,
"preview": "package ch.obermuhlner.math.big.example;\r\n\r\npublic class StopWatch {\r\n\tprivate long startNanos;\r\n\r\n\tpublic StopWatch() {"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/AggregateCsv.java",
"chars": 5157,
"preview": "package ch.obermuhlner.math.big.example.internal;\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.regex.Pattern;"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/BigDecimalExperiments.java",
"chars": 5865,
"preview": "package ch.obermuhlner.math.big.example.internal;\n\nimport ch.obermuhlner.math.big.BigDecimalMath;\n\nimport java.math.BigD"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/BigDecimalMathExperimental.java",
"chars": 34199,
"preview": "package ch.obermuhlner.math.big.example.internal;\r\n\r\nimport static java.math.BigDecimal.ONE;\r\nimport static java.math.Bi"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/GammaExperiments.java",
"chars": 9089,
"preview": "package ch.obermuhlner.math.big.example.internal;\n\nimport ch.obermuhlner.math.big.example.StopWatch;\n\nimport java.io.Fil"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/PerformanceBigDecimalMath.java",
"chars": 51229,
"preview": "package ch.obermuhlner.math.big.example.internal;\n\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/PerformanceRegressionBigDecimalMath.java",
"chars": 8146,
"preview": "package ch.obermuhlner.math.big.example.internal;\n\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.MathC"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/internal/SqrtExperiments.java",
"chars": 1110,
"preview": "package ch.obermuhlner.math.big.example.internal;\n\nimport ch.obermuhlner.math.big.BigDecimalMath;\n\nimport java.math.BigD"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/stream/BigDecimalStreamExample.java",
"chars": 1485,
"preview": "package ch.obermuhlner.math.big.example.stream;\r\n\r\nimport java.math.BigDecimal;\r\nimport java.math.MathContext;\r\n\r\nimport"
},
{
"path": "ch.obermuhlner.math.big.example/src/main/java/ch/obermuhlner/math/big/example/stream/BigFloatStreamExample.java",
"chars": 1459,
"preview": "package ch.obermuhlner.math.big.example.stream;\r\n\r\nimport ch.obermuhlner.math.big.BigFloat;\r\nimport ch.obermuhlner.math."
},
{
"path": "docs/_config.yml",
"chars": 26,
"preview": "theme: jekyll-theme-cayman"
},
{
"path": "docs/index.md",
"chars": 1136,
"preview": "# Big-Math Documentation\n\n<p align=\"center\">\n\t<img alt=\"big-math\" src=\"images/big-math-splashscreen.png\">\n</p>\n\n## Curre"
},
{
"path": "docs/javadoc/v1.3.0/META-INF/MANIFEST.MF",
"chars": 23,
"preview": "Manifest-Version: 1.0\n\n"
},
{
"path": "docs/javadoc/v1.3.0/allclasses-frame.html",
"chars": 3278,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/allclasses-noframe.html",
"chars": 2938,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/BigDecimalMath.html",
"chars": 57610,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/BigFloat.Context.html",
"chars": 24495,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/BigFloat.html",
"chars": 159741,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/BigRational.html",
"chars": 78697,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/AsinCalculator.html",
"chars": 15942,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/CosCalculator.html",
"chars": 16256,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/CoshCalculator.html",
"chars": 16284,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/ExpCalculator.html",
"chars": 16258,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/PowerIterator.html",
"chars": 9756,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/PowerNIterator.html",
"chars": 12196,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/PowerTwoNIterator.html",
"chars": 12266,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/PowerTwoNPlusOneIterator.html",
"chars": 12398,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/SeriesCalculator.html",
"chars": 18513,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/SinCalculator.html",
"chars": 16258,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/SinhCalculator.html",
"chars": 15952,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/package-frame.html",
"chars": 2327,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/package-summary.html",
"chars": 9002,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/internal/package-tree.html",
"chars": 7863,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/package-frame.html",
"chars": 1215,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/package-summary.html",
"chars": 5905,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/package-tree.html",
"chars": 5231,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/stream/BigDecimalStream.html",
"chars": 23110,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/stream/BigFloatStream.html",
"chars": 26304,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/stream/package-frame.html",
"chars": 1039,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/stream/package-summary.html",
"chars": 5350,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/ch/obermuhlner/math/big/stream/package-tree.html",
"chars": 4883,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/constant-values.html",
"chars": 3617,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/deprecated-list.html",
"chars": 3567,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/help-doc.html",
"chars": 8285,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/index-all.html",
"chars": 125609,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/index.html",
"chars": 2863,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">\n<!-- NewPage -->\n<"
},
{
"path": "docs/javadoc/v1.3.0/overview-frame.html",
"chars": 1087,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/overview-summary.html",
"chars": 4438,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/overview-tree.html",
"chars": 8440,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v1.3.0/package-list",
"chars": 88,
"preview": "ch.obermuhlner.math.big\nch.obermuhlner.math.big.internal\nch.obermuhlner.math.big.stream\n"
},
{
"path": "docs/javadoc/v1.3.0/script.js",
"chars": 827,
"preview": "function show(type)\n{\n count = 0;\n for (var key in methods) {\n var row = document.getElementById(key);\n "
},
{
"path": "docs/javadoc/v1.3.0/stylesheet.css",
"chars": 12842,
"preview": "/* Javadoc style sheet */\n/*\nOverall document style\n*/\n\n@import url('resources/fonts/dejavu.css');\n\nbody {\n backgroun"
},
{
"path": "docs/javadoc/v2.0.0/allclasses-frame.html",
"chars": 3556,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/allclasses-noframe.html",
"chars": 3176,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/BigComplex.html",
"chars": 67323,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/BigComplexMath.html",
"chars": 54226,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/BigDecimalMath.html",
"chars": 59129,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/BigFloat.Context.html",
"chars": 24495,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/BigFloat.html",
"chars": 159741,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/BigRational.html",
"chars": 78697,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/AsinCalculator.html",
"chars": 15942,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/CosCalculator.html",
"chars": 16256,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/CoshCalculator.html",
"chars": 16284,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/ExpCalculator.html",
"chars": 16258,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/PowerIterator.html",
"chars": 9756,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/PowerNIterator.html",
"chars": 12196,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/PowerTwoNIterator.html",
"chars": 12266,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/PowerTwoNPlusOneIterator.html",
"chars": 12398,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/SeriesCalculator.html",
"chars": 18513,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/SinCalculator.html",
"chars": 16258,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/SinhCalculator.html",
"chars": 15952,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/package-frame.html",
"chars": 2327,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/package-summary.html",
"chars": 9002,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/internal/package-tree.html",
"chars": 7863,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/package-frame.html",
"chars": 1445,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/package-summary.html",
"chars": 6663,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/package-tree.html",
"chars": 5637,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/stream/BigDecimalStream.html",
"chars": 23110,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/stream/BigFloatStream.html",
"chars": 26304,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
},
{
"path": "docs/javadoc/v2.0.0/ch/obermuhlner/math/big/stream/package-frame.html",
"chars": 1039,
"preview": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<!-- NewPage -->\n"
}
]
// ... and 406 more files (download for full content)
About this extraction
This page contains the full source code of the eobermuhlner/big-math GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 606 files (13.7 MB), approximately 3.6M tokens, and a symbol index with 1218 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.