{"id":37030391,"url":"https://github.com/eobermuhlner/big-math","last_synced_at":"2026-01-14T03:42:11.303Z","repository":{"id":46279502,"uuid":"58767125","full_name":"eobermuhlner/big-math","owner":"eobermuhlner","description":"Advanced Java BigDecimal math functions (pow, sqrt, log, sin, ...) using arbitrary precision.","archived":false,"fork":false,"pushed_at":"2024-11-17T09:51:47.000Z","size":23750,"stargazers_count":332,"open_issues_count":11,"forks_count":40,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-05-14T11:51:07.557Z","etag":null,"topics":["arbitrary-precision","big-math","bigdecimal","complex-numbers","mathematical-functions","newton-raphson","precision","taylor-series"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eobermuhlner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-05-13T19:29:00.000Z","updated_at":"2025-05-09T06:34:38.000Z","dependencies_parsed_at":"2023-10-20T20:48:50.869Z","dependency_job_id":null,"html_url":"https://github.com/eobermuhlner/big-math","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/eobermuhlner/big-math","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eobermuhlner%2Fbig-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eobermuhlner%2Fbig-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eobermuhlner%2Fbig-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eobermuhlner%2Fbig-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eobermuhlner","download_url":"https://codeload.github.com/eobermuhlner/big-math/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eobermuhlner%2Fbig-math/sbom","scorecard":{"id":378581,"data":{"date":"2025-08-11","repo":{"name":"github.com/eobermuhlner/big-math","commit":"7d84ea3ffcef4808a2e9b6376a1d2e472e2ca08f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Code-Review","score":2,"reason":"Found 6/27 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":9,"reason":"binaries present in source code","details":["Warn: binary detected: gradle/wrapper/gradle-wrapper.jar:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v2.3.2 not signed: https://api.github.com/repos/eobermuhlner/big-math/releases/82909604","Warn: release artifact v2.3.1 not signed: https://api.github.com/repos/eobermuhlner/big-math/releases/82197787","Warn: release artifact v2.3.0 not signed: https://api.github.com/repos/eobermuhlner/big-math/releases/21259689","Warn: release artifact v2.2.1 not signed: https://api.github.com/repos/eobermuhlner/big-math/releases/20568997","Warn: release artifact v2.2.0 not signed: https://api.github.com/repos/eobermuhlner/big-math/releases/19310841","Warn: release artifact v2.3.2 does not have provenance: https://api.github.com/repos/eobermuhlner/big-math/releases/82909604","Warn: release artifact v2.3.1 does not have provenance: https://api.github.com/repos/eobermuhlner/big-math/releases/82197787","Warn: release artifact v2.3.0 does not have provenance: https://api.github.com/repos/eobermuhlner/big-math/releases/21259689","Warn: release artifact v2.2.1 does not have provenance: https://api.github.com/repos/eobermuhlner/big-math/releases/20568997","Warn: release artifact v2.2.0 does not have provenance: https://api.github.com/repos/eobermuhlner/big-math/releases/19310841"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Branch-Protection","score":3,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'master'","Info: 'force pushes' disabled on branch 'master'","Warn: 'branch protection settings apply to administrators' is disabled on branch 'master'","Warn: could not determine whether codeowners review is allowed","Warn: no status checks found to merge onto branch 'master'","Warn: PRs are not required to make changes on branch 'master'; or we don't have data to detect it.If you think it might be the latter, make sure to run Scorecard with a PAT or use Repo Rules (that are always public) instead of Branch Protection settings"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 9 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T14:50:37.476Z","repository_id":46279502,"created_at":"2025-08-18T14:50:37.476Z","updated_at":"2025-08-18T14:50:37.476Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arbitrary-precision","big-math","bigdecimal","complex-numbers","mathematical-functions","newton-raphson","precision","taylor-series"],"created_at":"2026-01-14T03:42:10.736Z","updated_at":"2026-01-14T03:42:11.287Z","avatar_url":"https://github.com/eobermuhlner.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://api.travis-ci.org/eobermuhlner/big-math.svg?branch=master)](https://travis-ci.org/eobermuhlner/big-math)\n[![Code Coverage](https://badgen.net/codecov/c/github/eobermuhlner/big-math)](https://codecov.io/gh/eobermuhlner/big-math)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=big-math\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=big-math)\n[![Open Issues](https://badgen.net/github/open-issues/eobermuhlner/big-math)](https://github.com/eobermuhlner/big-math/issues)\n[![Closed Issues](https://badgen.net/github/closed-issues/eobermuhlner/big-math)](https://github.com/eobermuhlner/big-math/issues)\n[![Maven Central](https://img.shields.io/maven-central/v/ch.obermuhlner/big-math.svg)](https://search.maven.org/artifact/ch.obermuhlner/big-math)\n[![Last Commits](https://badgen.net/github/last-commit/eobermuhlner/big-math)](https://github.com/eobermuhlner/big-math/graphs/commit-activity)\n[![Join the chat at https://gitter.im/eobermuhlner-big-math/community](https://badges.gitter.im/eobermuhlner-big-math/community.svg)](https://gitter.im/eobermuhlner-big-math/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n\u003cp align=\"center\"\u003e\n\t\u003cimg alt=\"big-math\" src=\"docs/images/big-math-splashscreen.png\"\u003e\n\u003c/p\u003e\n\nAdvanced Java `BigDecimal` math functions (`pow`, `sqrt`, `log`, `sin`, ...) using arbitrary precision.\n\nSee also the official [Big-Math Documentation](http://eobermuhlner.github.io/big-math/).\n\n## BigDecimalMath\n\nThe class `BigDecimalMath` provides efficient and accurate implementations for:\n\n*   `log(BigDecimal, MathContext)`\n*   `exp(BigDecimal, MathContext)`\n*   `pow(BigDecimal, BigDecimal, MathContext)` calculates x^y\n*   `sqrt(BigDecimal, MathContext)`\n*   `root(BigDecimal, BigDecimal, MathContext)` calculates the n'th root of x\n*   `sin(BigDecimal, MathContext)`\n*   `cos(BigDecimal, MathContext)`\n*   `tan(BigDecimal, MathContext)`\n*   `asin(BigDecimal, MathContext)`\n*   `acos(BigDecimal, MathContext)`\n*   `atan(BigDecimal, MathContext)`\n*   `atan2(BigDecimal, BigDecimal, MathContext)`\n*   `sinh(BigDecimal, MathContext)`\n*   `cosh(BigDecimal, MathContext)`\n*   `tanh(BigDecimal, MathContext)`\n*   `asinh(BigDecimal, MathContext)`\n*   `acosh(BigDecimal, MathContext)`\n*   `atanh(BigDecimal, MathContext)`\n*   `toDegrees(BigDecimal, MathContext)` converts from radians to degrees\n*   `toRadians(BigDecimal, MathContext)` converts from degrees to radians\n*   `pow(BigDecimal, long, MathContext)` calculates x^y for `long` y\n*   `factorial(int)` calculates n!\n*   `bernoulli(int)` calculates Bernoulli numbers\n*   `pi(MathContext)` calculates pi to an arbitrary precision\n*   `e(MathContext)` calculates e to an arbitrary precision\n*   `toBigDecimal(String)` creates a `BigDecimal` from string representation (faster than `BigDecimal(String)`)\n*   `mantissa(BigDecimal)` extracts the mantissa from a `BigDecimal` (mantissa * 10^exponent)\n*   `exponent(BigDecimal)` extracts the exponent from a `BigDecimal` (mantissa * 10^exponent)\n*   `integralPart(BigDecimal)` extracts the integral part from a `BigDecimal` (everything before the decimal point) \n*   `fractionalPart(BigDecimal)` extracts the fractional part from a `BigDecimal` (everything after the decimal point)\n*   `isIntValue(BigDecimal)` checks whether the `BigDecimal` can be represented as an `int` value\n*   `isDoubleValue(BigDecimal)` checks whether the `BigDecimal` can be represented as a `double` value\n*   `roundWithTrailingZeroes(BigDecimal, MathContext)` rounds a `BigDecimal` to an arbitrary precision with trailing zeroes.\n\n\n### Usage\n\n#### Mathematical calculations for `BigDecimal`\n\nFor calculations with arbitrary precision you need to specify how precise you want a calculated result.\nFor `BigDecimal` calculations this is done using the `MathContext`.\n\n```java\nMathContext mathContext = new MathContext(100);\nSystem.out.println(\"sqrt(2)        = \" + BigDecimalMath.sqrt(BigDecimal.valueOf(2), mathContext));\nSystem.out.println(\"log10(2)       = \" + BigDecimalMath.log10(BigDecimal.valueOf(2), mathContext));\nSystem.out.println(\"exp(2)         = \" + BigDecimalMath.exp(BigDecimal.valueOf(2), mathContext));\nSystem.out.println(\"sin(2)         = \" + BigDecimalMath.sin(BigDecimal.valueOf(2), mathContext));\n```\nwill produce the following output on the console:\n```\nsqrt(2)        = 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573\nlog10(2)       = 0.3010299956639811952137388947244930267681898814621085413104274611271081892744245094869272521181861720\nexp(2)         = 7.389056098930650227230427460575007813180315570551847324087127822522573796079057763384312485079121795\nsin(2)         = 0.9092974268256816953960198659117448427022549714478902683789730115309673015407835446201266889249593803\n```\n\nSince many mathematical constants have an infinite number of digits you need to specfiy the desired precision for them as well:\n```java\nMathContext mathContext = new MathContext(100);\nSystem.out.println(\"pi             = \" + BigDecimalMath.pi(mathContext));\nSystem.out.println(\"e              = \" + BigDecimalMath.e(mathContext));\n```\nwill produce the following output on the console:\n```\npi             = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068\ne              = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427\n```\n\n#### Convenience methods for `BigDecimal`\n\nAdditional `BigDecimalMath` provides several useful methods (that are plain missing for `BigDecimal`):\n```java\nMathContext mathContext = new MathContext(100);\nSystem.out.println(\"mantissa(1.456E99)      = \" + BigDecimalMath.mantissa(BigDecimal.valueOf(1.456E99)));\nSystem.out.println(\"exponent(1.456E99)      = \" + BigDecimalMath.exponent(BigDecimal.valueOf(1.456E99)));\nSystem.out.println(\"integralPart(123.456)   = \" + BigDecimalMath.integralPart(BigDecimal.valueOf(123.456)));\nSystem.out.println(\"fractionalPart(123.456) = \" + BigDecimalMath.fractionalPart(BigDecimal.valueOf(123.456)));\nSystem.out.println(\"isIntValue(123)         = \" + BigDecimalMath.isIntValue(BigDecimal.valueOf(123)));\nSystem.out.println(\"isIntValue(123.456)     = \" + BigDecimalMath.isIntValue(BigDecimal.valueOf(123.456)));\nSystem.out.println(\"isDoubleValue(123.456)  = \" + BigDecimalMath.isDoubleValue(BigDecimal.valueOf(123.456)));\nSystem.out.println(\"isDoubleValue(1.23E999) = \" + BigDecimalMath.isDoubleValue(new BigDecimal(\"1.23E999\")));\n```\nwill produce the following output on the console:\n```\nmantissa(1.456E99)      = 1.456\nexponent(1.456E99)      = 99\nintegralPart(123.456)   = 123\nfractionalPart(123.456) = 0.456\nisIntValue(123)         = true\nisIntValue(123.456)     = false\nisDoubleValue(123.456)  = true\nisDoubleValue(1.23E999) = false\n```\n\nThe `BigDecimalMath` class is thread-safe and can be used in concurrent use cases.\n\n#### Streams of `BigDecimal`\n\nThe class `BigDecimalStream` provides factory methods for streams of `BigDecimal` elements.\n\nOverloaded variants of `range(start, end, step)` provide sequential elements equivalent to `IntStream.range(start, end)` but with configurable step (exclusive the end value).\n\nSimilar methods for the `rangeClosed()` (inclusive the end value) are available.\n\nThe streams are well behaved when used in parallel mode. \n\nThe following code snippet:\n```java\nSystem.out.println(\"Range [0, 10) step 1 (using BigDecimal as input parameters)\");\nBigDecimalStream.range(BigDecimal.valueOf(0), BigDecimal.valueOf(10), BigDecimal.valueOf(1), mathContext)\n\t.forEach(System.out::println);\n\nSystem.out.println(\"Range [0, 10) step 3 (using long as input parameters)\");\nBigDecimalStream.range(0, 10, 3, mathContext)\n\t.forEach(System.out::println);\n```\n\nproduces this output:\n```\nRange [0, 10) step 1 (using BigDecimal as input parameters)\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nRange [0, 12] step 3 (using long as input parameters)\n0\n3\n6\n9\n12\n```\n\n### FAQ\n\n#### Why do I have to pass `MathContext` to most functions?\n\nMany mathematical functions have results that have many digits (often an infinite number of digits).\nWhen calculating these functions you need to specify the number of digits you want in the result,\nbecause calculating an infinite number of digits would take literally forever and consume an infinite amount of memory.\n\nThe `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.\n\n\n#### What if I really do not want to pass the `MathContext` everytime?\n\nThe convenience class `DefaultBigDecimalMath` was added that provides mathematical functions\nwhere the `MathContext` must not be passed every time.\n\nPlease refer to the chapter [DefaultBigDecimalMath](#defaultbigdecimalmath)\n\n\n#### I specified a precision of `n` digits, but the results have completely different number of digits after the decimal point. Why?\n\nIt is a common misconception that the precision defines the number of digits after the decimal point.\n\nInstead the precision defines the number of relevant digits, independent of the decimal point.\nThe following numbers all have a precision of 3 digits:\n* 12300\n* 1230\n* 123\n* 12.3\n* 1.23\n* 0.123\n* 0.0123\n\nTo specify the number of digits after the decimal point use `BigDecimal.setScale(scale, mathContext)`.\n\n\n#### Why are `BigDecimalMath` functions so slow?\n\nThe 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.\n\nIf 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.\n\n\n#### How are the mathematical functions in `BigDecimalMath` calculated?\n\nFor the mathematical background and performance analysis please refer to this article:\n*\t[BigDecimalMath](http://obermuhlner.ch/wordpress/2016/06/02/bigdecimalmath/)\n\nSome of the implementation details are explained here: \n*\t[Adaptive precision in Newton’s Method](http://obermuhlner.ch/wordpress/2016/06/07/adaptive-precision-in-newtons-method/)\n\n\n#### Why is there `BigDecimalMath.toBigDecimal(String)` if Java already has a `BigDecimal(String)` constructor?\n\nThe `BigDecimal(String)` constructor as provided by Java gets increasingly slower if you pass longer strings to it.\nThe implementation in Java 11 and before is O(n^2).\n\nIf you want to convert very long strings (10000 characters or longer) then this slow constructor may become an issue.\n\n`BigDecimalMath.toBigDecimal(String)` is a drop-in replacement with the same functionality\n(converting a string representation into a `BigDecimal`) but it is using a faster recursive implementation.\n\nThe following chart shows the time necessary to create a `BigDecimal` from a string representation of increasing length:\n![toBigDecimal() precisions 0 to 100000](ch.obermuhlner.math.big.example/docu/benchmarks/images/perf_bigdec_string_precisions_to_100000.png)\n \n\n#### I only need a `sqrt` function - should I use this library?\n\nSince Java 9 the `BigDecimal` class has a new function `sqrt(BigDecimal, MathContext)`.\nIf you only need the square root function then by all means use the provided standard function instead of this library.\n\nIf you need any other high level function then you should still consider using this library.\n\nFor high precision (above 150 digits) the current implementation of\nJava 9 `BigDecimal.sqrt()` becomes increasingly slower than `BigDecimalMath.sqrt()`.\nYou should consider whether the increased performance is worth having an additional dependency.  \n\nThe following charts shows the time needed to calculate the square root of 3.1 with increasing precision.\n\n![Java9 sqrt vs. sqrt()](ch.obermuhlner.math.big.example/docu/benchmarks/images/perf_java9_sqrt_precisions_to_200.png)\n![Java9 sqrt vs. sqrt()](ch.obermuhlner.math.big.example/docu/benchmarks/images/perf_java9_sqrt_precisions_to_1000.png)\n\n\n### Performance\n\nThe following charts show the time needed to calculate the functions over a range of values with a precision of 300 digits.\n\n![sqrt(), root(), exp(), sin(), cos() -10 to 10](ch.obermuhlner.math.big.example/docu/benchmarks/images/perf_fast_funcs_from_-10_to_10.png)\n![sqrt(), root(), exp(), sin(), cos() 0 to 10](ch.obermuhlner.math.big.example/docu/benchmarks/images/perf_fast_funcs_from_0_to_10.png)\n![sqrt(), root(), exp(), sin(), cos() 0 to 100](ch.obermuhlner.math.big.example/docu/benchmarks/images/perf_fast_funcs_from_0_to_100.png)\n\n![exp(), log(), pow() 0 to 10](ch.obermuhlner.math.big.example/docu/benchmarks/images/perf_slow_funcs_from_0_to_10.png)\n![exp(), log(), pow() 0 to 100](ch.obermuhlner.math.big.example/docu/benchmarks/images/perf_slow_funcs_from_0_to_100.png)\n\n\n## BigComplex\n\nThe class `BigComplex` represents complex numbers in the form `(a + bi)`.\nIt follows the design of `BigDecimal` with some convenience improvements like overloaded operator methods.\n\nA big difference to `BigDecimal` is that `BigComplex.equals()` implements the *mathematical* equality\nand *not* the strict technical equality.\nThis was a difficult decision because it means that `BigComplex` behaves slightly different than `BigDecimal`\nbut considering that the strange equality of `BigDecimal` is a major source of bugs we\ndecided it was worth the slight inconsistency.\n\nIf you need the strict equality use `BigComplex.strictEquals()`.\n\n* `re`\n* `im`\n* `add(BigComplex)`\n* `add(BigComplex, MathContext)`\n* `add(BigDecimal)`\n* `add(BigDecimal, MathContext)`\n* `add(double)`\n* `subtract(BigComplex)`\n* `subtract(BigComplex, MathContext)`\n* `subtract(BigDecimal)`\n* `subtract(BigDecimal, MathContext)`\n* `subtract(double)`\n* `multiply(BigComplex)`\n* `multiply(BigComplex, MathContext)`\n* `multiply(BigDecimal)`\n* `multiply(BigDecimal, MathContext)`\n* `multiply(double)`\n* `divide(BigComplex)`\n* `divide(BigComplex, MathContext)`\n* `divide(BigDecimal)`\n* `divide(BigDecimal, MathContext)`\n* `divide(double)`\n* `reciprocal(MathContext)`\n* `conjugate()`\n* `negate()`\n* `abs(MathContext)`\n* `angle(MathContext)`\n* `absSquare(MathContext)`\n* `isReal()`\n* `re()`\n* `im()`\n* `round(MathContext)`\n* `hashCode()`\n* `equals(Object)`\n* `strictEquals(Object)`\n* `toString()`\n* `valueOf(BigDecimal)`\n* `valueOf(double)`\n* `valueOf(BigDecimal, BigDecimal)`\n* `valueOf(double, double)`\n* `valueOfPolar(BigDecimal, BigDecimal, MathContext)`\n* `valueOfPolar(double, double, MathContext`\n\n\n## BigComplexMath\n\nThe class `BigComplexMath` is the equivalent of `BigDecimalMath` and contains mathematical functions in the complex domain.\n\n* `sin(BigComplex, MathContext)` \n* `cos(BigComplex, MathContext)` \n* `tan(BigComplex, MathContext)` \n* `asin(BigComplex, MathContext)`\n* `acos(BigComplex, MathContext)`\n* `atan(BigComplex, MathContext)`\n* `acot(BigComplex, MathContext)`\n* `exp(BigComplex, MathContext)`\n* `log(BigComplex, MathContext)`\n* `pow(BigComplex, long, MathContext)` \n* `pow(BigComplex, BigDecimal, MathContext)` \n* `pow(BigComplex, BigComplex, MathContext)` \n* `sqrt(BigComplex, MathContext)` \n* `root(BigComplex, BigDecimal, MathContext)` \n* `root(BigComplex, BigComplex, MathContext)` \n\n\n## DefaultBigDecimalMath\n\nThe class `DefaultBigDecimalMath` is a wrapper around `BigDecimalMath` that passes always the current `MathContext` to the\nfunctions that need a `MathContext` argument.\n\nThe initial default `MathContext` is equivalent to `MathContext.DECIMAL128` but this can be overridden by setting the following system properties:\n- `ch.obermuhlner.math.big.default.precision` to a positive integer precision (default=34)\n- `ch.obermuhlner.math.big.default.rounding` to a RoundingMode name (default=HALF_UP)\n\nIt is also possible to programmatically set the default `MathContext` using `setDefaultMathContext(MathContext)`.\nIt is recommended to set the desired precision in the `MathContext` very early in the startup of the application and to not change it afterwards.\n\n**Important**: Avoid the pitfall of setting the precision temporarily using `setDefaultMathContext(MathContext)` for a calculation.\nThis can lead to race conditions and calculations with the wrong precision if other threads in your application do the same thing.\n\nTo set a temporary `MathContext` you have to choice to use either:\n- `DefaultBigDecimalMath.createLocalMathContext()` in a try-with-resources statement  \n- `DefaultBigDecimalMath.withLocalMathContext()` with a lambda function  \n\nExample code using `DefaultBigDecimalMath.createLocalMathContext()`:\n```java\nSystem.out.println(\"Pi[default]: \" + DefaultBigDecimalMath.pi());\ntry (DefaultBigDecimalMath.LocalMathContext context = DefaultBigDecimalMath.createLocalMathContext(5)) {\n    System.out.println(\"Pi[5]: \" + DefaultBigDecimalMath.pi());\n    try (DefaultBigDecimalMath.LocalMathContext context2 = DefaultBigDecimalMath.createLocalMathContext(10)) {\n        System.out.println(\"Pi[10]: \" + DefaultBigDecimalMath.pi());\n    };\n    System.out.println(\"Pi[5]: \" + DefaultBigDecimalMath.pi());\n};\nSystem.out.println(\"Pi[default]: \" + DefaultBigDecimalMath.pi());\n```\n\nExample code using `DefaultBigDecimalMath.withLocalMathContext()`:\n```java\nSystem.out.println(\"Pi[default]: \" + DefaultBigDecimalMath.pi());\nDefaultBigDecimalMath.withLocalMathContext(5, () -\u003e {\n    System.out.println(\"Pi[5]: \" + DefaultBigDecimalMath.pi());\n    DefaultBigDecimalMath.withLocalMathContext(10, () -\u003e {\n        System.out.println(\"Pi[10]: \" + DefaultBigDecimalMath.pi());\n    });\n    System.out.println(\"Pi[5]: \" + DefaultBigDecimalMath.pi());\n});\nSystem.out.println(\"Pi[default]: \" + DefaultBigDecimalMath.pi());\n```\n\nBoth snippets will give the following output:\n```console\nPi[default]: 3.141592653589793238462643383279503\nPi[5]: 3.1416\nPi[10]: 3.141592654\nPi[5]: 3.1416\nPi[default]: 3.141592653589793238462643383279503\n```\n\nThe temporary `MathContext` are stored in `ThreadLocal` variables\nand will therefore not conflict with each other when used in multi-threaded use case.\n\n**Important**: Due to the `ThreadLocal` variables the temporary `MathContext` will\n _not_ be available in other threads.\nThis includes streams using `parallel()`, thread pools and manually started threads.\nIf you need temporary `MathContext` for calculations then you _must_ \nset the local `MathContext` inside _every_ separate thread.\n\n```java\ntry (DefaultBigDecimalMath.LocalMathContext context = DefaultBigDecimalMath.createLocalMathContext(5)) {\n    BigDecimalStream.range(0.0, 1.0, 0.01, DefaultBigDecimalMath.currentMathContext())\n            .map(b -\u003e DefaultBigDecimalMath.cos(b))\n            .map(b -\u003e \"sequential \" + Thread.currentThread().getName() + \" [5]: \" + b)\n            .forEach(System.out::println);\n\n    BigDecimalStream.range(0.0, 1.0, 0.01, DefaultBigDecimalMath.currentMathContext())\n            .parallel()\n            .map(b -\u003e {\n                try (DefaultBigDecimalMath.LocalMathContext context2 = DefaultBigDecimalMath.createLocalMathContext(5)) {\n                    return DefaultBigDecimalMath.cos(b);\n                }\n            })\n            .map(b -\u003e \"parallel \" + Thread.currentThread().getName() + \" [5]: \" + b)\n            .forEach(System.out::println);\n}\n```\n\n## BigFloat\n\nThe class `BigFloat` is an experimental wrapper around `BigDecimal` which simplifies the consistent usage of the `MathContext` and provides a simpler API for calculations. \n\nThe API for calculations is simplified and more consistent with the typical mathematical usage.\n* Factory methods on the `Context` class for values:\n\t* `valueOf(BigFloat)`\n\t* `valueOf(BigDecimal)`\n\t* `valueOf(int)`\n\t* `valueOf(long)`\n\t* `valueOf(double)`\n\t* `valueOf(String)`\n\t* `pi()`\n\t* `e()`\n\n* All standard operators:\n\t* `add(x)`\n\t* `subtract(x)`\n\t* `multiply(x)`\n\t* `divide(x)`\n\t* `remainder(x)`\n\t* `pow(y)`\n\t* `root(y)`\n\n* Calculation methods are overloaded for different value types:\n \t* `add(BigFloat)`\n\t* `add(BigDecimal)`\n\t* `add(int)`\n\t* `add(long)`\n\t* `add(double)`\n\t* ...\n\n* Mathematical functions are written in the traditional form:\n \t* `abs(x)`\n\t* `log(x)`\n\t* `sin(x)`\n\t* `min(x1, x2, ...)`\n\t* `max(x1, x2, ...)`\n\t* ...\n\n* Support for advanced mathematical functions:\n \t* `sqrt(x)`\n\t* `log(x)`\n\t* `exp(x)`\n\t* `sin(x)`\n\t* `cos(x)`\n\t* `tan(x)`\n\t* ...\n\n* Methods to access parts of a value:\n \t* `getMantissa()`\n\t* `getExponent()`\n\t* `getIntegralPart()`\n\t* `getFractionalPart()`\n\n* Methods to verify value type conversions:\n \t* `isIntValue()`\n \t* `isDoubleValue()`\n\n* Equals and Hashcode methods:\n\t* `equals(Object)` returns whether two `BigFloat` values are mathematically the same\n\t* `hashCode()` consistent with `equals(Object)`\n\n* Comparison methods:\n \t* `isEqual(BigFloat)`\n\t* `isLessThan(BigFloat)`\n\t* `isLessThanOrEqual(BigFloat)`\n\t* `isGreaterThan(BigFloat)`\n\t* `isGreaterThanOrEqual(BigFloat)`\n\n* Sign methods:\n\t* `signum()`\n\t* `isNegative()`\n\t* `isZero()`\n\t* `isPositive()`\n\n### Usage\n\nBefore doing any calculations you need to create a `Context` specifying the precision used for all calculations.\n```java\nContext context = BigFloat.context(100); // precision of 100 digits\nContext anotherContext = BigFloat.context(new MathContext(10, RoundingMode.HALF_UP); // precision of 10 digits, rounding half up\n```\n\nThe `Context` can then be used to create the first value of the calculation:\n```java\nBigFloat value1 = context.valueOf(640320);\n```\n\nThe `BigFloat` instance holds a reference to the `Context`. This context is then passed from calculation to calculation.\n```java\nBigFloat value2 = context.valueOf(640320).pow(3).divide(24);\nBigFloat value3 = BigFloat.sin(value2);\n```\n\n\nThe `BigFloat` result can be converted to other numerical types:\n```java\nBigDecimal bigDecimalValue = value3.toBigDecimal();\ndouble doubleValue = value3.toDouble();\nlong longValue = value3.toLong();\nint intValue = value3.toInt();\n```\n\nThe `BigFloatStream` provides similar stream factories as `BigDecimalStream` that will produce streams of `BigFloat` elements.\n\n### Usage in Java Module Systems (Jigsaw and OSGi)\n\nSince release 2.0.1 the deployed big-math Jar file contains now a module name for the Jigsaw module system (Java 9 and later).\n\nThis allows it to be used as automatic module with a well defined module name instead\nof deriving the name magically from the Jar file name.\n\nThe module name follows the reverse domain convention and is: `ch.obermuhlner.math.big`\n\nThe big-math Jar file is also OSGi compatible.\n\nThe `MANIFEST.MF` contains all the necessary headers and exports the public packages:\n- `ch.obermuhlner.math.big`\n- `ch.obermuhlner.math.big.stream`\n\n### Usage in Kotlin\n\nIf you want to use big-math library in Kotlin you may do so directly, or you use the \n[kotlin-big-math](https://github.com/eobermuhlner/kotlin-big-math) library that provides additional features, like operators.\n\n\n## Using big-math in your projects\n\nTo use the Java library you can either download the newest version of the .jar file from the\n[published releases on Github](https://github.com/eobermuhlner/big-math/releases/)\nor use the following dependency to\n[Maven Central](https://search.maven.org/#search%7Cga%7C1%7Cbig-math)\nin your build script (please verify the version number to be the newest release):\n\n### Use big-math in Maven Build\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ech.obermuhlner\u003c/groupId\u003e\n    \u003cartifactId\u003ebig-math\u003c/artifactId\u003e\n    \u003cversion\u003e2.3.2\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Use big-math in Gradle Build\n\n```gradle\nrepositories {\n  mavenCentral()\n}\n\ndependencies {\n  compile 'ch.obermuhlner:big-math:2.3.2'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feobermuhlner%2Fbig-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feobermuhlner%2Fbig-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feobermuhlner%2Fbig-math/lists"}