{"id":13536876,"url":"https://github.com/ionspin/kotlin-multiplatform-bignum","last_synced_at":"2026-01-14T02:01:02.530Z","repository":{"id":36193329,"uuid":"176085256","full_name":"ionspin/kotlin-multiplatform-bignum","owner":"ionspin","description":"A Kotlin multiplatform library for arbitrary precision arithmetics","archived":false,"fork":false,"pushed_at":"2025-09-12T10:17:46.000Z","size":3304,"stargazers_count":439,"open_issues_count":37,"forks_count":46,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-20T05:50:47.203Z","etag":null,"topics":["arbitrary-precision","bigdecimal","biginteger","bignum","kotlin","kotlin-multiplatform"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ionspin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-17T10:21:34.000Z","updated_at":"2025-10-14T04:37:46.000Z","dependencies_parsed_at":"2024-01-16T15:40:32.933Z","dependency_job_id":"15bbfe46-2b16-4da4-a578-d96e96ad5239","html_url":"https://github.com/ionspin/kotlin-multiplatform-bignum","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/ionspin/kotlin-multiplatform-bignum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionspin%2Fkotlin-multiplatform-bignum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionspin%2Fkotlin-multiplatform-bignum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionspin%2Fkotlin-multiplatform-bignum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionspin%2Fkotlin-multiplatform-bignum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ionspin","download_url":"https://codeload.github.com/ionspin/kotlin-multiplatform-bignum/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionspin%2Fkotlin-multiplatform-bignum/sbom","scorecard":{"id":493073,"data":{"date":"2025-08-11","repo":{"name":"github.com/ionspin/kotlin-multiplatform-bignum","commit":"86b22ce0e2a2b0e163192a1670fe4e0362d5a0ac"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Maintained","score":10,"reason":"6 commit(s) and 6 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"Code-Review","score":1,"reason":"Found 3/23 approved changesets -- score normalized to 1","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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/github-pull-request-build.yml:1","Info: no jobLevel write permissions found"],"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":"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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/github-pull-request-build.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/ionspin/kotlin-multiplatform-bignum/github-pull-request-build.yml/main?enable=pin","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   4 third-party GitHubAction dependencies pinned"],"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":"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":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"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":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 13 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"}},{"name":"Vulnerabilities","score":0,"reason":"16 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q","Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3","Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T19:44:56.737Z","repository_id":36193329,"created_at":"2025-08-19T19:44:56.737Z","updated_at":"2025-08-19T19:44:56.737Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408709,"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","bigdecimal","biginteger","bignum","kotlin","kotlin-multiplatform"],"created_at":"2024-08-01T09:00:50.896Z","updated_at":"2026-01-14T02:01:02.411Z","avatar_url":"https://github.com/ionspin.png","language":"Kotlin","funding_links":[],"categories":["Libraries"],"sub_categories":["Utility","🧮 Arithmetic"],"readme":"[![pipeline status](https://gitlab.com/ionspin-github-ci/kotlin-multiplatform-bignum-ci/badges/main/pipeline.svg)](https://gitlab.com/ionspin-github-ci/kotlin-multiplatform-bignum-ci/-/commits/main)\n[![Maven Central](https://img.shields.io/maven-central/v/com.ionspin.kotlin/bignum.svg)](https://repo1.maven.org/maven2/com/ionspin/kotlin/bignum/)\n# Kotlin MP BigNum library \n\nKotlin Multiplatform BigNum library is a pure kotlin implementation of arbitrary precision\narithmetic operations. It follows the same approach as Kotlin does on JVM to keep the interface\nfamiliar.\n\n## Notes \u0026 Roadmap\n\nThis is an implementation of pure kotlin arbitrary integer and floating-point arithmetic support.\n\n**The APIs might change until v1.0**\n\nVersion 0.3.0 brings API changes to BigDecimal API see changelog for full list.\n\nAlso, there is a plan to implement platform native versions.\n\nTesting to verify that the library works properly is mostly done against Java BigInteger and BigDecimal implementations.\n\n## Should I use this in production?\n\nThe library is still under development, but at the moment it is feature complete, further improvements will be optimizations\nand bug-fixing. \n\n### WASM\n\nWASM platform is experimental, use with caution, tests for wasm are not run on Windows and Mac at the moment. Note that currently wasm returns a value after converting to IEEE-754 number, unlike\nother platforms (JVM, JS, Native), so if you use:\n```kotlin\nval a = BigDecimal.fromFloat(0.000000000000123f)\n```\nexpect `a` to be `1.2299999885799495E-13`.\n\n## Integration\n\n#### Gradle\n```kotlin\nimplementation(\"com.ionspin.kotlin:bignum:0.3.10\")\n```\n\n#### Snapshot builds\n```kotlin\nrepositories {\n    maven {\n        url = uri(\"https://oss.sonatype.org/content/repositories/snapshots\")\n    }\n}\nimplementation(\"com.ionspin.kotlin:bignum:0.3.11-SNAPSHOT\")\n\n```\n\n## Serialization\n\nSerializers for KotlinX Serializtion library are provided, see more here [kotlinx serialization support](bignum-serialization-kotlinx/README.md)\n\nNote that because kotlinx doesn't support linux ARM targets as well as MinGW x86, serialization support library doesn't either.\nAdditionally, because of a bug when building serialization support library only JS IR variant is provided.\n\n\n## Usage\n\n### Integers\n\n#### Creating Big Integers\n\nTo create a big integer you can parse a string:\n```kotlin\nBigInteger.parse(\"-1122334455667788990011223344556677889900\", 10)\n```\n\nOr use the extensions or companion function for `Long`, `Int`, `Byte` or `Short`\n```kotlin\nval bigIntegerExtension = 234L.toBigInteger()\nval bigIntegerCompanion = BigInteger.fromLong(234L)\n\n```\n\nOr use extensions functions for `String`\n```kotlin\n\"12345678\".toBigInteger()\n```\n### Basic Arithmetic Operations\n\n#### Addition\n```kotlin\nval a = BigInteger.fromLong(Long.MAX_VALUE)\nval b = BigInteger.fromInt(Integer.MAX_VALUE)\n\nval sum = a + b\nprintln(\"Sum: $sum\")\n----- Output -----\nSum: Sum: 9223372039002259454\n```\n\n#### Subtraction\n```kotlin\nval a = BigInteger.fromLong(Long.MIN_VALUE)\nval b = BigInteger.fromLong(Long.MAX_VALUE)\n\nval difference = a - b\nprintln(\"Difference: $difference\")\n----- Output -----\nDifference: -18446744073709551615\n```\n\n#### Multiplication\n```kotlin\nval a = BigInteger.fromLong(Long.MAX_VALUE)\nval b = BigInteger.fromLong(Long.MIN_VALUE)\n\nval product = a * b\n\nprintln(\"Product: $product\")\n----- Output -----\nProduct: -85070591730234615856620279821087277056\n```\n\n#### Division - Quotient\n```kotlin\nval a = BigInteger.fromLong(Long.MAX_VALUE)\nval b = BigInteger.fromInt(Int.MAX_VALUE)\n\nval dividend = a + b\nval divisor = BigInteger.fromLong(Long.MAX_VALUE)\n\nval quotient = dividend / divisor\n        println(\"Quotient: $quotient\")\n----- Output -----\nQuotient: 1\n```\n\n#### Division - Remainder\n```kotlin\nval a = BigInteger.fromLong(Long.MAX_VALUE)\nval b = BigInteger.fromInt(Int.MAX_VALUE)\n\nval dividend = a + b\nval divisor = BigInteger.fromLong(Long.MAX_VALUE)\n\nval remainder = dividend % divisor\nprintln(\"Remainder: $remainder\")\n----- Output -----\nRemainder: 2147483647\n```\n\n#### Division - Quotient and Remainder\n```kotlin\nval a = BigInteger.fromLong(Long.MAX_VALUE)\nval b = BigInteger.fromInt(Int.MAX_VALUE)\n\nval dividend = a + b\nval divisor = BigInteger.fromLong(Long.MAX_VALUE)\n\nval quotientAndRemainder = dividend divrem divisor\n\nprintln(\"Quotient: ${quotientAndRemainder.quotient} \\nRemainder: ${quotientAndRemainder.remainder}\")\n----- Output -----\nQuotient: 1 \nRemainder: 2147483647\n```\n\n### Bitwise Operations\n\n#### Shift Left\n```kotlin\nval a = BigInteger.fromByte(1)\n\nval shifted = a shl 215\nprintln(\"Shifted: $shifted\")\n----- Output -----\nShifted: 52656145834278593348959013841835216159447547700274555627155488768\n```\n\n#### Shift Right\n```kotlin\nval a = BigInteger.parseString(\"100000000000000000000000000000000\", 10)\n\nval shifted = a shr 90\n----- Output -----\nShifted: 80779\n\n```\n\n#### Xor\n```kotlin\nval operand = BigInteger.parseString(\"11110000\", 2)\nval mask = BigInteger.parseString(\"00111100\", 2)\n\nval xorResult = operand xor mask\n\nprintln(\"Xor result: ${xorResult.toString(2)}\")\n----- Output -----\nXor result: 11001100\n```\n\n\n#### And\n```kotlin\nval operand = BigInteger.parseString(\"FFFFFFFFFF000000000000\", 16)\nval mask =    BigInteger.parseString(\"00000000FFFF0000000000\", 16)\nval andResult = operand and mask\nprintln(\"And result: ${andResult.toString(16)}\")\n----- Output -----\nAnd result: ff000000000000\n```\n\n#### Or\n```kotlin\nval operand = BigInteger.parseString(\"FFFFFFFFFF000000000000\", 16)\nval mask =    BigInteger.parseString(\"00000000FFFF0000000000\", 16)\nval orResult = operand or mask\nprintln(\"Or result: ${orResult.toString(16)}\")\n----- Output -----\nOr result: ffffffffffff0000000000\n```\n\n#### Binary Not\n\nUnlike Java BigInteger which does two's complement inversion, this method does bitwise inversion, \n\ni.e.:\n\n    If the number was \"1100\" binary, not() returns \"0011\" =\u003e \"11\" =\u003e 4 in base 10\n    In the same case Java BigInteger would return \"1011\" =\u003e -13 two's complement base 10\n    \n```kotlin\nval operand = BigInteger.parseString(\"11110000\", 2)\nval result = operand.not()\nprintln(\"Not operation result: ${result.toString(2)}\")\n----- Output -----\nInv result: 1111\n```\n\n#### Modular integers\n\nA `modInverse` function that is equivalent to java BigInteger `modInverse` is available. Note that this method will\nproduce a **BigInteger** not a **ModularBigInteger**\n\nBig integers can be converted to modularIntegers with same modulo, and then `inverse()` method is available. This method \n**will** return ModularBigInteger\n\n```kotlin\nval a = 100_002.toBigInteger()\nval modularA = a.toModularBigInteger(500.toBigInteger())\nprintln(\"ModularBigInteger: ${modularA.toStringWithModulo()}\")\n----- Output -----\nModularBigInteger: 2 mod 500\n```\n\nIf you want to create more ModularBigIntegers with the same module, you can retrieve creator by calling `getCreator`\n\nMore inforamtion about the ModularBigIntegers can be found in the third section\n\n## Floating Point\n\n### Creating\n\n#### Parsing\nTo create a BigDecimal you can parse a string in _expanded_ or scientific notation\n\n**Scientific** \n\n```kotlin\nval bigDecimal = BigDecimal.parseString(\"1.23E-6)\")\nprintln(\"BigDecimal: $bigDecimal\")\n----- Output -----\nBigDecimal: 1.23E-6\n```\n\n**Expanded**\n\n```kotlin\nval bigDecimal = BigDecimal.parseString(\"0.00000123\")\nprintln(\"BigDecimal: $bigDecimal\")\n----- Output -----\nBigDecimal: 1.23E-6\n```\n\n#### From Long, Int, Short, Byte\n\nYou can convert standard types to BigDecimal, i.e. Long\n```kotlin\nval bigDecimal = BigDecimal.fromLong(7111)\nprintln(\"BigDecimal: $bigDecimal\")\n----- Output -----\nBigDecimal: 7.111E+3\n``` \n\nOr you can specify an exponent. when you do specify an exponent, input value (long, int, short, byte) is considered to \nbe in **scientific notation**.\n```kotlin\nval bigDecimal = BigDecimal.fromLongWithExponent(1, -5L)\nprintln(\"BigDecimal: $bigDecimal\")\nprintln(\"BigDecimalExpanded: ${bigDecimal.toStringExpanded()}\")\n----- Output -----\nBigDecimal: 1.0E-5\nBigDecimalExpanded: 0.00001\n\n```\n\n### Extension functions\n\nFor `String`\n```kotlin\n\nval bigDecimal = \"12345678.123\".toBigInteger\n```\n\nOr for `Double` of `Float`\n\n```kotlin\nval bigDecimalFromFloat = 123.456f.toBigDecimal() \nval bigDecimalFromDouble = 123.456.toBigDecimal()\n```\n\n`Long`, `Int`, `Short`, `Byte` \n```kotlin\nval bigDecimalFromLong = 10.toLong().toBigDecimal() \nval bigDecimalFromInt = 10.toInt().toBigDecimal()\nval bigDecimalFromShort = 10.toShort().toBigDecimal() \nval bigDecimalFromByte = 10.toByte().toBigDecimal()\n```\n\n## toString\n\nBy default toString() is returned in scientific output, but expanded output is also available\n```kotlin\nval bigDecimal = BigDecimal.parseString(\"123.456\")\nprintln(\"BigDecimal: ${bigDecimal.toStringExpanded()}\")\nbigDecimal.toStringExpanded() == \"123.456\"\n----- Output -----\nBigDecimal: 123.456\n```\n\n## toByteArray and fromByteArray\n\nConverts the BigInteger to and from big endian byte array.  \n```kotlin\nval bigIntOriginal = BigInteger.fromULong(ULong.MAX_VALUE)\nval byteArray = bigIntOriginal.toByteArray()\nval reconstructed = BigInteger.fromByteArray(byteArray)\nprintln(\"${bigIntOriginal == reconstructed}\")\n----- Output -----\ntrue\n```\n\nThere are two helper methods when converting from two's complement array (the same form that Java BigInteger provides):\n- `fromTwosComplementByteArray`\n```kotlin\nval negativeInput = ubyteArrayOf(0xFFU, 0x55U, 0x44U, 0x34U)\nval negativeBigInt = BigInteger.fromTwosComplementByteArray(negativeInput.asByteArray())\n```\n\n- `toTwosComplementByteArray`\n```kotlin\nval negativeBigInt = BigInteger.parseString(\"-AABBCC\", 16)\nval negativeBigIntArray = negativeBigInt.toTwosComplementByteArray()\n\n\n```\n\n### Arithmetic operations\n\nStandard arithmetic operations that are present:\n* Addition\n* Subtraction\n* Multiplication\n* Division\n* Exponentiation\n* Increase by one\n* Decrease by one\n* Absolute value\n* Negate\n* Signum\n\n\n(Suspiciously missing is square root, should be added soon™)\n\nOperations are executed with existing significands and then rounded down afterwards. Decimal mode parameter controls the precision and rounding mode\n\n### DecimalMode\nThis is a counterpart to the Java BigDecimal MathContext and scale at the same time. Decimal mode API is under revision and will be improved during 0.3.0-0.4.0 library lifecycle\n\n```kotlin\ndata class DecimalMode(val decimalPrecision : Long = 0, val roundingMode : RoundingMode = RoundingMode.NONE, val scale: Long = -1)\n``` \n\n`decimalPrecision` defines how many digits should significand have\n\n`roundingMode` defines rounding mode. \n\n##### Decimal mode resolution\n\n* `DecimalMode` supplied to the operation always overrides all other `DecimalModes` set in `BigDecimal`s\n\n* If a `DecimalMode` is set when creating a `BigDecimal` that mode will be used for all operations.\n\n* If two `BigDecimal`s have different `DecimalModes` with different RoundingModes an `ArithmeticException` will be thrown. \nIf the modes are same, but the precision is different, larger precision will be used.\n\n### Scale \n\nScale, or the number of digits to the right of the decimal, can also be specified.  Default is no\nscale, which puts no restriction on number of digits to the right of the decimal. When scale is\nspecified, a `RoundingMode` other than `RoundingMode.NONE` is also required.\nWhen arithmetic operations have both operands unlimited precision and no scaling, the result is\nalso unlimited precision and no scale. When an operation mixes an unlimited precision operand\nand a scaled operand, the result is unlimited precision. WHen both operands have scale,\nwhether unlimited precision or limited precision, then these rules for scale of the result are used:\n\n* add, subtract - max of the two scales\u003c/li\u003e\n* multiply - sum of the two scales\u003c/li\u003e\n* divide - min of the two scales\u003c/li\u003e\n\n##### Infinite precision  \n\nPrecision 0 and roundingMode none attempt to provide infinite precisions. Exception is division (and exponentiation with negative parameter), where default precision is the sum of precisions of operands (or 6, if the sum is below 6). If result of the operation cannot fit inside precision and RoundingMode is NONE, `ArithmeticException` \nwill be thrown.\n\nExample from the tests:\n```kotlin\n   fun readmeDivisionTest() {\n        assertFailsWith(ArithmeticException::class) {\n            val a = 1.toBigDecimal()\n            val b = 3.toBigDecimal()\n            val result = a/b\n        }\n\n        assertTrue {\n            val a = 1.toBigDecimal()\n            val b = 3.toBigDecimal()\n            val result = a.div(b, DecimalMode(20, RoundingMode.ROUND_HALF_AWAY_FROM_ZERO))\n            result.toString() == \"3.3333333333333333333E-1\"\n        }\n    }\n```\n\n#### Convenience rounding methods\n`BigDecimal` class contains two convenience rounding methods, the `roundToDigitPositionAfterDecimalPoint(digitPosition: Long, roundingMode: RoundingMode)`\nwhich rounds to a specific position after the decimal point, like in the following example:\n```kotlin\n        assertTrue {\n            val rounded = BigDecimal.fromIntWithExponent(123456789, 3)\n                .roundToDigitPositionAfterDecimalPoint(3, RoundingMode.CEILING)\n            rounded.toStringExpanded() == \"1234.568\"\n        }\n```\nand `roundToDigitPosition(digitPosition: Long, roundingMode: RoundingMode)` which rounds to a specifi digit precision\nregardless of decimal point, like in the following example:\n```kotlin\n        assertTrue {\n            val rounded = BigDecimal.parseString(\"1234.5678\")\n                .roundToDigitPosition(3, RoundingMode.ROUND_HALF_TOWARDS_ZERO)\n            rounded.toStringExpanded() == \"1230\"\n        }\n\n        assertTrue {\n            val rounded = BigDecimal.parseString(\"0.0012345678\")\n                .roundToDigitPosition(4, RoundingMode.ROUND_HALF_TOWARDS_ZERO)\n            rounded.toStringExpanded() == \"0.001\"\n        }\n```\n\n#### Rounding modes\nName | Description\n-----|----------------------------\nFLOOR | Towards negative infinity\nCEILING|Towards positive infinity\nAWAY_FROM_ZERO|Away from zero\nTOWARDS_ZERO| Towards zero\nNONE|Infinite decimalPrecision, and beyond\nROUND_HALF_AWAY_FROM_ZERO|Round towards nearest integer, using away from zero as tie breaker when significant digit being rounded is 5\nROUND_HALF_TOWARDS_ZERO|Round towards nearest integer, using towards zero as tie breaker when significant digit being rounded is 5\nROUND_HALF_CEILING|Round towards nearest integer, using towards infinity as tie breaker when significant digit being rounded is 5\nROUND_HALF_FLOOR|Round towards nearest integer, using towards negative infinity as tie breaker when significant digit being rounded is 5\n\n### Modular Integers\n\nModular arithmetic operations are supported only between integers with the same modulo. \n\n## Creating Modular Integers\n\nFirst define the modulo you are going to use by getting an instance of the creator, and than \nuse that creator to create instances of modular integers\n\n```kotlin\nval creator = ModularBigInteger.creatorForModulo(100)\nval modularBigInteger = creator.fromLong(150)\nprintln(\"ModularBigInteger: ${modularBigInteger.toStringWithModulo()}\")\n----- Output -----\nModularBigInteger: 50 mod 100\n\n```\n\nOtherwise, behavior is similar to normal integers\n\n\n### Sources\n\nFor examples of rounding modes consult [Comparison of approaches for rounding to an integer](https://en.wikipedia.org/wiki/Rounding) \non Wikipedia\n\nThis library draws inspiration from libraries like Java BigInteger, GNU MP Arithmetic Library, Javolution JScience,\nas well as following literature\n\n```\nModern Computer Arithmetic\nRichard P. Brent and Paul Zimmermann\nVersion 0.5.9 of 7 October 2010\n```\n```\nHacker`s Delight\nHenry S. Warren, Jr.\nSecond Edition\n```\n```\nArt of Computer Programming, Volume 2: Seminumerical Algorithms\nDonald E. Knuth\n3rd Edition\n```\n\n```\nRefinement of a newton reciprocal algorithm for arbitrary precision numbers\nYiping Cheng, Ze Liu\n```\nAnd many other blogs and posts scattered over the internet.\n\nIf you want to try building BigNum library yourself, those are the sources I would recommend to start with.\n\n### Development environment\nIf you are planning on contributing to the development of the library, you can set a local gradle variable\nin `gradle.properties` in your gradle home directory (i.e. on Linux ~/.gradle/gradle.properties) called\n`bignumPrimaryDevelopmentOs` to `linux`, `windows` or `mac` so that the gradle builds JVM and JS targets on your \nplatform. The reason for this switch is that most of the test are run on JVM by comparing results to Java BigInteger/Decimal\nso they should be run on your main development OS to verify proper results, and can be skipped on other operating systems\nwhere you are developing that platform specific features.\n\nAnd thank you for contributing!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fionspin%2Fkotlin-multiplatform-bignum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fionspin%2Fkotlin-multiplatform-bignum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fionspin%2Fkotlin-multiplatform-bignum/lists"}