https://github.com/scalajs-io/bignum
Arbitrary-precision integer arithmetic using OpenSSL
https://github.com/scalajs-io/bignum
node nodejs npm scala scalajs
Last synced: 4 months ago
JSON representation
Arbitrary-precision integer arithmetic using OpenSSL
- Host: GitHub
- URL: https://github.com/scalajs-io/bignum
- Owner: scalajs-io
- License: apache-2.0
- Created: 2017-02-05T03:43:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:07:14.000Z (about 6 years ago)
- Last Synced: 2025-01-17T22:42:51.960Z (5 months ago)
- Topics: node, nodejs, npm, scala, scalajs
- Language: Scala
- Size: 19.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Bignum API for Scala.js
================================
[bignum](https://www.npmjs.com/package/bignum) - An arbitrary-precision integer arithmetic using OpenSSL.### Description
This library is based on node-bigint by substack, but instead of using libgmp, it uses the builtin bignum
functionality provided by OpenSSL. The advantage is that OpenSSL is already part of Node.js, so this library
does not add any external dependency whatsoever.### Build Requirements
* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally
```bash
$ sbt clean publish-local
```### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```Then you can run the tests:
```bash
$ sbt test
```### Examples
You can perform math functions via built-in methods:
```scala
import io.scalajs.npm.bignum._val v1 = "782910138827292261791972728324982"
val v2 = "182373273283402171237474774728373"val b = new BigNum(v1).add(500).sub(v2).div(8)
// b.toString == "75067108192986261319312244199638"
```Alternatively, you can perform math functions via overloaded operators:
```scala
import io.scalajs.npm.bignum._val v1 = "782910138827292261791972728324982"
val v2 = "182373273283402171237474774728373"val b = (new BigNum(v1) + 500 - v2) / 8
// b.toString == "75067108192986261319312244199638"
```Prime number detection:
```scala
import io.scalajs.npm.bignum._val v1 = "782910138827292261791972728324982"
val v2 = "182373273283402171237474774728373"for {
n <- 0 to 100
p = BigNum.pow(2, n) - 1 if p.probPrime(50)
} {
val perfect = p.mul(BigNum.pow(2, n - 1))
println(perfect.toString)
}
```### Artifacts and Resolvers
To add the `BigNum` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "bignum" % "0.5.0"
```Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```