{"id":16942752,"url":"https://github.com/dankogai/swift-bignum","last_synced_at":"2025-03-22T12:32:58.651Z","repository":{"id":63907534,"uuid":"50888704","full_name":"dankogai/swift-bignum","owner":"dankogai","description":"Arbitrary-precision arithmetic for Swift, in Swift","archived":false,"fork":false,"pushed_at":"2023-11-16T11:56:39.000Z","size":1816,"stargazers_count":28,"open_issues_count":2,"forks_count":8,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-18T11:22:50.523Z","etag":null,"topics":["arbitrary-precision","floatingpoint","math","rational-numbers","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/dankogai.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2016-02-02T02:40:58.000Z","updated_at":"2024-11-02T17:59:04.000Z","dependencies_parsed_at":"2024-10-28T13:19:04.393Z","dependency_job_id":"59d4c419-b7c6-4231-80ef-c4613001fc03","html_url":"https://github.com/dankogai/swift-bignum","commit_stats":{"total_commits":155,"total_committers":4,"mean_commits":38.75,"dds":0.038709677419354827,"last_synced_commit":"44a83f3d0dcc8bc5881aed54a4093bdbd7c54018"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankogai%2Fswift-bignum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankogai%2Fswift-bignum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankogai%2Fswift-bignum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankogai%2Fswift-bignum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dankogai","download_url":"https://codeload.github.com/dankogai/swift-bignum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244959449,"owners_count":20538625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","floatingpoint","math","rational-numbers","swift"],"created_at":"2024-10-13T21:12:49.892Z","updated_at":"2025-03-22T12:32:58.253Z","avatar_url":"https://github.com/dankogai.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Swift 5](https://img.shields.io/badge/swift-5-blue.svg)](https://swift.org)\n[![MIT LiCENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![CI via GitHub Actions](https://github.com/dankogai/swift-bignum/actions/workflows/swift.yml/badge.svg?branch=main)](https://github.com/dankogai/swift-bignum/actions/workflows/swift.yml)\n\n# swift-bignum\n\nArbitrary-precision arithmetic for Swift, in Swift\n\n## Synopsis\n\n````swift\nimport BigNum\nBigRat.sqrt(2, precision:128)  // 240615969168004511545033772477625056927/170141183460469231731687303715884105728\nBigFloat.exp(1, precision:128) // 2.718281828459045235360287471352662497759\n````\n\n## Description\n\nThis module offers two flavors of Arbitrary-precision types that conforms to [FloatingPoint].\n\n* `BigRat`   - Arbitrary-precision rational number.\n* `BigFloat` - Arbitrary-precision floating point.\n\n[FloatingPoint]: https://developer.apple.com/documentation/swift/floatingpoint\n\nIn addition to all arithmetic operations that [FloatingPoint] supports.  Most of the functions in `\u003cmath.h\u003e` are offered as static functions.  As you see in the synopsis above, all arithmetic functions and operators that are lossy can take `precision:Int` as an optional argument.  When omitted the value of `BigRat.precision` or `BigFloat.precision` is used (default:64).\n\n```swift\nBigFloat.sqrt(2) // 1.41421356237309504876\nBigFloat.precision = 128\nBigFloat.sqrt(2) // 1.414213562373095048801688724209698078569\n```\n\n`BigInt`, an arbitrary-precision interger type is internally used and re-exported so you don't have to `import BigInt` just for that.  `BigInt` is also extended with `.over()` method so instead of constructing `BigRat` directly, you can:\n\n```swift\nBigInt(3260954456333195553).over(BigInt(2305843009213693952)) // == BigRat.sqrt(2)\n```\n\n## Usage\n\n### Build\n\n```sh\n$ git clone https://github.com/dankogai/swift-bignum.git\n$ cd swift-bignum # the following assumes your $PWD is here\n$ swift build\n```\n\n### REPL\n\nSimply\n\n```sh\n$ scripts/run-repl.sh\n```\n\nor\n\n```sh\n$ swift run --repl\n\n```\n\nand in your repl,\n\n```sh\n[0/0] Build complete!\nLaunching Swift REPL with arguments: -I/Users/dankogai/github/swift-bignum/.build/x86_64-apple-macosx/release -L/Users/dankogai/github/swift-bignum/.build/x86_64-apple-macosx/release -lBigNum__REPL -I/Users/dankogai/github/swift-bignum/.build/checkouts/swift-numerics/Sources/_NumericsShims/include\nWelcome to Swift version 5.5.2-dev.\nType :help for assistance.\n  1\u003e import BigNum \n  2\u003e var bf = BigFloat.sqrt(2, precision:128)\nbf: BigNum.BigFloat = {\n  scale = -127\n  mantissa = {\n    magnitude = {\n      kind = array\n      storage = 2 values {\n        [0] = 6448461645324402335\n        [1] = 13043817825332782212\n      }\n    }\n    sign = plus\n  }\n}\n  3\u003e print(bf)\n1.414213562373095048801688724209698078569\n````\n\n### From your Xcode Projects.\n\nSimply add the package from **Package Dependencies** tab of the Project.\nEnter `https://github.com/dankogai/swift-bignum` in the search field and click `[Add Package]`\n\n![](img/add-package.png)\n\nNow you are able to `import BigNum`.\n\n![](img/import-bignum.png)\n\nNow all you have to do is build and enjoy!\n\n![](img/app-built.png)\n\nIf you enconter errors like `Missing required module '_NumericShims'`, try cleaning up your `~/Library/Developer/Xcode/DerivedData`.\n\n### From Your SwiftPM-Managed Projects\n\nAdd the following to the `dependencies` section:\n\n```swift\n.package(\n  url: \"https://github.com/dankogai/swift-bignum.git\", .branch(\"main\")\n)\n```\n\nand the following to the `.target` argument:\n\n```swift\n.target(\n  name: \"YourSwiftyPackage\",\n  dependencies: [\"BigNum\"])\n```\n\nNow all you have to do is:\n\n```swift\nimport BigNum\n```\n\nin your code.  Enjoy!\n\n# Prerequisite\n\nSwift 5 or better, OS X or Linux to build.\n\n* Depends on [attaswift/BigInt] for internal representation of\n`BigFloat` and `BigRat`.\n* Depends on [apple/swift-numerics] since\nversion 5.1 for the `ElementaryFunctions` protocol.\n* Prior versions depended on [dankogai/swift-floatingpoint] for the\n`FloatingPointMath` protocols but it is replaced by the\n`ElementaryFunctions`.\n\n[attaswift/BigInt]: https://github.com/attaswift/BigInt\n[apple/swift-numerics]: https://github.com/apple/swift-numerics\n[dankogai/swift-floatingpoint]: https://github.com/danogai/swift-floatingpoint\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdankogai%2Fswift-bignum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdankogai%2Fswift-bignum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdankogai%2Fswift-bignum/lists"}