code is now typescript. Some minor fixes
This commit is contained in:
parent
ff9f8afd61
commit
fd780cb3ec
|
@ -15,7 +15,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [11, 12, 13]
|
node-version: [10, 12, 14]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ jobs:
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
if: steps.check.outputs.changed == 'true'
|
if: steps.check.outputs.changed == 'true'
|
||||||
with:
|
with:
|
||||||
node-version: 12
|
node-version: 14
|
||||||
registry-url: https://registry.npmjs.org/
|
registry-url: https://registry.npmjs.org/
|
||||||
|
|
||||||
- name: install
|
- name: install
|
||||||
|
|
|
@ -12,9 +12,9 @@ node_modules
|
||||||
# Visual Studio Code
|
# Visual Studio Code
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
.idea
|
|
||||||
|
|
||||||
# MYC output
|
# MYC output
|
||||||
.nyc_output
|
.nyc_output
|
||||||
coverage/*
|
coverage
|
||||||
|
|
||||||
|
# Test temporal files
|
||||||
|
.mocha-ts
|
||||||
|
|
21
.npmignore
21
.npmignore
|
@ -1,8 +1,9 @@
|
||||||
# Build scripts
|
# Build scripts
|
||||||
build/*
|
build
|
||||||
|
|
||||||
# Source files
|
# Test files
|
||||||
src/*
|
test
|
||||||
|
**/*.spec.ts
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
@ -20,10 +21,16 @@ npm-debug.log*
|
||||||
|
|
||||||
# MYC output
|
# MYC output
|
||||||
.nyc_output
|
.nyc_output
|
||||||
coverage/*
|
coverage
|
||||||
|
|
||||||
# Travis
|
|
||||||
.travis.yml
|
|
||||||
|
|
||||||
# GitHub
|
# GitHub
|
||||||
.github
|
.github
|
||||||
|
|
||||||
|
# tsconfig
|
||||||
|
tsconfig.json
|
||||||
|
|
||||||
|
# SRC docs
|
||||||
|
src/docs
|
||||||
|
|
||||||
|
# Test temporal files
|
||||||
|
.mocha-ts
|
215
README.md
215
README.md
|
@ -1,6 +1,6 @@
|
||||||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
||||||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
|
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
|
||||||
![Node CI](https://github.com/juanelas/bigint-mod-arith/workflows/Node%20CI/badge.svg)
|
[![Node CI](https://github.com/juanelas/bigint-mod-arith/workflows/Node%20CI/badge.svg)](https://github.com/juanelas/bigint-mod-arith/actions?query=workflow%3A%22Node+CI%22)
|
||||||
[![Coverage Status](https://coveralls.io/repos/github/juanelas/bigint-mod-arith/badge.svg?branch=master)](https://coveralls.io/github/juanelas/bigint-mod-arith?branch=master)
|
[![Coverage Status](https://coveralls.io/repos/github/juanelas/bigint-mod-arith/badge.svg?branch=master)](https://coveralls.io/github/juanelas/bigint-mod-arith?branch=master)
|
||||||
|
|
||||||
# bigint-mod-arith
|
# bigint-mod-arith
|
||||||
|
@ -9,57 +9,33 @@ Some extra functions to work with modular arithmetic using native JS ([ES-2020](
|
||||||
|
|
||||||
> The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html).
|
> The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html).
|
||||||
|
|
||||||
## Installation
|
## Usage
|
||||||
|
|
||||||
bigint-mod-arith is distributed for [web browsers and/or webviews supporting BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) as an ES6 module or an IIFE file; and for Node.js (>=10.4.0), as a CJS module.
|
`bigint-mod-arith` can be imported to your project with `npm`:
|
||||||
|
|
||||||
bigint-mod-arith can be imported to your project with `npm`:
|
```console
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install bigint-mod-arith
|
npm install bigint-mod-arith
|
||||||
```
|
```
|
||||||
|
|
||||||
NPM installation defaults to the ES6 module for browsers and the CJS one for Node.js. For web browsers, you can also directly download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/lib/index.browser.bundle.iife.js) or the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/lib/index.browser.bundle.mod.js) from the repository.
|
Then either require (Node.js CJS):
|
||||||
|
|
||||||
|
|
||||||
## Usage example
|
|
||||||
|
|
||||||
Import your module as :
|
|
||||||
|
|
||||||
- Node.js
|
|
||||||
```javascript
|
```javascript
|
||||||
const bigintModArith = require('bigint-mod-arith')
|
const bigintModArith = require('bigint-mod-arith')
|
||||||
... // your code here
|
|
||||||
```
|
```
|
||||||
- JavaScript native or TypeScript project (including React and Angular)
|
|
||||||
|
or import (JavaScript ES module):
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import * as bigintModArith from 'bigint-mod-arith'
|
import * as bigintModArith from 'bigint-mod-arith'
|
||||||
... // your code here
|
|
||||||
```
|
|
||||||
- JavaScript native browser ES module
|
|
||||||
```html
|
|
||||||
<script type="module">
|
|
||||||
import * as bigintModArith from 'lib/index.browser.bundle.mod.js' // Use you actual path to the broser mod bundle
|
|
||||||
... // your code here
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
- JavaScript native browser IIFE
|
|
||||||
```html
|
|
||||||
<head>
|
|
||||||
...
|
|
||||||
<script src="../../lib/index.browser.bundle.iife.js"></script> <!-- Use you actual path to the browser bundle -->
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
...
|
|
||||||
<script>
|
|
||||||
... // your code here
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The appropriate version for browser or node is automatically exported.
|
||||||
|
|
||||||
|
You can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/dist/bundles/bigint-mod-arith.iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/dist/bundles/bigint-mod-arith.esm.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/dist/bundles/bigint-mod-arith.umd.js) and manually add it to your project, or, if you have already imported `bigint-mod-arith` to your project, just get the bundles from `node_modules/bigint-mod-arith/dist/bundles/`.
|
||||||
|
|
||||||
An example of usage could be:
|
An example of usage could be:
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
/* Stage 3 BigInts with value 666 can be declared as BigInt('666')
|
/* Stage 3 BigInts with value 666 can be declared as BigInt('666')
|
||||||
or the shorter syntax 666n.
|
or the shorter syntax 666n.
|
||||||
Notice that you can also pass a number, e.g. BigInt(666), but it is not
|
Notice that you can also pass a number, e.g. BigInt(666), but it is not
|
||||||
|
@ -75,171 +51,8 @@ console.log(bigintModArith.modPow(a, b, n)) // prints 6
|
||||||
console.log(bigintModArith.modInv(2n, 5n)) // prints 3
|
console.log(bigintModArith.modInv(2n, 5n)) // prints 3
|
||||||
|
|
||||||
console.log(bigintModArith.modInv(BigInt('3'), BigInt('5'))) // prints 2
|
console.log(bigintModArith.modInv(BigInt('3'), BigInt('5'))) // prints 2
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## API reference documentation
|
## API reference documentation
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith"></a>
|
[Check the API](./docs/API.md)
|
||||||
|
|
||||||
### bigint-mod-arith
|
|
||||||
Some common functions for modular arithmetic using native JS implementation of BigInt
|
|
||||||
|
|
||||||
|
|
||||||
* [bigint-mod-arith](#module_bigint-mod-arith)
|
|
||||||
* [~abs(a)](#module_bigint-mod-arith..abs) ⇒ <code>bigint</code>
|
|
||||||
* [~bitLength(a)](#module_bigint-mod-arith..bitLength) ⇒ <code>number</code>
|
|
||||||
* [~eGcd(a, b)](#module_bigint-mod-arith..eGcd) ⇒ <code>egcdReturn</code>
|
|
||||||
* [~gcd(a, b)](#module_bigint-mod-arith..gcd) ⇒ <code>bigint</code>
|
|
||||||
* [~lcm(a, b)](#module_bigint-mod-arith..lcm) ⇒ <code>bigint</code>
|
|
||||||
* [~max(a, b)](#module_bigint-mod-arith..max) ⇒ <code>bigint</code>
|
|
||||||
* [~min(a, b)](#module_bigint-mod-arith..min) ⇒ <code>bigint</code>
|
|
||||||
* [~modInv(a, n)](#module_bigint-mod-arith..modInv) ⇒ <code>bigint</code> \| <code>NaN</code>
|
|
||||||
* [~modPow(b, e, n)](#module_bigint-mod-arith..modPow) ⇒ <code>bigint</code>
|
|
||||||
* [~toZn(a, n)](#module_bigint-mod-arith..toZn) ⇒ <code>bigint</code>
|
|
||||||
* [~egcdReturn](#module_bigint-mod-arith..egcdReturn) : <code>Object</code>
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..abs"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~abs(a) ⇒ <code>bigint</code>
|
|
||||||
Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>bigint</code> - the absolute value of a
|
|
||||||
|
|
||||||
| Param | Type |
|
|
||||||
| --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..bitLength"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~bitLength(a) ⇒ <code>number</code>
|
|
||||||
Returns the bitlength of a number
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>number</code> - - the bit length
|
|
||||||
|
|
||||||
| Param | Type |
|
|
||||||
| --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..eGcd"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~eGcd(a, b) ⇒ <code>egcdReturn</code>
|
|
||||||
An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
|
|
||||||
Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>egcdReturn</code> - A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
|
|
||||||
| Param | Type |
|
|
||||||
| --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> |
|
|
||||||
| b | <code>number</code> \| <code>bigint</code> |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..gcd"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~gcd(a, b) ⇒ <code>bigint</code>
|
|
||||||
Greatest-common divisor of two integers based on the iterative binary algorithm.
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>bigint</code> - The greatest common divisor of a and b
|
|
||||||
|
|
||||||
| Param | Type |
|
|
||||||
| --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> |
|
|
||||||
| b | <code>number</code> \| <code>bigint</code> |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..lcm"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~lcm(a, b) ⇒ <code>bigint</code>
|
|
||||||
The least common multiple computed as abs(a*b)/gcd(a,b)
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>bigint</code> - The least common multiple of a and b
|
|
||||||
|
|
||||||
| Param | Type |
|
|
||||||
| --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> |
|
|
||||||
| b | <code>number</code> \| <code>bigint</code> |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..max"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~max(a, b) ⇒ <code>bigint</code>
|
|
||||||
Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>bigint</code> - maximum of numbers a and b
|
|
||||||
|
|
||||||
| Param | Type |
|
|
||||||
| --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> |
|
|
||||||
| b | <code>number</code> \| <code>bigint</code> |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..min"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~min(a, b) ⇒ <code>bigint</code>
|
|
||||||
Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>bigint</code> - minimum of numbers a and b
|
|
||||||
|
|
||||||
| Param | Type |
|
|
||||||
| --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> |
|
|
||||||
| b | <code>number</code> \| <code>bigint</code> |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..modInv"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~modInv(a, n) ⇒ <code>bigint</code> \| <code>NaN</code>
|
|
||||||
Modular inverse.
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>bigint</code> \| <code>NaN</code> - the inverse modulo n or NaN if it does not exist
|
|
||||||
|
|
||||||
| Param | Type | Description |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> | The number to find an inverse for |
|
|
||||||
| n | <code>number</code> \| <code>bigint</code> | The modulo |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..modPow"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~modPow(b, e, n) ⇒ <code>bigint</code>
|
|
||||||
Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>bigint</code> - b**e mod n
|
|
||||||
|
|
||||||
| Param | Type | Description |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| b | <code>number</code> \| <code>bigint</code> | base |
|
|
||||||
| e | <code>number</code> \| <code>bigint</code> | exponent |
|
|
||||||
| n | <code>number</code> \| <code>bigint</code> | modulo |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..toZn"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~toZn(a, n) ⇒ <code>bigint</code>
|
|
||||||
Finds the smallest positive element that is congruent to a in modulo n
|
|
||||||
|
|
||||||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Returns**: <code>bigint</code> - The smallest positive representation of a in modulo n
|
|
||||||
|
|
||||||
| Param | Type | Description |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| a | <code>number</code> \| <code>bigint</code> | An integer |
|
|
||||||
| n | <code>number</code> \| <code>bigint</code> | The modulo |
|
|
||||||
|
|
||||||
<a name="module_bigint-mod-arith..egcdReturn"></a>
|
|
||||||
|
|
||||||
#### bigint-mod-arith~egcdReturn : <code>Object</code>
|
|
||||||
A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
|
|
||||||
**Kind**: inner typedef of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith)
|
|
||||||
**Properties**
|
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
| --- | --- |
|
|
||||||
| g | <code>bigint</code> |
|
|
||||||
| x | <code>bigint</code> |
|
|
||||||
| y | <code>bigint</code> |
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
#! /usr/bin/env node
|
||||||
|
const path = require('path')
|
||||||
|
const childProcess = require('child_process')
|
||||||
|
|
||||||
|
const rootDir = path.join(__dirname, '../..')
|
||||||
|
const mochaTsRelativeDir = '.mocha-ts'
|
||||||
|
const minimatch = require('minimatch')
|
||||||
|
const glob = require('glob')
|
||||||
|
|
||||||
|
// First let us prepare the args to pass to mocha.
|
||||||
|
// ts.files will be replaced by their js-transpiled counterparts
|
||||||
|
// a watch file to our semaphore will be added
|
||||||
|
const processedArgs = processArgs(process.argv.slice(2))
|
||||||
|
|
||||||
|
// Now we can run a script and invoke a callback when complete, e.g.
|
||||||
|
runScript(path.join(rootDir, 'node_modules/.bin/mocha'), processArgs(processedArgs))
|
||||||
|
|
||||||
|
function processArgs (args) {
|
||||||
|
args = process.argv.slice(2).map(arg => {
|
||||||
|
const filenames = glob.sync(arg, { cwd: rootDir, matchBase: true })
|
||||||
|
if (filenames.length > 0) {
|
||||||
|
return filenames.map(file => {
|
||||||
|
const isTsTestFile = minimatch(file, '{test/**/*.ts,src/**/*.spec.ts}', { matchBase: true })
|
||||||
|
if (isTsTestFile) {
|
||||||
|
return `${mochaTsRelativeDir}/${file.slice(0, -3)}.js`
|
||||||
|
}
|
||||||
|
return file
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return arg
|
||||||
|
})
|
||||||
|
|
||||||
|
const processedArgs = []
|
||||||
|
|
||||||
|
let addSemaphore = false
|
||||||
|
let semaphoreAdded = false
|
||||||
|
for (const arg of args) {
|
||||||
|
if (Array.isArray(arg)) {
|
||||||
|
processedArgs.push(...arg)
|
||||||
|
} else {
|
||||||
|
processedArgs.push(arg)
|
||||||
|
if (arg === '--watch' || arg === '-w') {
|
||||||
|
addSemaphore = true
|
||||||
|
} else if (arg === '--watch-files') {
|
||||||
|
processedArgs.push(`${mochaTsRelativeDir}/semaphore`)
|
||||||
|
semaphoreAdded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (addSemaphore === true || semaphoreAdded === false) {
|
||||||
|
processedArgs.push('--watch-files')
|
||||||
|
processedArgs.push(`${mochaTsRelativeDir}/semaphore`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return processedArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
function runScript (scriptPath, args) {
|
||||||
|
const mochaCmd = childProcess.fork(path.join(rootDir, 'node_modules/.bin/mocha'), processedArgs, {
|
||||||
|
cwd: rootDir
|
||||||
|
})
|
||||||
|
|
||||||
|
mochaCmd.on('error', (error) => {
|
||||||
|
throw error
|
||||||
|
})
|
||||||
|
|
||||||
|
// execute the callback once the process has finished running
|
||||||
|
mochaCmd.on('exit', function (code) {
|
||||||
|
if (code !== 0) {
|
||||||
|
throw new Error('exit code ' + code)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const jsdoc2md = require('jsdoc-to-markdown')
|
const TypeDoc = require('typedoc')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const pkgJson = require('../package.json')
|
const pkgJson = require('../package.json')
|
||||||
|
|
||||||
|
@ -14,6 +14,33 @@ function camelise (str) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function typedoc () {
|
||||||
|
const app = new TypeDoc.Application()
|
||||||
|
|
||||||
|
// If you want TypeDoc to load tsconfig.json / typedoc.json files
|
||||||
|
app.options.addReader(new TypeDoc.TSConfigReader())
|
||||||
|
app.options.addReader(new TypeDoc.TypeDocReader())
|
||||||
|
|
||||||
|
app.bootstrap({
|
||||||
|
// typedoc options here
|
||||||
|
entryPoints: ['src/index.ts'],
|
||||||
|
plugin: ['typedoc-plugin-markdown'],
|
||||||
|
includeVersion: true,
|
||||||
|
entryDocument: 'API.md',
|
||||||
|
readme: 'none'
|
||||||
|
})
|
||||||
|
|
||||||
|
const project = app.convert()
|
||||||
|
|
||||||
|
if (project) {
|
||||||
|
// Project may not have converted correctly
|
||||||
|
const output = path.join(rootDir, './docs')
|
||||||
|
|
||||||
|
// Rendered docs
|
||||||
|
await app.generateDocs(project, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getRepositoryData () {
|
function getRepositoryData () {
|
||||||
if (typeof pkgJson.repository === 'string') {
|
if (typeof pkgJson.repository === 'string') {
|
||||||
const repodata = pkgJson.repository.split(/[:/]/)
|
const repodata = pkgJson.repository.split(/[:/]/)
|
||||||
|
@ -30,39 +57,45 @@ function getRepositoryData () {
|
||||||
|
|
||||||
const { repoProvider, repoUsername, repoName } = getRepositoryData() || { repoProvider: null, repoUsername: null, repoName: null }
|
const { repoProvider, repoUsername, repoName } = getRepositoryData() || { repoProvider: null, repoUsername: null, repoName: null }
|
||||||
|
|
||||||
let iifeBundle, esmBundle, workflowBadget, coverallsBadge
|
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // We are going to take only the package name part if there is a scope, e.g. @my-org/package-name
|
||||||
if (repoProvider && repoProvider === 'github') {
|
const { name } = pkgJson.name.match(regex).groups
|
||||||
iifeBundle = `[IIFE bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/lib/index.browser.bundle.iife.js)`
|
const camelCaseName = camelise(name)
|
||||||
esmBundle = `[ESM bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/lib/index.browser.bundle.mod.js)`
|
|
||||||
workflowBadget = `![Node CI](https://github.com/${repoUsername}/${repoName}/workflows/Node%20CI/badge.svg)`
|
let iifeBundle, esmBundle, umdBundle, workflowBadget, coverallsBadge
|
||||||
|
if (repoProvider) {
|
||||||
|
switch (repoProvider) {
|
||||||
|
case 'github':
|
||||||
|
iifeBundle = `[IIFE bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/dist/bundles/${name}.iife.js)`
|
||||||
|
esmBundle = `[ESM bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/dist/bundles/${name}.esm.js)`
|
||||||
|
umdBundle = `[UMD bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/dist/bundles/${name}.umd.js)`
|
||||||
|
workflowBadget = `[![Node CI](https://github.com/${repoUsername}/${repoName}/workflows/Node%20CI/badge.svg)](https://github.com/${repoUsername}/${repoName}/actions?query=workflow%3A%22Node+CI%22)`
|
||||||
coverallsBadge = `[![Coverage Status](https://coveralls.io/repos/github/${repoUsername}/${repoName}/badge.svg?branch=master)](https://coveralls.io/github/${repoUsername}/${repoName}?branch=master)`
|
coverallsBadge = `[![Coverage Status](https://coveralls.io/repos/github/${repoUsername}/${repoName}/badge.svg?branch=master)](https://coveralls.io/github/${repoUsername}/${repoName}?branch=master)`
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'gitlab':
|
||||||
|
iifeBundle = `[IIFE bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/dist/bundles/${name}.iife.js?inline=false)`
|
||||||
|
esmBundle = `[ESM bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/dist/bundles/${name}.esm.js?inline=false)`
|
||||||
|
umdBundle = `[IIFE bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/dist/bundles/${name}.umd.js?inline=false)`
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const templateFile = path.join(rootDir, pkgJson.directories.src, 'doc', 'readme-template.md')
|
const templateFile = path.join(rootDir, pkgJson.directories.src, 'docs/index.md')
|
||||||
let template = fs.readFileSync(templateFile, { encoding: 'UTF-8' })
|
let template = fs.readFileSync(templateFile, { encoding: 'UTF-8' })
|
||||||
.replace(/\{\{PKG_NAME\}\}/g, pkgJson.name)
|
.replace(/\{\{PKG_NAME\}\}/g, pkgJson.name)
|
||||||
.replace(/\{\{PKG_CAMELCASE\}\}/g, camelise(pkgJson.name))
|
.replace(/\{\{PKG_CAMELCASE\}\}/g, camelCaseName)
|
||||||
.replace(/\{\{IIFE_BUNDLE\}\}/g, iifeBundle || 'IIFE bundle')
|
.replace(/\{\{IIFE_BUNDLE\}\}/g, iifeBundle || 'IIFE bundle')
|
||||||
.replace(/\{\{ESM_BUNDLE\}\}/g, esmBundle || 'ESM bundle')
|
.replace(/\{\{ESM_BUNDLE\}\}/g, esmBundle || 'ESM bundle')
|
||||||
|
.replace(/\{\{UMD_BUNDLE\}\}/g, umdBundle || 'UMD bundle')
|
||||||
|
|
||||||
if (repoProvider && repoProvider === 'github') {
|
if (repoProvider && repoProvider === 'github') {
|
||||||
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}/g, workflowBadget + '\n' + coverallsBadge)
|
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}/g, workflowBadget + '\n' + coverallsBadge)
|
||||||
}
|
}
|
||||||
|
|
||||||
const input = path.join(rootDir, pkgJson.browser)
|
|
||||||
// Let us replace bigint literals by standard numbers to avoid issues with bigint
|
|
||||||
const source = fs.readFileSync(input, { encoding: 'UTF-8' }).replace(/([0-9]+)n([,\s\n)])/g, '$1$2')
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
source,
|
|
||||||
template,
|
|
||||||
'heading-depth': 3, // The initial heading depth. For example, with a value of 2 the top-level markdown headings look like "## The heading"
|
|
||||||
'global-index-format': 'none' // none, grouped, table, dl.
|
|
||||||
}
|
|
||||||
|
|
||||||
jsdoc2md.clear().then(() => {
|
|
||||||
const readmeContents = jsdoc2md.renderSync(options)
|
|
||||||
|
|
||||||
const readmeFile = path.join(rootDir, 'README.md')
|
const readmeFile = path.join(rootDir, 'README.md')
|
||||||
fs.writeFileSync(readmeFile, readmeContents)
|
fs.writeFileSync(readmeFile, template)
|
||||||
})
|
|
||||||
|
typedoc()
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
const fs = require('fs')
|
|
||||||
const ts = require('typescript')
|
|
||||||
const path = require('path')
|
|
||||||
const pkgJson = require('../package.json')
|
|
||||||
|
|
||||||
const rootDir = path.join(__dirname, '..')
|
|
||||||
const jsFile = path.join(rootDir, pkgJson.browser)
|
|
||||||
const dtsFile = path.join(rootDir, pkgJson.types)
|
|
||||||
|
|
||||||
const compilerOptions = {
|
|
||||||
declaration: true,
|
|
||||||
noEmit: false,
|
|
||||||
emitDeclarationOnly: true,
|
|
||||||
allowJs: true
|
|
||||||
}
|
|
||||||
|
|
||||||
const host = ts.createCompilerHost(compilerOptions)
|
|
||||||
|
|
||||||
host.writeFile = (fileName, contents) => {
|
|
||||||
fs.writeFileSync(dtsFile, contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare and emit the d.ts files
|
|
||||||
const program = ts.createProgram([jsFile], compilerOptions, host)
|
|
||||||
program.emit()
|
|
|
@ -1,15 +1,18 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const resolve = require('@rollup/plugin-node-resolve')
|
const resolve = require('@rollup/plugin-node-resolve').nodeResolve
|
||||||
const replace = require('@rollup/plugin-replace')
|
const replace = require('@rollup/plugin-replace')
|
||||||
const { terser } = require('rollup-plugin-terser')
|
const { terser } = require('rollup-plugin-terser')
|
||||||
|
const typescriptPlugin = require('@rollup/plugin-typescript')
|
||||||
|
const commonjs = require('@rollup/plugin-commonjs')
|
||||||
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
const pkgJson = require('../package.json')
|
const pkgJson = require('../package.json')
|
||||||
|
|
||||||
const rootDir = path.join(__dirname, '..')
|
const rootDir = path.join(__dirname, '..')
|
||||||
const srcDir = path.join(rootDir, pkgJson.directories.src)
|
const dstDir = path.join(rootDir, pkgJson.directories.dist)
|
||||||
const dstDir = path.join(rootDir, pkgJson.directories.lib)
|
const srcDir = path.join(rootDir, 'src')
|
||||||
|
|
||||||
function camelise (str) {
|
function camelise (str) {
|
||||||
return str.replace(/-([a-z])/g,
|
return str.replace(/-([a-z])/g,
|
||||||
|
@ -18,61 +21,113 @@ function camelise (str) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const pkgName = pkgJson.name
|
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // We are going to take only the package name part if there is a scope, e.g. @my-org/package-name
|
||||||
const pkgCamelisedName = camelise(pkgName)
|
const { name } = pkgJson.name.match(regex).groups
|
||||||
|
const pkgCamelisedName = camelise(name)
|
||||||
|
|
||||||
const input = path.join(srcDir, 'js', 'index.js')
|
const input = path.join(srcDir, 'index.ts')
|
||||||
|
if (fs.existsSync(input) !== true) throw new Error('The entry point should be index.ts')
|
||||||
|
|
||||||
|
const tsBundleOptions = {
|
||||||
|
exclude: ['test/**/*', 'src/**/*.spec.ts', './build/typings/global-this-pkg.d.ts']
|
||||||
|
}
|
||||||
|
|
||||||
|
const external = [...Object.keys(pkgJson.dependencies || {}), ...Object.keys(pkgJson.peerDependencies || {})]
|
||||||
|
|
||||||
|
const sourcemapOutputOptions = {
|
||||||
|
sourcemap: 'inline',
|
||||||
|
sourcemapExcludeSources: true
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{ // Native JS
|
{ // ESM for browsers
|
||||||
input: input,
|
input: input,
|
||||||
output: [
|
output: [
|
||||||
{
|
{
|
||||||
file: path.join(rootDir, pkgJson.browser),
|
file: path.join(rootDir, pkgJson.exports['.'].default),
|
||||||
|
...sourcemapOutputOptions,
|
||||||
format: 'es'
|
format: 'es'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
replace({
|
replace({
|
||||||
'process.browser': true
|
IS_BROWSER: true,
|
||||||
})
|
preventAssignment: true
|
||||||
]
|
}),
|
||||||
// external: ['bigint-crypto-utils']
|
typescriptPlugin(tsBundleOptions)
|
||||||
|
],
|
||||||
|
external
|
||||||
},
|
},
|
||||||
{ // Browser bundles
|
{ // Browser bundles
|
||||||
input: input,
|
input: input,
|
||||||
output: [
|
output: [
|
||||||
{
|
{
|
||||||
file: path.join(dstDir, 'index.browser.bundle.iife.js'),
|
file: path.join(dstDir, `bundles/${name}.iife.js`),
|
||||||
format: 'iife',
|
format: 'iife',
|
||||||
name: pkgCamelisedName
|
name: pkgCamelisedName
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: path.join(dstDir, 'index.browser.bundle.mod.js'),
|
file: path.join(dstDir, `bundles/${name}.esm.js`),
|
||||||
format: 'es'
|
format: 'es'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: path.join(dstDir, `bundles/${name}.umd.js`),
|
||||||
|
format: 'umd',
|
||||||
|
name: pkgCamelisedName
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
replace({
|
replace({
|
||||||
'process.browser': true
|
IS_BROWSER: true,
|
||||||
|
preventAssignment: true
|
||||||
}),
|
}),
|
||||||
|
typescriptPlugin(tsBundleOptions),
|
||||||
resolve({
|
resolve({
|
||||||
browser: true
|
browser: true,
|
||||||
|
exportConditions: ['browser', 'module', 'import', 'default']
|
||||||
}),
|
}),
|
||||||
terser()
|
terser()
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ // Node
|
{ // Node ESM
|
||||||
input: input,
|
input: input,
|
||||||
output: {
|
output: {
|
||||||
file: path.join(rootDir, pkgJson.main),
|
dir: path.join(rootDir, path.dirname(pkgJson.exports['.'].node.import)),
|
||||||
|
entryFileNames: path.basename(pkgJson.exports['.'].node.import),
|
||||||
|
...sourcemapOutputOptions,
|
||||||
|
format: 'es'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
replace({
|
||||||
|
IS_BROWSER: false,
|
||||||
|
preventAssignment: true
|
||||||
|
}),
|
||||||
|
typescriptPlugin({
|
||||||
|
...tsBundleOptions,
|
||||||
|
declaration: true,
|
||||||
|
outDir: path.join(rootDir, path.dirname(pkgJson.exports['.'].node.import)),
|
||||||
|
declarationDir: path.join(rootDir, path.dirname(pkgJson.exports['.'].node.import), 'types'),
|
||||||
|
declarationMap: true
|
||||||
|
}),
|
||||||
|
commonjs({ extensions: ['.js', '.ts'] }) // the ".ts" extension is required
|
||||||
|
],
|
||||||
|
external
|
||||||
|
},
|
||||||
|
{ // Node CJS with declaration files
|
||||||
|
input: input,
|
||||||
|
output: {
|
||||||
|
dir: path.join(rootDir, path.dirname(pkgJson.exports['.'].node.require)),
|
||||||
|
entryFileNames: path.basename(pkgJson.exports['.'].node.require),
|
||||||
|
...sourcemapOutputOptions,
|
||||||
format: 'cjs'
|
format: 'cjs'
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
replace({
|
replace({
|
||||||
'process.browser': false
|
IS_BROWSER: false,
|
||||||
})
|
preventAssignment: true
|
||||||
|
}),
|
||||||
|
typescriptPlugin(tsBundleOptions),
|
||||||
|
commonjs({ extensions: ['.js', '.ts'] }) // the ".ts" extension is required
|
||||||
]
|
]
|
||||||
// external: ['bigint-crypto-utils']
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
const resolve = require('@rollup/plugin-node-resolve')
|
|
||||||
const replace = require('@rollup/plugin-replace')
|
|
||||||
const commonjs = require('@rollup/plugin-commonjs')
|
|
||||||
const multi = require('@rollup/plugin-multi-entry')
|
|
||||||
|
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
const pkgJson = require('../package.json')
|
|
||||||
const pkgJsonLock = require('../package-lock.json')
|
|
||||||
const mochaVersion = pkgJsonLock.dependencies.mocha.version
|
|
||||||
const chaiVersion = pkgJsonLock.dependencies.chai.version
|
|
||||||
const pkgName = pkgJson.name
|
|
||||||
|
|
||||||
const rootDir = path.join(__dirname, '..')
|
|
||||||
|
|
||||||
// Let's first create the appropriate html file loading mocha, chai and a bundle of the tests
|
|
||||||
const templatePath = path.join(rootDir, pkgJson.directories.src, 'browser', 'tests-template.html')
|
|
||||||
const dstDir = path.join(rootDir, pkgJson.directories.test, 'browser')
|
|
||||||
const dstFileName = path.join(dstDir, 'index.html')
|
|
||||||
|
|
||||||
const template = fs.readFileSync(templatePath, 'utf-8')
|
|
||||||
const bundleFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js')
|
|
||||||
const testsJs = `
|
|
||||||
<script type="module">
|
|
||||||
import * as _pkg from '${path.relative(templatePath, bundleFile)}'
|
|
||||||
window._pkg = _pkg;
|
|
||||||
import './tests.js';
|
|
||||||
mocha.run();
|
|
||||||
</script>`
|
|
||||||
|
|
||||||
fs.writeFileSync(dstFileName,
|
|
||||||
template.replace(/{{TESTS}}/g, testsJs).replace(/{{PKG_NAME}}/g, pkgName).replace(/{{MOCHA_VERSION}}/g, mochaVersion).replace(/{{CHAI_VERSION}}/g, chaiVersion)
|
|
||||||
)
|
|
||||||
|
|
||||||
const input = path.join(rootDir, pkgJson.directories.test, '*.js')
|
|
||||||
console.log(input)
|
|
||||||
|
|
||||||
module.exports = [
|
|
||||||
{
|
|
||||||
input: input,
|
|
||||||
plugins: [
|
|
||||||
multi({ exports: false }),
|
|
||||||
replace({
|
|
||||||
'const _pkg = require(\'../lib/index.node\')': '',
|
|
||||||
'const chai = require(\'chai\')': '',
|
|
||||||
delimiters: ['', ''],
|
|
||||||
'process.browser': true
|
|
||||||
}),
|
|
||||||
resolve({
|
|
||||||
browser: true
|
|
||||||
}),
|
|
||||||
commonjs()
|
|
||||||
],
|
|
||||||
output: {
|
|
||||||
file: path.join(rootDir, pkgJson.directories.test, 'browser', 'tests.js'),
|
|
||||||
format: 'esm'
|
|
||||||
},
|
|
||||||
external: [pkgName]
|
|
||||||
}
|
|
||||||
]
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
const puppeteer = require('puppeteer')
|
||||||
|
|
||||||
|
const browserTests = async ({ logWarnings = false, serverPort = 38000, keepServerRunning = false, puppeteerOptions = {} }) => {
|
||||||
|
const server = require('./server.js').server
|
||||||
|
await server.init()
|
||||||
|
await server.listen(serverPort)
|
||||||
|
const browser = await puppeteer.launch(puppeteerOptions)
|
||||||
|
const page = await browser.newPage()
|
||||||
|
page.on('console', function (message) {
|
||||||
|
let ignore = message.type() === 'warning' && !logWarnings
|
||||||
|
if (message.type() === 'error' && message.location()) {
|
||||||
|
if (message.location().url.includes('favicon.ico')) {
|
||||||
|
ignore = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ignore) return
|
||||||
|
|
||||||
|
let text = (message.args().length > 0) ? message.args()[0]._remoteObject.value : message.text()
|
||||||
|
const args = []
|
||||||
|
if (message.args() !== undefined && message.args().length > 1) {
|
||||||
|
for (let i = 1; i < message.args().length; i++) {
|
||||||
|
args.push(message.args()[i]._remoteObject.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.type() === 'error' && message.location()) {
|
||||||
|
text = `${message.location().url} : ${text}`
|
||||||
|
}
|
||||||
|
let consoleType = 'log'
|
||||||
|
switch (message.type()) {
|
||||||
|
case 'error':
|
||||||
|
consoleType = 'error'
|
||||||
|
break
|
||||||
|
case 'warning':
|
||||||
|
consoleType = 'warn'
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
console[consoleType](text, ...args)
|
||||||
|
})
|
||||||
|
page.on('error', function (err) { page.emit(new Error(err)) })
|
||||||
|
|
||||||
|
await page.goto('http://localhost:38000/')
|
||||||
|
const watchDog = page.waitForFunction('_mocha.state === \'stopped\'')
|
||||||
|
await watchDog
|
||||||
|
|
||||||
|
if (keepServerRunning === false) {
|
||||||
|
await page.close()
|
||||||
|
await browser.close()
|
||||||
|
await server.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
// puppeteer options
|
||||||
|
puppeteerOptions: {
|
||||||
|
headless: true
|
||||||
|
// slowMo: 100,
|
||||||
|
// timeout: 10000
|
||||||
|
},
|
||||||
|
doNotLogWarnings: true,
|
||||||
|
keepServerRunning: false, // keep server running until manually closed with ctrl-c. In combination with puppeteerOptions.headless (or just connecting any browser to the test page) allows debugging in browser
|
||||||
|
serverPort: 38000
|
||||||
|
}
|
||||||
|
browserTests(opts)
|
|
@ -0,0 +1,141 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const http = require('http')
|
||||||
|
const path = require('path')
|
||||||
|
const pkgJson = require('../../../package.json')
|
||||||
|
|
||||||
|
const rollup = require('rollup')
|
||||||
|
const resolve = require('@rollup/plugin-node-resolve').nodeResolve
|
||||||
|
const replace = require('@rollup/plugin-replace')
|
||||||
|
const multi = require('@rollup/plugin-multi-entry')
|
||||||
|
const typescript = require('@rollup/plugin-typescript')
|
||||||
|
const commonjs = require('@rollup/plugin-commonjs')
|
||||||
|
|
||||||
|
const rootDir = path.join(__dirname, '..', '..', '..')
|
||||||
|
|
||||||
|
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // We are going to take only the package name part if there is a scope, e.g. @my-org/package-name
|
||||||
|
const { name } = pkgJson.name.match(regex).groups
|
||||||
|
|
||||||
|
const indexHtml = `<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||||
|
<title>${name}</title>
|
||||||
|
<script src="/mocha.js"></script>
|
||||||
|
<script src="/chai.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
<div id="mocha"></div>
|
||||||
|
<script>
|
||||||
|
mocha.setup({
|
||||||
|
ui: 'bdd',
|
||||||
|
reporter: 'spec',
|
||||||
|
color: 'true',
|
||||||
|
timeout: 90000
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<script type="module">
|
||||||
|
import * as _pkg from './${name}.esm.js'
|
||||||
|
self._pkg = _pkg
|
||||||
|
import './tests.js'
|
||||||
|
window._mocha = mocha.run()
|
||||||
|
</script>
|
||||||
|
</html>`
|
||||||
|
|
||||||
|
async function buildTests () {
|
||||||
|
// create a bundle
|
||||||
|
const inputOptions = {
|
||||||
|
input: [path.join(rootDir, pkgJson.directories.test, '**/*.ts'), path.join(rootDir, pkgJson.directories.src, '**/*.spec.ts')],
|
||||||
|
plugins: [
|
||||||
|
multi({ exports: true }),
|
||||||
|
replace({
|
||||||
|
IS_BROWSER: true,
|
||||||
|
preventAssignment: true
|
||||||
|
}),
|
||||||
|
typescript(),
|
||||||
|
resolve({
|
||||||
|
browser: true,
|
||||||
|
exportConditions: ['browser', 'module', 'import', 'default']
|
||||||
|
}),
|
||||||
|
commonjs()
|
||||||
|
]
|
||||||
|
}
|
||||||
|
const bundle = await rollup.rollup(inputOptions)
|
||||||
|
const { output } = await bundle.generate({ format: 'esm' })
|
||||||
|
await bundle.close()
|
||||||
|
return output[0].code
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestServer {
|
||||||
|
constructor () {
|
||||||
|
this.server = http.createServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
async init () {
|
||||||
|
const tests = await buildTests()
|
||||||
|
this.server.on('request', function (req, res) {
|
||||||
|
if (req.url === `/${name}.esm.js`) {
|
||||||
|
fs.readFile(path.join(rootDir, pkgJson.directories.dist, `bundles/${name}.esm.js`), function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
res.writeHead(404)
|
||||||
|
res.end(JSON.stringify(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||||
|
res.end(data)
|
||||||
|
})
|
||||||
|
} else if (req.url === '/index.html' || req.url === '/') {
|
||||||
|
res.writeHead(200)
|
||||||
|
res.end(indexHtml)
|
||||||
|
} else if (req.url === '/tests.js') {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||||
|
res.end(tests)
|
||||||
|
} else if (req.url === '/mocha.js') {
|
||||||
|
fs.readFile(path.join(rootDir, 'node_modules/mocha/mocha.js'), function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
res.writeHead(404)
|
||||||
|
res.end(JSON.stringify(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||||
|
res.end(data)
|
||||||
|
})
|
||||||
|
} else if (req.url === '/chai.js' || req.url === '/chai') {
|
||||||
|
fs.readFile(path.join(rootDir, 'node_modules/chai/chai.js'), function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
res.writeHead(404)
|
||||||
|
res.end(JSON.stringify(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||||
|
res.end(data)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
res.writeHead(404)
|
||||||
|
res.end()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
listen (port = 38080) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.server.listen(port, error => {
|
||||||
|
if (error) return reject(error)
|
||||||
|
console.log(`Testing server listenning at http://localhost:${port}`)
|
||||||
|
return resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
close () {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.server.close(error => (error) ? reject(error) : resolve())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.server = new TestServer()
|
|
@ -0,0 +1,59 @@
|
||||||
|
const EventEmitter = require('events')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
module.exports = class Builder extends EventEmitter {
|
||||||
|
constructor (semaphoreFile, name = 'builder') {
|
||||||
|
super()
|
||||||
|
this.name = name
|
||||||
|
this.firstBuild = true
|
||||||
|
fs.mkdirSync(path.dirname(semaphoreFile), { recursive: true })
|
||||||
|
|
||||||
|
this.semaphoreFile = semaphoreFile
|
||||||
|
this._ready = false
|
||||||
|
|
||||||
|
this.on('message', (...message) => {
|
||||||
|
if (message !== undefined) {
|
||||||
|
console.log(`\x1b[33mℹ [${this.name}]`, ...message, '\x1b[0m')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.on('error', (...error) => {
|
||||||
|
if (error !== undefined) {
|
||||||
|
console.error(`\x1b[31m❗ [${this.name}]`, ...error, '\x1b[0m')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.on('ready', () => {
|
||||||
|
if (this.firstBuild === false) {
|
||||||
|
fs.writeFileSync(this.semaphoreFile, '', 'utf-8')
|
||||||
|
} else {
|
||||||
|
this.firstBuild = false
|
||||||
|
}
|
||||||
|
this._ready = true
|
||||||
|
})
|
||||||
|
|
||||||
|
this.on('busy', () => {
|
||||||
|
this._ready = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
ready () {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
if (this._ready === true) return resolve()
|
||||||
|
this.once('ready', () => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async start () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async close () {}
|
||||||
|
|
||||||
|
clean () {
|
||||||
|
fs.rmSync(this.semaphoreFile, { force: true })
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
const EventEmitter = require('events')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
const rollup = require('rollup')
|
||||||
|
const loadAndParseConfigFile = require('rollup/dist/loadConfigFile')
|
||||||
|
|
||||||
|
const Builder = require('./Builder.js')
|
||||||
|
|
||||||
|
const rootDir = path.join(__dirname, '../../../../')
|
||||||
|
const pkgJson = require(path.join(rootDir, 'package.json'))
|
||||||
|
|
||||||
|
module.exports = class RollupBuilder extends Builder {
|
||||||
|
constructor ({ name = 'rollup', configPath = path.join(rootDir, 'rollup.config.js'), tempDir = path.join(rootDir, '.mocha-ts'), watch = false }) {
|
||||||
|
super(path.join(tempDir, 'semaphore'), name)
|
||||||
|
this.configPath = configPath
|
||||||
|
this.watch = watch
|
||||||
|
}
|
||||||
|
|
||||||
|
async start () {
|
||||||
|
await super.start()
|
||||||
|
|
||||||
|
const { options } = await loadAndParseConfigFile(this.configPath)
|
||||||
|
// Watch only the Node CJS module, that is the one we are going to use with mocha
|
||||||
|
const rollupOptions = options.filter(bundle => {
|
||||||
|
const file = (bundle.output[0].dir !== undefined)
|
||||||
|
? path.join(bundle.output[0].dir, bundle.output[0].entryFileNames)
|
||||||
|
: bundle.output[0].file
|
||||||
|
return file === path.join(rootDir, pkgJson.main)
|
||||||
|
})[0]
|
||||||
|
|
||||||
|
this.builder = new RollupBundler(rollupOptions, this.watch)
|
||||||
|
|
||||||
|
this.builder.on('event', event => {
|
||||||
|
switch (event.code) {
|
||||||
|
case 'START':
|
||||||
|
this.emit('busy')
|
||||||
|
if (this.firstBuild === true) {
|
||||||
|
this.emit('message', 'building your module...')
|
||||||
|
} else {
|
||||||
|
this.emit('message', 'file changes detected. Rebuilding module files...')
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'BUNDLE_END':
|
||||||
|
if (event.result) event.result.close()
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'END':
|
||||||
|
if (event.result) event.result.close()
|
||||||
|
this.emit('ready')
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'ERROR':
|
||||||
|
if (event.result) event.result.close()
|
||||||
|
this.emit('error', event.error)
|
||||||
|
fs.writeFileSync(path.join(rootDir, pkgJson.main), '', 'utf8')
|
||||||
|
this.emit('ready')
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
this.emit('busy')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.builder.start()
|
||||||
|
|
||||||
|
return await this.ready()
|
||||||
|
}
|
||||||
|
|
||||||
|
async close () {
|
||||||
|
await super.close()
|
||||||
|
this.builder.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RollupBundler extends EventEmitter {
|
||||||
|
constructor (rollupOptions, watch = false) {
|
||||||
|
super()
|
||||||
|
this.rollupOptions = rollupOptions
|
||||||
|
this.watch = watch
|
||||||
|
}
|
||||||
|
|
||||||
|
async start () {
|
||||||
|
if (this.watch === true) {
|
||||||
|
this.watcher = rollup.watch(this.rollupOptions)
|
||||||
|
|
||||||
|
this.watcher.on('event', event => {
|
||||||
|
this.emit('event', event)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (fs.existsSync(path.join(rootDir, pkgJson.main)) === false) {
|
||||||
|
await this._bundle()
|
||||||
|
} else {
|
||||||
|
this.emit('event', { code: 'END', noBuild: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async _bundle () {
|
||||||
|
this.emit('event', { code: 'START' })
|
||||||
|
for (const optionsObj of [].concat(this.rollupOptions)) {
|
||||||
|
try {
|
||||||
|
const bundle = await rollup.rollup(optionsObj)
|
||||||
|
try {
|
||||||
|
await Promise.all(optionsObj.output.map(bundle.write))
|
||||||
|
this.emit('event', { code: 'BUNDLE_END' })
|
||||||
|
} catch (error) {
|
||||||
|
this.emit('event', { code: 'ERROR', error })
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.emit('event', { code: 'ERROR', error })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.emit('event', { code: 'END' })
|
||||||
|
}
|
||||||
|
|
||||||
|
close () {
|
||||||
|
if (this.watcher !== undefined) this.watcher.close()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
const ts = require('typescript')
|
||||||
|
const JSON5 = require('json5')
|
||||||
|
|
||||||
|
const Builder = require('./Builder.js')
|
||||||
|
|
||||||
|
const rootDir = path.join(__dirname, '../../../../')
|
||||||
|
const mochaTsRelativeDir = '.mocha-ts'
|
||||||
|
const mochaTsDir = path.join(rootDir, mochaTsRelativeDir)
|
||||||
|
|
||||||
|
const formatHost = {
|
||||||
|
getCanonicalFileName: path => path,
|
||||||
|
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
||||||
|
getNewLine: () => ts.sys.newLine
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = class TestsBuilder extends Builder {
|
||||||
|
constructor ({ name = 'tsc', configPath = path.join(rootDir, 'tsconfig.json'), tempDir = mochaTsDir }) {
|
||||||
|
super(path.join(tempDir, 'semaphore'), name)
|
||||||
|
|
||||||
|
if (fs.existsSync(configPath) !== true) throw new Error(`Couldn't find a tsconfig file at ${configPath}`)
|
||||||
|
|
||||||
|
this.tempDir = tempDir
|
||||||
|
|
||||||
|
const readFileAndMangle = (path) => { // We need to change the include or file in the original file to only compile the tests
|
||||||
|
const fileStr = fs.readFileSync(path, 'utf8')
|
||||||
|
const config = JSON5.parse(fileStr)
|
||||||
|
if (config.file) delete config.file
|
||||||
|
config.include = ['build/typings/**/*.ts', 'test/**/*.ts', 'src/**/*.spec.ts']
|
||||||
|
return JSON.stringify(config)
|
||||||
|
}
|
||||||
|
const configFile = ts.readJsonConfigFile(configPath, readFileAndMangle)
|
||||||
|
|
||||||
|
const parsedTsConfig = ts.parseJsonSourceFileConfigFileContent(configFile, ts.sys, path.dirname(configPath))
|
||||||
|
|
||||||
|
const createProgram = ts.createSemanticDiagnosticsBuilderProgram
|
||||||
|
|
||||||
|
const reportDiagnostic = (diagnostic) => {
|
||||||
|
const filePath = path.relative(rootDir, diagnostic.file.fileName)
|
||||||
|
const tranpiledJsPath = `${path.join(tempDir, filePath).slice(0, -3)}.js`
|
||||||
|
const errorLine = diagnostic.file.text.slice(0, diagnostic.start).split(/\r\n|\r|\n/).length
|
||||||
|
if (fs.existsSync(tranpiledJsPath)) {
|
||||||
|
fs.writeFileSync(tranpiledJsPath, '', 'utf8')
|
||||||
|
}
|
||||||
|
this.emit('error', `[Error ${diagnostic.code}]`, `${filePath}:${errorLine}`, ':', ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()))
|
||||||
|
}
|
||||||
|
|
||||||
|
const reportWatchStatusChanged = (diagnostic, newLine, options, errorCount) => {
|
||||||
|
if (errorCount !== undefined) {
|
||||||
|
this.emit('ready')
|
||||||
|
} else {
|
||||||
|
this.emit('busy')
|
||||||
|
if (diagnostic.code === 6031) {
|
||||||
|
this.emit('message', 'transpiling your tests...')
|
||||||
|
} else if (diagnostic.code === 6032) {
|
||||||
|
this.emit('message', 'file changes detected. Transpiling your tests...')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that there is another overload for `createWatchCompilerHost` that takes
|
||||||
|
// a set of root files.
|
||||||
|
this.host = ts.createWatchCompilerHost(
|
||||||
|
parsedTsConfig.fileNames,
|
||||||
|
{
|
||||||
|
...parsedTsConfig.options,
|
||||||
|
rootDir,
|
||||||
|
outDir: this.tempDir,
|
||||||
|
module: 'commonjs',
|
||||||
|
noEmit: false,
|
||||||
|
noResolve: true,
|
||||||
|
sourceMap: true
|
||||||
|
},
|
||||||
|
ts.sys,
|
||||||
|
createProgram,
|
||||||
|
reportDiagnostic,
|
||||||
|
reportWatchStatusChanged
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async start () {
|
||||||
|
await super.start()
|
||||||
|
// `createWatchProgram` creates an initial program, watches files, and updates
|
||||||
|
// the program over time.
|
||||||
|
this.watcher = ts.createWatchProgram(this.host)
|
||||||
|
return await this.ready()
|
||||||
|
}
|
||||||
|
|
||||||
|
async close () {
|
||||||
|
await super.close()
|
||||||
|
this.watcher.close()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
const chai = require('chai')
|
||||||
|
const rimraf = require('rimraf')
|
||||||
|
|
||||||
|
const RollupBuilder = require('./builders/RollupBuilder.js')
|
||||||
|
const TestsBuilder = require('./builders/TestsBuilder.js')
|
||||||
|
|
||||||
|
const rootDir = path.join(__dirname, '../../../')
|
||||||
|
|
||||||
|
global.chai = chai
|
||||||
|
|
||||||
|
const watch = process.argv.includes('--watch') || process.argv.includes('-w')
|
||||||
|
|
||||||
|
const tempDir = path.join(rootDir, '.mocha-ts')
|
||||||
|
|
||||||
|
const rollupBuilder = new RollupBuilder({ name: 'rollup', configPath: path.join(rootDir, 'build/rollup.config.js'), tempDir, watch })
|
||||||
|
const testBuilder = new TestsBuilder({ name: 'tsc', tempDir })
|
||||||
|
|
||||||
|
rollupBuilder.start() // This should be in exports.mochaGlobalSetup but mocha fails when not in watch mode (DIRT...)
|
||||||
|
testBuilder.start() // This should be in exports.mochaGlobalSetup but mocha fails when not in watch mode (DIRT...)
|
||||||
|
|
||||||
|
exports.mochaHooks = {
|
||||||
|
beforeAll: [
|
||||||
|
async function () {
|
||||||
|
// Just in case our module had been modified. Reload it when the tests are repeated (for mocha watch mode).
|
||||||
|
delete require.cache[require.resolve(rootDir)]
|
||||||
|
global._pkg = require(rootDir)
|
||||||
|
},
|
||||||
|
async function () {
|
||||||
|
this.timeout('120000')
|
||||||
|
await Promise.all([rollupBuilder.ready(), testBuilder.ready()])
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// exports.mochaGlobalSetup = async function () {
|
||||||
|
// await rollupBuilder.start()
|
||||||
|
// await testBuilder.start()
|
||||||
|
// }
|
||||||
|
|
||||||
|
exports.mochaGlobalTeardown = async function () {
|
||||||
|
await testBuilder.close()
|
||||||
|
await rollupBuilder.close()
|
||||||
|
|
||||||
|
// I use the sync version of rimraf precisely because it blocks the
|
||||||
|
// main thread and thus the mocha watcher, which otherwise would complain
|
||||||
|
// about files being deleted
|
||||||
|
rimraf.sync(tempDir, { disableGlob: true })
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import * as _pkgModule from '../..'
|
||||||
|
|
||||||
|
export as namespace _pkg
|
||||||
|
|
||||||
|
export = _pkgModule
|
|
@ -0,0 +1 @@
|
||||||
|
declare const IS_BROWSER: boolean
|
|
@ -0,0 +1 @@
|
||||||
|
function n(n){return n>=0?n:-n}function t(n){if(1n===(n=BigInt(n)))return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){let r=BigInt(n),i=BigInt(t);if(r<=0n||i<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,u=1n,o=1n,f=0n;for(;0n!==r;){const n=i/r,t=i%r,c=e-o*n,g=u-f*n;i=r,r=t,e=o,u=f,o=c,f=g}return{g:i,x:e,y:u}}function i(t,r){let i=BigInt(n(t)),e=BigInt(n(r));if(0n===i)return e;if(0n===e)return i;let u=0n;for(;0n===(1n&(i|e));)i>>=1n,e>>=1n,u++;for(;0n===(1n&i);)i>>=1n;do{for(;0n===(1n&e);)e>>=1n;if(i>e){const n=i;i=e,e=n}e-=i}while(0n!==e);return i<<u}function e(t,r){const e=BigInt(t),u=BigInt(r);return 0n===e&&0n===u?BigInt(0):n(e*u)/i(e,u)}function u(n,t){return n>=t?n:t}function o(n,t){return n>=t?t:n}function f(n,t){const r=BigInt(t);if(t<=0)return NaN;const i=BigInt(n)%r;return i<0n?i+r:i}function c(n,t){try{const i=r(f(n,t),t);return 1n!==i.g?NaN:f(i.x,t)}catch(n){return NaN}}function g(t,r,i){const e=BigInt(i);if(e<=0n)return NaN;if(1n===e)return BigInt(0);let u=f(t,e);if((r=BigInt(r))<0n)return c(g(u,n(r),e),e);let o=1n;for(;r>0;)r%2n===1n&&(o=o*u%e),r/=2n,u=u**2n%e;return o}export{n as abs,t as bitLength,r as eGcd,i as gcd,e as lcm,u as max,o as min,c as modInv,g as modPow,f as toZn};
|
|
@ -0,0 +1 @@
|
||||||
|
var bigintModArith=function(n){"use strict";function t(n){return n>=0?n:-n}function r(n,t){let r=BigInt(n),i=BigInt(t);if(r<=0n||i<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,o=1n,u=1n,f=0n;for(;0n!==r;){const n=i/r,t=i%r,c=e-u*n,g=o-f*n;i=r,r=t,e=u,o=f,u=c,f=g}return{g:i,x:e,y:o}}function i(n,r){let i=BigInt(t(n)),e=BigInt(t(r));if(0n===i)return e;if(0n===e)return i;let o=0n;for(;0n===(1n&(i|e));)i>>=1n,e>>=1n,o++;for(;0n===(1n&i);)i>>=1n;do{for(;0n===(1n&e);)e>>=1n;if(i>e){const n=i;i=e,e=n}e-=i}while(0n!==e);return i<<o}function e(n,t){const r=BigInt(t);if(t<=0)return NaN;const i=BigInt(n)%r;return i<0n?i+r:i}function o(n,t){try{const i=r(e(n,t),t);return 1n!==i.g?NaN:e(i.x,t)}catch(n){return NaN}}return n.abs=t,n.bitLength=function(n){if(1n===(n=BigInt(n)))return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.eGcd=r,n.gcd=i,n.lcm=function(n,r){const e=BigInt(n),o=BigInt(r);return 0n===e&&0n===o?BigInt(0):t(e*o)/i(e,o)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modInv=o,n.modPow=function n(r,i,u){const f=BigInt(u);if(f<=0n)return NaN;if(1n===f)return BigInt(0);let c=e(r,f);if((i=BigInt(i))<0n)return o(n(c,t(i),f),f);let g=1n;for(;i>0;)i%2n===1n&&(g=g*c%f),i/=2n,c=c**2n%f;return g},n.toZn=e,Object.defineProperty(n,"__esModule",{value:!0}),n}({});
|
|
@ -0,0 +1 @@
|
||||||
|
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).bigintModArith={})}(this,(function(n){"use strict";function t(n){return n>=0?n:-n}function e(n,t){let e=BigInt(n),r=BigInt(t);if(e<=0n||r<=0n)throw new RangeError("a and b MUST be > 0");let i=0n,o=1n,f=1n,u=0n;for(;0n!==e;){const n=r/e,t=r%e,c=i-f*n,g=o-u*n;r=e,e=t,i=f,o=u,f=c,u=g}return{g:r,x:i,y:o}}function r(n,e){let r=BigInt(t(n)),i=BigInt(t(e));if(0n===r)return i;if(0n===i)return r;let o=0n;for(;0n===(1n&(r|i));)r>>=1n,i>>=1n,o++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&i);)i>>=1n;if(r>i){const n=r;r=i,i=n}i-=r}while(0n!==i);return r<<o}function i(n,t){const e=BigInt(t);if(t<=0)return NaN;const r=BigInt(n)%e;return r<0n?r+e:r}function o(n,t){try{const r=e(i(n,t),t);return 1n!==r.g?NaN:i(r.x,t)}catch(n){return NaN}}n.abs=t,n.bitLength=function(n){if(1n===(n=BigInt(n)))return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.eGcd=e,n.gcd=r,n.lcm=function(n,e){const i=BigInt(n),o=BigInt(e);return 0n===i&&0n===o?BigInt(0):t(i*o)/r(i,o)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modInv=o,n.modPow=function n(e,r,f){const u=BigInt(f);if(u<=0n)return NaN;if(1n===u)return BigInt(0);let c=i(e,u);if((r=BigInt(r))<0n)return o(n(c,t(r),u),u);let g=1n;for(;r>0;)r%2n===1n&&(g=g*c%u),r/=2n,c=c**2n%u;return g},n.toZn=i,Object.defineProperty(n,"__esModule",{value:!0})}));
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Some common functions for modular arithmetic using native JS implementation of BigInt
|
||||||
|
*
|
||||||
|
* @packageDocumentation
|
||||||
|
*/
|
||||||
|
export { abs } from './ts/abs';
|
||||||
|
export { bitLength } from './ts/bitLength';
|
||||||
|
export { Egcd, eGcd } from './ts/egcd';
|
||||||
|
export { gcd } from './ts/gcd';
|
||||||
|
export { lcm } from './ts/lcm';
|
||||||
|
export { max } from './ts/max';
|
||||||
|
export { min } from './ts/min';
|
||||||
|
export { modInv } from './ts/modInv';
|
||||||
|
export { modPow } from './ts/modPow';
|
||||||
|
export { toZn } from './ts/toZn';
|
||||||
|
//# sourceMappingURL=index.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA"}
|
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
*
|
||||||
|
* @returns The absolute value of a
|
||||||
|
*/
|
||||||
|
export declare function abs(a: number | bigint): number | bigint;
|
||||||
|
//# sourceMappingURL=abs.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"abs.d.ts","sourceRoot":"","sources":["../../../../src/ts/abs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAEpD"}
|
|
@ -0,0 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Returns the bitlength of a number
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @returns The bit length
|
||||||
|
*/
|
||||||
|
export declare function bitLength(a: number | bigint): number;
|
||||||
|
//# sourceMappingURL=bitLength.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"bitLength.d.ts","sourceRoot":"","sources":["../../../../src/ts/bitLength.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CAQnD"}
|
|
@ -0,0 +1,16 @@
|
||||||
|
export interface Egcd {
|
||||||
|
g: bigint;
|
||||||
|
x: bigint;
|
||||||
|
y: bigint;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
|
||||||
|
* Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
||||||
|
*/
|
||||||
|
export declare function eGcd(a: number | bigint, b: number | bigint): Egcd;
|
||||||
|
//# sourceMappingURL=egcd.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"egcd.d.ts","sourceRoot":"","sources":["../../../../src/ts/egcd.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AACD;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,IAAI,CA2B9D"}
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Greatest-common divisor of two integers based on the iterative binary algorithm.
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns The greatest common divisor of a and b
|
||||||
|
*/
|
||||||
|
export declare function gcd(a: number | bigint, b: number | bigint): bigint;
|
||||||
|
//# sourceMappingURL=gcd.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"gcd.d.ts","sourceRoot":"","sources":["../../../../src/ts/gcd.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CAwB/D"}
|
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* The least common multiple computed as abs(a*b)/gcd(a,b)
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns The least common multiple of a and b
|
||||||
|
*/
|
||||||
|
export declare function lcm(a: number | bigint, b: number | bigint): bigint;
|
||||||
|
//# sourceMappingURL=lcm.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"lcm.d.ts","sourceRoot":"","sources":["../../../../src/ts/lcm.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CAK/D"}
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns Maximum of numbers a and b
|
||||||
|
*/
|
||||||
|
export declare function max(a: number | bigint, b: number | bigint): number | bigint;
|
||||||
|
//# sourceMappingURL=max.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"max.d.ts","sourceRoot":"","sources":["../../../../src/ts/max.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAEtE"}
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns Minimum of numbers a and b
|
||||||
|
*/
|
||||||
|
export declare function min(a: number | bigint, b: number | bigint): number | bigint;
|
||||||
|
//# sourceMappingURL=min.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"min.d.ts","sourceRoot":"","sources":["../../../../src/ts/min.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAEtE"}
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Modular inverse.
|
||||||
|
*
|
||||||
|
* @param a The number to find an inverse for
|
||||||
|
* @param n The modulo
|
||||||
|
*
|
||||||
|
* @returns The inverse modulo n or number NaN if it does not exist
|
||||||
|
*/
|
||||||
|
export declare function modInv(a: number | bigint, n: number | bigint): bigint | number;
|
||||||
|
//# sourceMappingURL=modInv.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"modInv.d.ts","sourceRoot":"","sources":["../../../../src/ts/modInv.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAWzE"}
|
|
@ -0,0 +1,11 @@
|
||||||
|
/**
|
||||||
|
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
||||||
|
*
|
||||||
|
* @param b base
|
||||||
|
* @param e exponent
|
||||||
|
* @param n modulo
|
||||||
|
*
|
||||||
|
* @returns b**e mod n or number NaN if n <= 0
|
||||||
|
*/
|
||||||
|
export declare function modPow(b: number | bigint, e: number | bigint, n: number | bigint): bigint | number;
|
||||||
|
//# sourceMappingURL=modPow.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"modPow.d.ts","sourceRoot":"","sources":["../../../../src/ts/modPow.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAoB3F"}
|
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* Finds the smallest positive element that is congruent to a in modulo n
|
||||||
|
* @param {number|bigint} a An integer
|
||||||
|
* @param {number|bigint} n The modulo
|
||||||
|
*
|
||||||
|
* @returns The smallest positive representation of a in modulo n or number NaN if n < 0
|
||||||
|
*/
|
||||||
|
export declare function toZn(a: number | bigint, n: number | bigint): bigint | number;
|
||||||
|
//# sourceMappingURL=toZn.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"toZn.d.ts","sourceRoot":"","sources":["../../../../src/ts/toZn.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAMvE"}
|
|
@ -0,0 +1,234 @@
|
||||||
|
bigint-mod-arith - v2.0.8
|
||||||
|
|
||||||
|
# bigint-mod-arith - v2.0.8
|
||||||
|
|
||||||
|
Some common functions for modular arithmetic using native JS implementation of BigInt
|
||||||
|
|
||||||
|
## Table of contents
|
||||||
|
|
||||||
|
### Interfaces
|
||||||
|
|
||||||
|
- [Egcd](interfaces/egcd.md)
|
||||||
|
|
||||||
|
### Functions
|
||||||
|
|
||||||
|
- [abs](API.md#abs)
|
||||||
|
- [bitLength](API.md#bitlength)
|
||||||
|
- [eGcd](API.md#egcd)
|
||||||
|
- [gcd](API.md#gcd)
|
||||||
|
- [lcm](API.md#lcm)
|
||||||
|
- [max](API.md#max)
|
||||||
|
- [min](API.md#min)
|
||||||
|
- [modInv](API.md#modinv)
|
||||||
|
- [modPow](API.md#modpow)
|
||||||
|
- [toZn](API.md#tozn)
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
### abs
|
||||||
|
|
||||||
|
▸ **abs**(`a`: *number* \| *bigint*): *number* \| *bigint*
|
||||||
|
|
||||||
|
Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type |
|
||||||
|
:------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* |
|
||||||
|
|
||||||
|
**Returns:** *number* \| *bigint*
|
||||||
|
|
||||||
|
The absolute value of a
|
||||||
|
|
||||||
|
Defined in: ts/abs.ts:8
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### bitLength
|
||||||
|
|
||||||
|
▸ **bitLength**(`a`: *number* \| *bigint*): *number*
|
||||||
|
|
||||||
|
Returns the bitlength of a number
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type |
|
||||||
|
:------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* |
|
||||||
|
|
||||||
|
**Returns:** *number*
|
||||||
|
|
||||||
|
The bit length
|
||||||
|
|
||||||
|
Defined in: ts/bitLength.ts:7
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### eGcd
|
||||||
|
|
||||||
|
▸ **eGcd**(`a`: *number* \| *bigint*, `b`: *number* \| *bigint*): [*Egcd*](interfaces/egcd.md)
|
||||||
|
|
||||||
|
An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
|
||||||
|
Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type |
|
||||||
|
:------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* |
|
||||||
|
`b` | *number* \| *bigint* |
|
||||||
|
|
||||||
|
**Returns:** [*Egcd*](interfaces/egcd.md)
|
||||||
|
|
||||||
|
A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
||||||
|
|
||||||
|
Defined in: ts/egcd.ts:15
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### gcd
|
||||||
|
|
||||||
|
▸ **gcd**(`a`: *number* \| *bigint*, `b`: *number* \| *bigint*): *bigint*
|
||||||
|
|
||||||
|
Greatest-common divisor of two integers based on the iterative binary algorithm.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type |
|
||||||
|
:------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* |
|
||||||
|
`b` | *number* \| *bigint* |
|
||||||
|
|
||||||
|
**Returns:** *bigint*
|
||||||
|
|
||||||
|
The greatest common divisor of a and b
|
||||||
|
|
||||||
|
Defined in: ts/gcd.ts:10
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### lcm
|
||||||
|
|
||||||
|
▸ **lcm**(`a`: *number* \| *bigint*, `b`: *number* \| *bigint*): *bigint*
|
||||||
|
|
||||||
|
The least common multiple computed as abs(a*b)/gcd(a,b)
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type |
|
||||||
|
:------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* |
|
||||||
|
`b` | *number* \| *bigint* |
|
||||||
|
|
||||||
|
**Returns:** *bigint*
|
||||||
|
|
||||||
|
The least common multiple of a and b
|
||||||
|
|
||||||
|
Defined in: ts/lcm.ts:10
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### max
|
||||||
|
|
||||||
|
▸ **max**(`a`: *number* \| *bigint*, `b`: *number* \| *bigint*): *number* \| *bigint*
|
||||||
|
|
||||||
|
Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type |
|
||||||
|
:------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* |
|
||||||
|
`b` | *number* \| *bigint* |
|
||||||
|
|
||||||
|
**Returns:** *number* \| *bigint*
|
||||||
|
|
||||||
|
Maximum of numbers a and b
|
||||||
|
|
||||||
|
Defined in: ts/max.ts:9
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### min
|
||||||
|
|
||||||
|
▸ **min**(`a`: *number* \| *bigint*, `b`: *number* \| *bigint*): *number* \| *bigint*
|
||||||
|
|
||||||
|
Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type |
|
||||||
|
:------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* |
|
||||||
|
`b` | *number* \| *bigint* |
|
||||||
|
|
||||||
|
**Returns:** *number* \| *bigint*
|
||||||
|
|
||||||
|
Minimum of numbers a and b
|
||||||
|
|
||||||
|
Defined in: ts/min.ts:9
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### modInv
|
||||||
|
|
||||||
|
▸ **modInv**(`a`: *number* \| *bigint*, `n`: *number* \| *bigint*): *bigint* \| *number*
|
||||||
|
|
||||||
|
Modular inverse.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type | Description |
|
||||||
|
:------ | :------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* | The number to find an inverse for |
|
||||||
|
`n` | *number* \| *bigint* | The modulo |
|
||||||
|
|
||||||
|
**Returns:** *bigint* \| *number*
|
||||||
|
|
||||||
|
The inverse modulo n or number NaN if it does not exist
|
||||||
|
|
||||||
|
Defined in: ts/modInv.ts:11
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### modPow
|
||||||
|
|
||||||
|
▸ **modPow**(`b`: *number* \| *bigint*, `e`: *number* \| *bigint*, `n`: *number* \| *bigint*): *bigint* \| *number*
|
||||||
|
|
||||||
|
Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type | Description |
|
||||||
|
:------ | :------ | :------ |
|
||||||
|
`b` | *number* \| *bigint* | base |
|
||||||
|
`e` | *number* \| *bigint* | exponent |
|
||||||
|
`n` | *number* \| *bigint* | modulo |
|
||||||
|
|
||||||
|
**Returns:** *bigint* \| *number*
|
||||||
|
|
||||||
|
b**e mod n or number NaN if n <= 0
|
||||||
|
|
||||||
|
Defined in: ts/modPow.ts:13
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### toZn
|
||||||
|
|
||||||
|
▸ **toZn**(`a`: *number* \| *bigint*, `n`: *number* \| *bigint*): *bigint* \| *number*
|
||||||
|
|
||||||
|
Finds the smallest positive element that is congruent to a in modulo n
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
|
||||||
|
Name | Type | Description |
|
||||||
|
:------ | :------ | :------ |
|
||||||
|
`a` | *number* \| *bigint* | An integer |
|
||||||
|
`n` | *number* \| *bigint* | The modulo |
|
||||||
|
|
||||||
|
**Returns:** *bigint* \| *number*
|
||||||
|
|
||||||
|
The smallest positive representation of a in modulo n or number NaN if n < 0
|
||||||
|
|
||||||
|
Defined in: ts/toZn.ts:8
|
|
@ -0,0 +1,35 @@
|
||||||
|
[bigint-mod-arith - v2.0.8](../API.md) / Egcd
|
||||||
|
|
||||||
|
# Interface: Egcd
|
||||||
|
|
||||||
|
## Table of contents
|
||||||
|
|
||||||
|
### Properties
|
||||||
|
|
||||||
|
- [g](egcd.md#g)
|
||||||
|
- [x](egcd.md#x)
|
||||||
|
- [y](egcd.md#y)
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### g
|
||||||
|
|
||||||
|
• **g**: *bigint*
|
||||||
|
|
||||||
|
Defined in: ts/egcd.ts:2
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### x
|
||||||
|
|
||||||
|
• **x**: *bigint*
|
||||||
|
|
||||||
|
Defined in: ts/egcd.ts:3
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### y
|
||||||
|
|
||||||
|
• **y**: *bigint*
|
||||||
|
|
||||||
|
Defined in: ts/egcd.ts:4
|
|
@ -1 +0,0 @@
|
||||||
var bigintModArith=function(n){"use strict";function t(n){return(n=BigInt(n))>=0n?n:-n}function r(n,t){if((n=BigInt(n))<=0n|(t=BigInt(t))<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,i=1n,e=1n,u=0n;for(;0n!==n;){const o=t/n,f=t%n,g=r-e*o,c=i-u*o;t=n,n=f,r=e,i=u,e=g,u=c}return{g:t,x:r,y:i}}function i(n,r){if(n=t(n),r=t(r),0n===n)return r;if(0n===r)return n;let i=0n;for(;!(1n&(n|r));)n>>=1n,r>>=1n,i++;for(;!(1n&n);)n>>=1n;do{for(;!(1n&r);)r>>=1n;if(n>r){const t=n;n=r,r=t}r-=n}while(r);return n<<i}function e(n,t){try{const i=r(u(n,t),t);return 1n!==i.g?NaN:u(i.x,t)}catch(n){return NaN}}function u(n,t){return(t=BigInt(t))<=0?NaN:(n=BigInt(n)%t)<0?n+t:n}return n.abs=t,n.bitLength=function(n){if(1n===(n=BigInt(n)))return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.eGcd=r,n.gcd=i,n.lcm=function(n,r){return n=BigInt(n),r=BigInt(r),0n===n&&0n===r?BigInt(0):t(n*r)/i(n,r)},n.max=function(n,t){return(n=BigInt(n))>=(t=BigInt(t))?n:t},n.min=function(n,t){return(n=BigInt(n))>=(t=BigInt(t))?t:n},n.modInv=e,n.modPow=function n(r,i,o){if(0n===(o=BigInt(o)))return NaN;if(1n===o)return BigInt(0);if(r=u(r,o),(i=BigInt(i))<0n)return e(n(r,t(i),o),o);let f=1n;for(;i>0;)i%2n===1n&&(f=f*r%o),i/=2n,r=r**2n%o;return f},n.toZn=u,n}({});
|
|
|
@ -1 +0,0 @@
|
||||||
function n(n){return(n=BigInt(n))>=0n?n:-n}function t(n){if(1n===(n=BigInt(n)))return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if((n=BigInt(n))<=0n|(t=BigInt(t))<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,i=1n,e=1n,u=0n;for(;0n!==n;){const f=t/n,o=t%n,g=r-e*f,B=i-u*f;t=n,n=o,r=e,i=u,e=g,u=B}return{g:t,x:r,y:i}}function i(t,r){if(t=n(t),r=n(r),0n===t)return r;if(0n===r)return t;let i=0n;for(;!(1n&(t|r));)t>>=1n,r>>=1n,i++;for(;!(1n&t);)t>>=1n;do{for(;!(1n&r);)r>>=1n;if(t>r){const n=t;t=r,r=n}r-=t}while(r);return t<<i}function e(t,r){return t=BigInt(t),r=BigInt(r),0n===t&&0n===r?BigInt(0):n(t*r)/i(t,r)}function u(n,t){return(n=BigInt(n))>=(t=BigInt(t))?n:t}function f(n,t){return(n=BigInt(n))>=(t=BigInt(t))?t:n}function o(n,t){try{const i=r(B(n,t),t);return 1n!==i.g?NaN:B(i.x,t)}catch(n){return NaN}}function g(t,r,i){if(0n===(i=BigInt(i)))return NaN;if(1n===i)return BigInt(0);if(t=B(t,i),(r=BigInt(r))<0n)return o(g(t,n(r),i),i);let e=1n;for(;r>0;)r%2n===1n&&(e=e*t%i),r/=2n,t=t**2n%i;return e}function B(n,t){return(t=BigInt(t))<=0?NaN:(n=BigInt(n)%t)<0?n+t:n}export{n as abs,t as bitLength,r as eGcd,i as gcd,e as lcm,u as max,f as min,o as modInv,g as modPow,B as toZn};
|
|
|
@ -1,221 +0,0 @@
|
||||||
/**
|
|
||||||
* Some common functions for modular arithmetic using native JS implementation of BigInt
|
|
||||||
* @module bigint-mod-arith
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
*
|
|
||||||
* @returns {bigint} the absolute value of a
|
|
||||||
*/
|
|
||||||
function abs (a) {
|
|
||||||
a = BigInt(a)
|
|
||||||
return (a >= 0n) ? a : -a
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the bitlength of a number
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @returns {number} - the bit length
|
|
||||||
*/
|
|
||||||
function bitLength (a) {
|
|
||||||
a = BigInt(a)
|
|
||||||
if (a === 1n) { return 1 }
|
|
||||||
let bits = 1
|
|
||||||
do {
|
|
||||||
bits++
|
|
||||||
} while ((a >>= 1n) > 1n)
|
|
||||||
return bits
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} egcdReturn A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
* @property {bigint} g
|
|
||||||
* @property {bigint} x
|
|
||||||
* @property {bigint} y
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
|
|
||||||
* Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {egcdReturn} A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*/
|
|
||||||
function eGcd (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
if (a <= 0n | b <= 0n) throw new RangeError('a and b MUST be > 0') // a and b MUST be positive
|
|
||||||
|
|
||||||
let x = 0n
|
|
||||||
let y = 1n
|
|
||||||
let u = 1n
|
|
||||||
let v = 0n
|
|
||||||
|
|
||||||
while (a !== 0n) {
|
|
||||||
const q = b / a
|
|
||||||
const r = b % a
|
|
||||||
const m = x - (u * q)
|
|
||||||
const n = y - (v * q)
|
|
||||||
b = a
|
|
||||||
a = r
|
|
||||||
x = u
|
|
||||||
y = v
|
|
||||||
u = m
|
|
||||||
v = n
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
g: b,
|
|
||||||
x: x,
|
|
||||||
y: y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Greatest-common divisor of two integers based on the iterative binary algorithm.
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} The greatest common divisor of a and b
|
|
||||||
*/
|
|
||||||
function gcd (a, b) {
|
|
||||||
a = abs(a)
|
|
||||||
b = abs(b)
|
|
||||||
if (a === 0n) { return b } else if (b === 0n) { return a }
|
|
||||||
|
|
||||||
let shift = 0n
|
|
||||||
while (!((a | b) & 1n)) {
|
|
||||||
a >>= 1n
|
|
||||||
b >>= 1n
|
|
||||||
shift++
|
|
||||||
}
|
|
||||||
while (!(a & 1n)) a >>= 1n
|
|
||||||
do {
|
|
||||||
while (!(b & 1n)) b >>= 1n
|
|
||||||
if (a > b) {
|
|
||||||
const x = a
|
|
||||||
a = b
|
|
||||||
b = x
|
|
||||||
}
|
|
||||||
b -= a
|
|
||||||
} while (b)
|
|
||||||
|
|
||||||
// rescale
|
|
||||||
return a << shift
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The least common multiple computed as abs(a*b)/gcd(a,b)
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} The least common multiple of a and b
|
|
||||||
*/
|
|
||||||
function lcm (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
if (a === 0n && b === 0n) return BigInt(0)
|
|
||||||
return abs(a * b) / gcd(a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} maximum of numbers a and b
|
|
||||||
*/
|
|
||||||
function max (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
return (a >= b) ? a : b
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} minimum of numbers a and b
|
|
||||||
*/
|
|
||||||
function min (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
return (a >= b) ? b : a
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modular inverse.
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a The number to find an inverse for
|
|
||||||
* @param {number|bigint} n The modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint|NaN} the inverse modulo n or NaN if it does not exist
|
|
||||||
*/
|
|
||||||
function modInv (a, n) {
|
|
||||||
try {
|
|
||||||
const egcd = eGcd(toZn(a, n), n)
|
|
||||||
if (egcd.g !== 1n) {
|
|
||||||
return NaN // modular inverse does not exist
|
|
||||||
} else {
|
|
||||||
return toZn(egcd.x, n)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return NaN
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
|
||||||
*
|
|
||||||
* @param {number|bigint} b base
|
|
||||||
* @param {number|bigint} e exponent
|
|
||||||
* @param {number|bigint} n modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint} b**e mod n
|
|
||||||
*/
|
|
||||||
function modPow (b, e, n) {
|
|
||||||
n = BigInt(n)
|
|
||||||
if (n === 0n) { return NaN } else if (n === 1n) { return BigInt(0) }
|
|
||||||
|
|
||||||
b = toZn(b, n)
|
|
||||||
|
|
||||||
e = BigInt(e)
|
|
||||||
if (e < 0n) {
|
|
||||||
return modInv(modPow(b, abs(e), n), n)
|
|
||||||
}
|
|
||||||
|
|
||||||
let r = 1n
|
|
||||||
while (e > 0) {
|
|
||||||
if ((e % 2n) === 1n) {
|
|
||||||
r = (r * b) % n
|
|
||||||
}
|
|
||||||
e = e / 2n
|
|
||||||
b = b ** 2n % n
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the smallest positive element that is congruent to a in modulo n
|
|
||||||
* @param {number|bigint} a An integer
|
|
||||||
* @param {number|bigint} n The modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint} The smallest positive representation of a in modulo n
|
|
||||||
*/
|
|
||||||
function toZn (a, n) {
|
|
||||||
n = BigInt(n)
|
|
||||||
if (n <= 0) { return NaN }
|
|
||||||
|
|
||||||
a = BigInt(a) % n
|
|
||||||
return (a < 0) ? a + n : a
|
|
||||||
}
|
|
||||||
|
|
||||||
export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn }
|
|
|
@ -1,234 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
Object.defineProperty(exports, '__esModule', { value: true })
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Some common functions for modular arithmetic using native JS implementation of BigInt
|
|
||||||
* @module bigint-mod-arith
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
*
|
|
||||||
* @returns {bigint} the absolute value of a
|
|
||||||
*/
|
|
||||||
function abs (a) {
|
|
||||||
a = BigInt(a)
|
|
||||||
return (a >= 0n) ? a : -a
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the bitlength of a number
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @returns {number} - the bit length
|
|
||||||
*/
|
|
||||||
function bitLength (a) {
|
|
||||||
a = BigInt(a)
|
|
||||||
if (a === 1n) { return 1 }
|
|
||||||
let bits = 1
|
|
||||||
do {
|
|
||||||
bits++
|
|
||||||
} while ((a >>= 1n) > 1n)
|
|
||||||
return bits
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} egcdReturn A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
* @property {bigint} g
|
|
||||||
* @property {bigint} x
|
|
||||||
* @property {bigint} y
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
|
|
||||||
* Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {egcdReturn} A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*/
|
|
||||||
function eGcd (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
if (a <= 0n | b <= 0n) throw new RangeError('a and b MUST be > 0') // a and b MUST be positive
|
|
||||||
|
|
||||||
let x = 0n
|
|
||||||
let y = 1n
|
|
||||||
let u = 1n
|
|
||||||
let v = 0n
|
|
||||||
|
|
||||||
while (a !== 0n) {
|
|
||||||
const q = b / a
|
|
||||||
const r = b % a
|
|
||||||
const m = x - (u * q)
|
|
||||||
const n = y - (v * q)
|
|
||||||
b = a
|
|
||||||
a = r
|
|
||||||
x = u
|
|
||||||
y = v
|
|
||||||
u = m
|
|
||||||
v = n
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
g: b,
|
|
||||||
x: x,
|
|
||||||
y: y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Greatest-common divisor of two integers based on the iterative binary algorithm.
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} The greatest common divisor of a and b
|
|
||||||
*/
|
|
||||||
function gcd (a, b) {
|
|
||||||
a = abs(a)
|
|
||||||
b = abs(b)
|
|
||||||
if (a === 0n) { return b } else if (b === 0n) { return a }
|
|
||||||
|
|
||||||
let shift = 0n
|
|
||||||
while (!((a | b) & 1n)) {
|
|
||||||
a >>= 1n
|
|
||||||
b >>= 1n
|
|
||||||
shift++
|
|
||||||
}
|
|
||||||
while (!(a & 1n)) a >>= 1n
|
|
||||||
do {
|
|
||||||
while (!(b & 1n)) b >>= 1n
|
|
||||||
if (a > b) {
|
|
||||||
const x = a
|
|
||||||
a = b
|
|
||||||
b = x
|
|
||||||
}
|
|
||||||
b -= a
|
|
||||||
} while (b)
|
|
||||||
|
|
||||||
// rescale
|
|
||||||
return a << shift
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The least common multiple computed as abs(a*b)/gcd(a,b)
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} The least common multiple of a and b
|
|
||||||
*/
|
|
||||||
function lcm (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
if (a === 0n && b === 0n) return BigInt(0)
|
|
||||||
return abs(a * b) / gcd(a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} maximum of numbers a and b
|
|
||||||
*/
|
|
||||||
function max (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
return (a >= b) ? a : b
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} minimum of numbers a and b
|
|
||||||
*/
|
|
||||||
function min (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
return (a >= b) ? b : a
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modular inverse.
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a The number to find an inverse for
|
|
||||||
* @param {number|bigint} n The modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint|NaN} the inverse modulo n or NaN if it does not exist
|
|
||||||
*/
|
|
||||||
function modInv (a, n) {
|
|
||||||
try {
|
|
||||||
const egcd = eGcd(toZn(a, n), n)
|
|
||||||
if (egcd.g !== 1n) {
|
|
||||||
return NaN // modular inverse does not exist
|
|
||||||
} else {
|
|
||||||
return toZn(egcd.x, n)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return NaN
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
|
||||||
*
|
|
||||||
* @param {number|bigint} b base
|
|
||||||
* @param {number|bigint} e exponent
|
|
||||||
* @param {number|bigint} n modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint} b**e mod n
|
|
||||||
*/
|
|
||||||
function modPow (b, e, n) {
|
|
||||||
n = BigInt(n)
|
|
||||||
if (n === 0n) { return NaN } else if (n === 1n) { return BigInt(0) }
|
|
||||||
|
|
||||||
b = toZn(b, n)
|
|
||||||
|
|
||||||
e = BigInt(e)
|
|
||||||
if (e < 0n) {
|
|
||||||
return modInv(modPow(b, abs(e), n), n)
|
|
||||||
}
|
|
||||||
|
|
||||||
let r = 1n
|
|
||||||
while (e > 0) {
|
|
||||||
if ((e % 2n) === 1n) {
|
|
||||||
r = (r * b) % n
|
|
||||||
}
|
|
||||||
e = e / 2n
|
|
||||||
b = b ** 2n % n
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the smallest positive element that is congruent to a in modulo n
|
|
||||||
* @param {number|bigint} a An integer
|
|
||||||
* @param {number|bigint} n The modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint} The smallest positive representation of a in modulo n
|
|
||||||
*/
|
|
||||||
function toZn (a, n) {
|
|
||||||
n = BigInt(n)
|
|
||||||
if (n <= 0) { return NaN }
|
|
||||||
|
|
||||||
a = BigInt(a) % n
|
|
||||||
return (a < 0) ? a + n : a
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.abs = abs
|
|
||||||
exports.bitLength = bitLength
|
|
||||||
exports.eGcd = eGcd
|
|
||||||
exports.gcd = gcd
|
|
||||||
exports.lcm = lcm
|
|
||||||
exports.max = max
|
|
||||||
exports.min = min
|
|
||||||
exports.modInv = modInv
|
|
||||||
exports.modPow = modPow
|
|
||||||
exports.toZn = toZn
|
|
File diff suppressed because it is too large
Load Diff
104
package.json
104
package.json
|
@ -20,57 +20,85 @@
|
||||||
"url": "https://github.com/juanelas"
|
"url": "https://github.com/juanelas"
|
||||||
},
|
},
|
||||||
"repository": "github:juanelas/bigint-mod-arith",
|
"repository": "github:juanelas/bigint-mod-arith",
|
||||||
"main": "./lib/index.node.js",
|
|
||||||
"browser": "./lib/index.browser.mod.js",
|
|
||||||
"types": "./types/index.d.ts",
|
|
||||||
"directories": {
|
|
||||||
"build": "./build",
|
|
||||||
"lib": "./lib",
|
|
||||||
"src": "./src",
|
|
||||||
"test": "./test",
|
|
||||||
"types": "./types"
|
|
||||||
},
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.4.0"
|
"node": ">=10.4.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"types": "./dist/esm/types/index.d.ts",
|
||||||
"test": "nyc --check-coverage mocha",
|
"main": "./dist/cjs/index.node.cjs",
|
||||||
"coverage": "nyc report --reporter=lcov",
|
"browser": "./dist/esm/index.browser.js",
|
||||||
"build:js": "rollup -c build/rollup.config.js",
|
"module": "./dist/esm/index.node.js",
|
||||||
"build:standard": "standard --fix",
|
"exports": {
|
||||||
"build:browserTests": "rollup -c build/rollup.tests.config.js",
|
".": {
|
||||||
"build:docs": "node build/build.docs.js",
|
"node": {
|
||||||
"build:dts": "node build/build.dts.js",
|
"require": "./dist/cjs/index.node.cjs",
|
||||||
"build": "run-s build:**",
|
"import": "./dist/esm/index.node.js"
|
||||||
"preversion": "npm run build && npm run test",
|
|
||||||
"postversion": "git push"
|
|
||||||
},
|
},
|
||||||
"standard": {
|
"default": "./dist/esm/index.browser.js"
|
||||||
|
},
|
||||||
|
"./bundles/": "./dist/bundles/",
|
||||||
|
"./types/": "./dist/esm/types/"
|
||||||
|
},
|
||||||
|
"directories": {
|
||||||
|
"build": "./build",
|
||||||
|
"dist": "./dist",
|
||||||
|
"docs": "./docs",
|
||||||
|
"src": "./src",
|
||||||
|
"test": "./test"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "run-s lint build:js docs test:browser coverage",
|
||||||
|
"build:js": "rollup -c build/rollup.config.js",
|
||||||
|
"clean": "rimraf .nyc_output .mocha-ts coverage dist docs",
|
||||||
|
"coverage": "nyc --check-coverage --exclude build --exclude '{src/**/*.spec.ts,test/**/*.ts}' --reporter=text --reporter=lcov node ./build/bin/mocha-ts.js --require build/testing/mocha/mocha-init.js '{src/**/*.spec.ts,test/**/*.ts}'",
|
||||||
|
"docs": "node build/build.docs.js",
|
||||||
|
"lint": "ts-standard --fix",
|
||||||
|
"mocha": "node ./build/bin/mocha-ts.js --require build/testing/mocha/mocha-init.js ",
|
||||||
|
"preversion": "npm run build",
|
||||||
|
"test": "run-s test:browser test:node",
|
||||||
|
"test:browser": "node build/testing/browser/index.js",
|
||||||
|
"test:node": "npm run mocha -- '{src/**/*.spec.ts,test/**/*.ts}'",
|
||||||
|
"watch": "npm run mocha -- --watch '{src/**/*.spec.ts,test/**/*.ts}'"
|
||||||
|
},
|
||||||
|
"ts-standard": {
|
||||||
"env": [
|
"env": [
|
||||||
"mocha"
|
"mocha"
|
||||||
],
|
],
|
||||||
"globals": [
|
"globals": [
|
||||||
"BigInt"
|
"IS_BROWSER",
|
||||||
|
"browser",
|
||||||
|
"page",
|
||||||
|
"_pkg",
|
||||||
|
"chai"
|
||||||
],
|
],
|
||||||
|
"project": "./tsconfig.json",
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"/test/browser/",
|
"dist/**/*"
|
||||||
"/lib/index.browser.bundle.iife.js",
|
|
||||||
"/lib/index.browser.bundle.mod.js"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^11.1.0",
|
"@rollup/plugin-commonjs": "^17.0.0",
|
||||||
"@rollup/plugin-multi-entry": "^3.0.0",
|
"@rollup/plugin-multi-entry": "^4.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^7.1.3",
|
"@rollup/plugin-node-resolve": "^11.2.0",
|
||||||
"@rollup/plugin-replace": "^2.3.1",
|
"@rollup/plugin-replace": "^2.4.1",
|
||||||
"chai": "^4.2.0",
|
"@rollup/plugin-typescript": "^8.2.0",
|
||||||
"jsdoc-to-markdown": "^5.0.3",
|
"@types/chai": "^4.2.14",
|
||||||
"mocha": "^7.1.1",
|
"@types/mocha": "^8.2.1",
|
||||||
|
"chai": "^4.3.3",
|
||||||
|
"glob": "^7.1.6",
|
||||||
|
"json5": "^2.2.0",
|
||||||
|
"minimatch": "^3.0.4",
|
||||||
|
"mocha": "^8.3.0",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"nyc": "^15.0.1",
|
"nyc": "^15.1.0",
|
||||||
"rollup": "^2.6.1",
|
"pirates": "^4.0.1",
|
||||||
"rollup-plugin-terser": "^5.3.0",
|
"puppeteer": "^8.0.0",
|
||||||
"standard": "^14.3.3",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"rollup": "^2.40.0",
|
||||||
|
"rollup-plugin-terser": "^7.0.2",
|
||||||
|
"ts-standard": "^10.0.0",
|
||||||
|
"tslib": "^2.1.0",
|
||||||
|
"typedoc": "^0.20.29",
|
||||||
|
"typedoc-plugin-markdown": "^3.6.0",
|
||||||
|
"typescript": "^4.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>{{PKG_NAME}} - Mocha Tests</title>
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/{{MOCHA_VERSION}}/mocha.min.css">
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/{{MOCHA_VERSION}}/mocha.min.js"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/{{CHAI_VERSION}}/chai.min.js"></script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div id="mocha"></div>
|
|
||||||
<script>mocha.setup('bdd'); mocha.setup({ timeout: 90000 });</script>
|
|
||||||
{{TESTS}}
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
|
@ -8,57 +8,33 @@ Some extra functions to work with modular arithmetic using native JS ([ES-2020](
|
||||||
|
|
||||||
> The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html).
|
> The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html).
|
||||||
|
|
||||||
## Installation
|
## Usage
|
||||||
|
|
||||||
{{PKG_NAME}} is distributed for [web browsers and/or webviews supporting BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) as an ES6 module or an IIFE file; and for Node.js (>=10.4.0), as a CJS module.
|
`{{PKG_NAME}}` can be imported to your project with `npm`:
|
||||||
|
|
||||||
{{PKG_NAME}} can be imported to your project with `npm`:
|
```console
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install {{PKG_NAME}}
|
npm install {{PKG_NAME}}
|
||||||
```
|
```
|
||||||
|
|
||||||
NPM installation defaults to the ES6 module for browsers and the CJS one for Node.js. For web browsers, you can also directly download the {{IIFE_BUNDLE}} or the {{ESM_BUNDLE}} from the repository.
|
Then either require (Node.js CJS):
|
||||||
|
|
||||||
|
|
||||||
## Usage example
|
|
||||||
|
|
||||||
Import your module as :
|
|
||||||
|
|
||||||
- Node.js
|
|
||||||
```javascript
|
```javascript
|
||||||
const {{PKG_CAMELCASE}} = require('{{PKG_NAME}}')
|
const {{PKG_CAMELCASE}} = require('{{PKG_NAME}}')
|
||||||
... // your code here
|
|
||||||
```
|
```
|
||||||
- JavaScript native or TypeScript project (including React and Angular)
|
|
||||||
|
or import (JavaScript ES module):
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import * as {{PKG_CAMELCASE}} from '{{PKG_NAME}}'
|
import * as {{PKG_CAMELCASE}} from '{{PKG_NAME}}'
|
||||||
... // your code here
|
|
||||||
```
|
|
||||||
- JavaScript native browser ES module
|
|
||||||
```html
|
|
||||||
<script type="module">
|
|
||||||
import * as {{PKG_CAMELCASE}} from 'lib/index.browser.bundle.mod.js' // Use you actual path to the broser mod bundle
|
|
||||||
... // your code here
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
- JavaScript native browser IIFE
|
|
||||||
```html
|
|
||||||
<head>
|
|
||||||
...
|
|
||||||
<script src="../../lib/index.browser.bundle.iife.js"></script> <!-- Use you actual path to the browser bundle -->
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
...
|
|
||||||
<script>
|
|
||||||
... // your code here
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The appropriate version for browser or node is automatically exported.
|
||||||
|
|
||||||
|
You can also download the {{IIFE_BUNDLE}}, the {{ESM_BUNDLE}} or the {{UMD_BUNDLE}} and manually add it to your project, or, if you have already imported `{{PKG_NAME}}` to your project, just get the bundles from `node_modules/{{PKG_NAME}}/dist/bundles/`.
|
||||||
|
|
||||||
An example of usage could be:
|
An example of usage could be:
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
/* Stage 3 BigInts with value 666 can be declared as BigInt('666')
|
/* Stage 3 BigInts with value 666 can be declared as BigInt('666')
|
||||||
or the shorter syntax 666n.
|
or the shorter syntax 666n.
|
||||||
Notice that you can also pass a number, e.g. BigInt(666), but it is not
|
Notice that you can also pass a number, e.g. BigInt(666), but it is not
|
||||||
|
@ -74,9 +50,8 @@ console.log(bigintModArith.modPow(a, b, n)) // prints 6
|
||||||
console.log(bigintModArith.modInv(2n, 5n)) // prints 3
|
console.log(bigintModArith.modInv(2n, 5n)) // prints 3
|
||||||
|
|
||||||
console.log(bigintModArith.modInv(BigInt('3'), BigInt('5'))) // prints 2
|
console.log(bigintModArith.modInv(BigInt('3'), BigInt('5'))) // prints 2
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## API reference documentation
|
## API reference documentation
|
||||||
|
|
||||||
{{>main}}
|
[Check the API](./docs/API.md)
|
|
@ -0,0 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Some common functions for modular arithmetic using native JS implementation of BigInt
|
||||||
|
*
|
||||||
|
* @packageDocumentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
export { abs } from './ts/abs'
|
||||||
|
export { bitLength } from './ts/bitLength'
|
||||||
|
export { Egcd, eGcd } from './ts/egcd'
|
||||||
|
export { gcd } from './ts/gcd'
|
||||||
|
export { lcm } from './ts/lcm'
|
||||||
|
export { max } from './ts/max'
|
||||||
|
export { min } from './ts/min'
|
||||||
|
export { modInv } from './ts/modInv'
|
||||||
|
export { modPow } from './ts/modPow'
|
||||||
|
export { toZn } from './ts/toZn'
|
219
src/js/index.js
219
src/js/index.js
|
@ -1,219 +0,0 @@
|
||||||
/**
|
|
||||||
* Some common functions for modular arithmetic using native JS implementation of BigInt
|
|
||||||
* @module bigint-mod-arith
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
*
|
|
||||||
* @returns {bigint} the absolute value of a
|
|
||||||
*/
|
|
||||||
export function abs (a) {
|
|
||||||
a = BigInt(a)
|
|
||||||
return (a >= 0n) ? a : -a
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the bitlength of a number
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @returns {number} - the bit length
|
|
||||||
*/
|
|
||||||
export function bitLength (a) {
|
|
||||||
a = BigInt(a)
|
|
||||||
if (a === 1n) { return 1 }
|
|
||||||
let bits = 1
|
|
||||||
do {
|
|
||||||
bits++
|
|
||||||
} while ((a >>= 1n) > 1n)
|
|
||||||
return bits
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} egcdReturn A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
* @property {bigint} g
|
|
||||||
* @property {bigint} x
|
|
||||||
* @property {bigint} y
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
|
|
||||||
* Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {egcdReturn} A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*/
|
|
||||||
export function eGcd (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
if (a <= 0n | b <= 0n) throw new RangeError('a and b MUST be > 0') // a and b MUST be positive
|
|
||||||
|
|
||||||
let x = 0n
|
|
||||||
let y = 1n
|
|
||||||
let u = 1n
|
|
||||||
let v = 0n
|
|
||||||
|
|
||||||
while (a !== 0n) {
|
|
||||||
const q = b / a
|
|
||||||
const r = b % a
|
|
||||||
const m = x - (u * q)
|
|
||||||
const n = y - (v * q)
|
|
||||||
b = a
|
|
||||||
a = r
|
|
||||||
x = u
|
|
||||||
y = v
|
|
||||||
u = m
|
|
||||||
v = n
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
g: b,
|
|
||||||
x: x,
|
|
||||||
y: y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Greatest-common divisor of two integers based on the iterative binary algorithm.
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} The greatest common divisor of a and b
|
|
||||||
*/
|
|
||||||
export function gcd (a, b) {
|
|
||||||
a = abs(a)
|
|
||||||
b = abs(b)
|
|
||||||
if (a === 0n) { return b } else if (b === 0n) { return a }
|
|
||||||
|
|
||||||
let shift = 0n
|
|
||||||
while (!((a | b) & 1n)) {
|
|
||||||
a >>= 1n
|
|
||||||
b >>= 1n
|
|
||||||
shift++
|
|
||||||
}
|
|
||||||
while (!(a & 1n)) a >>= 1n
|
|
||||||
do {
|
|
||||||
while (!(b & 1n)) b >>= 1n
|
|
||||||
if (a > b) {
|
|
||||||
const x = a
|
|
||||||
a = b
|
|
||||||
b = x
|
|
||||||
}
|
|
||||||
b -= a
|
|
||||||
} while (b)
|
|
||||||
|
|
||||||
// rescale
|
|
||||||
return a << shift
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The least common multiple computed as abs(a*b)/gcd(a,b)
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} The least common multiple of a and b
|
|
||||||
*/
|
|
||||||
export function lcm (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
if (a === 0n && b === 0n) return BigInt(0)
|
|
||||||
return abs(a * b) / gcd(a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} maximum of numbers a and b
|
|
||||||
*/
|
|
||||||
export function max (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
return (a >= b) ? a : b
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} minimum of numbers a and b
|
|
||||||
*/
|
|
||||||
export function min (a, b) {
|
|
||||||
a = BigInt(a)
|
|
||||||
b = BigInt(b)
|
|
||||||
return (a >= b) ? b : a
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modular inverse.
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a The number to find an inverse for
|
|
||||||
* @param {number|bigint} n The modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint|NaN} the inverse modulo n or NaN if it does not exist
|
|
||||||
*/
|
|
||||||
export function modInv (a, n) {
|
|
||||||
try {
|
|
||||||
const egcd = eGcd(toZn(a, n), n)
|
|
||||||
if (egcd.g !== 1n) {
|
|
||||||
return NaN // modular inverse does not exist
|
|
||||||
} else {
|
|
||||||
return toZn(egcd.x, n)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return NaN
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
|
||||||
*
|
|
||||||
* @param {number|bigint} b base
|
|
||||||
* @param {number|bigint} e exponent
|
|
||||||
* @param {number|bigint} n modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint} b**e mod n
|
|
||||||
*/
|
|
||||||
export function modPow (b, e, n) {
|
|
||||||
n = BigInt(n)
|
|
||||||
if (n === 0n) { return NaN } else if (n === 1n) { return BigInt(0) }
|
|
||||||
|
|
||||||
b = toZn(b, n)
|
|
||||||
|
|
||||||
e = BigInt(e)
|
|
||||||
if (e < 0n) {
|
|
||||||
return modInv(modPow(b, abs(e), n), n)
|
|
||||||
}
|
|
||||||
|
|
||||||
let r = 1n
|
|
||||||
while (e > 0) {
|
|
||||||
if ((e % 2n) === 1n) {
|
|
||||||
r = (r * b) % n
|
|
||||||
}
|
|
||||||
e = e / 2n
|
|
||||||
b = b ** 2n % n
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the smallest positive element that is congruent to a in modulo n
|
|
||||||
* @param {number|bigint} a An integer
|
|
||||||
* @param {number|bigint} n The modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint} The smallest positive representation of a in modulo n
|
|
||||||
*/
|
|
||||||
export function toZn (a, n) {
|
|
||||||
n = BigInt(n)
|
|
||||||
if (n <= 0) { return NaN }
|
|
||||||
|
|
||||||
a = BigInt(a) % n
|
|
||||||
return (a < 0) ? a + n : a
|
|
||||||
}
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
*
|
||||||
|
* @returns The absolute value of a
|
||||||
|
*/
|
||||||
|
export function abs (a: number|bigint): number|bigint {
|
||||||
|
return (a >= 0) ? a : -a
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
/**
|
||||||
|
* Returns the bitlength of a number
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @returns The bit length
|
||||||
|
*/
|
||||||
|
export function bitLength (a: number|bigint): number {
|
||||||
|
a = BigInt(a)
|
||||||
|
if (a === 1n) { return 1 }
|
||||||
|
let bits = 1
|
||||||
|
do {
|
||||||
|
bits++
|
||||||
|
} while ((a >>= 1n) > 1n)
|
||||||
|
return bits
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
export interface Egcd {
|
||||||
|
g: bigint
|
||||||
|
x: bigint
|
||||||
|
y: bigint
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
|
||||||
|
* Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
||||||
|
*/
|
||||||
|
export function eGcd (a: number|bigint, b: number|bigint): Egcd {
|
||||||
|
let aBigint = BigInt(a)
|
||||||
|
let bBigInt = BigInt(b)
|
||||||
|
if (aBigint <= 0n || bBigInt <= 0n) throw new RangeError('a and b MUST be > 0') // a and b MUST be positive
|
||||||
|
|
||||||
|
let x = 0n
|
||||||
|
let y = 1n
|
||||||
|
let u = 1n
|
||||||
|
let v = 0n
|
||||||
|
|
||||||
|
while (aBigint !== 0n) {
|
||||||
|
const q = bBigInt / aBigint
|
||||||
|
const r = bBigInt % aBigint
|
||||||
|
const m = x - (u * q)
|
||||||
|
const n = y - (v * q)
|
||||||
|
bBigInt = aBigint
|
||||||
|
aBigint = r
|
||||||
|
x = u
|
||||||
|
y = v
|
||||||
|
u = m
|
||||||
|
v = n
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
g: bBigInt,
|
||||||
|
x: x,
|
||||||
|
y: y
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { abs } from './abs'
|
||||||
|
/**
|
||||||
|
* Greatest-common divisor of two integers based on the iterative binary algorithm.
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns The greatest common divisor of a and b
|
||||||
|
*/
|
||||||
|
export function gcd (a: number|bigint, b: number|bigint): bigint {
|
||||||
|
let aAbs = BigInt(abs(a))
|
||||||
|
let bAbs = BigInt(abs(b))
|
||||||
|
if (aAbs === 0n) { return bAbs } else if (bAbs === 0n) { return aAbs }
|
||||||
|
|
||||||
|
let shift = 0n
|
||||||
|
while (((aAbs | bAbs) & 1n) === 0n) {
|
||||||
|
aAbs >>= 1n
|
||||||
|
bAbs >>= 1n
|
||||||
|
shift++
|
||||||
|
}
|
||||||
|
while ((aAbs & 1n) === 0n) aAbs >>= 1n
|
||||||
|
do {
|
||||||
|
while ((bAbs & 1n) === 0n) bAbs >>= 1n
|
||||||
|
if (aAbs > bAbs) {
|
||||||
|
const x = aAbs
|
||||||
|
aAbs = bAbs
|
||||||
|
bAbs = x
|
||||||
|
}
|
||||||
|
bAbs -= aAbs
|
||||||
|
} while (bAbs !== 0n)
|
||||||
|
|
||||||
|
// rescale
|
||||||
|
return aAbs << shift
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { abs } from './abs'
|
||||||
|
import { gcd } from './gcd'
|
||||||
|
/**
|
||||||
|
* The least common multiple computed as abs(a*b)/gcd(a,b)
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns The least common multiple of a and b
|
||||||
|
*/
|
||||||
|
export function lcm (a: number|bigint, b: number|bigint): bigint {
|
||||||
|
const aBigInt = BigInt(a)
|
||||||
|
const bBigInt = BigInt(b)
|
||||||
|
if (aBigInt === 0n && bBigInt === 0n) return BigInt(0)
|
||||||
|
return abs(aBigInt * bBigInt) as bigint / gcd(aBigInt, bBigInt)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
/**
|
||||||
|
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns Maximum of numbers a and b
|
||||||
|
*/
|
||||||
|
export function max (a: number|bigint, b: number|bigint): number|bigint {
|
||||||
|
return (a >= b) ? a : b
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
/**
|
||||||
|
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* @param b
|
||||||
|
*
|
||||||
|
* @returns Minimum of numbers a and b
|
||||||
|
*/
|
||||||
|
export function min (a: number|bigint, b: number|bigint): number|bigint {
|
||||||
|
return (a >= b) ? b : a
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { eGcd } from './egcd'
|
||||||
|
import { toZn } from './toZn'
|
||||||
|
/**
|
||||||
|
* Modular inverse.
|
||||||
|
*
|
||||||
|
* @param a The number to find an inverse for
|
||||||
|
* @param n The modulo
|
||||||
|
*
|
||||||
|
* @returns The inverse modulo n or number NaN if it does not exist
|
||||||
|
*/
|
||||||
|
export function modInv (a: number|bigint, n: number|bigint): bigint|number {
|
||||||
|
try {
|
||||||
|
const egcd = eGcd(toZn(a, n), n)
|
||||||
|
if (egcd.g !== 1n) {
|
||||||
|
return NaN // modular inverse does not exist
|
||||||
|
} else {
|
||||||
|
return toZn(egcd.x, n)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return NaN
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { abs } from './abs'
|
||||||
|
import { modInv } from './modInv'
|
||||||
|
import { toZn } from './toZn'
|
||||||
|
/**
|
||||||
|
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
||||||
|
*
|
||||||
|
* @param b base
|
||||||
|
* @param e exponent
|
||||||
|
* @param n modulo
|
||||||
|
*
|
||||||
|
* @returns b**e mod n or number NaN if n <= 0
|
||||||
|
*/
|
||||||
|
export function modPow (b: number|bigint, e: number|bigint, n: number|bigint): bigint|number {
|
||||||
|
const nBigInt = BigInt(n)
|
||||||
|
if (nBigInt <= 0n) { return NaN } else if (nBigInt === 1n) { return BigInt(0) }
|
||||||
|
|
||||||
|
let bZn = toZn(b, nBigInt)
|
||||||
|
|
||||||
|
e = BigInt(e)
|
||||||
|
if (e < 0n) {
|
||||||
|
return modInv(modPow(bZn, abs(e), nBigInt), nBigInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
let r = 1n
|
||||||
|
while (e > 0) {
|
||||||
|
if ((e % 2n) === 1n) {
|
||||||
|
r = (r * (bZn as bigint)) % nBigInt
|
||||||
|
}
|
||||||
|
e = e / 2n
|
||||||
|
bZn = bZn as bigint ** 2n % nBigInt
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
* Finds the smallest positive element that is congruent to a in modulo n
|
||||||
|
* @param {number|bigint} a An integer
|
||||||
|
* @param {number|bigint} n The modulo
|
||||||
|
*
|
||||||
|
* @returns The smallest positive representation of a in modulo n or number NaN if n < 0
|
||||||
|
*/
|
||||||
|
export function toZn (a: number|bigint, n: number|bigint): bigint|number {
|
||||||
|
const nBigInt = BigInt(n)
|
||||||
|
if (n <= 0) { return NaN }
|
||||||
|
|
||||||
|
const aZn = BigInt(a) % nBigInt
|
||||||
|
return (aZn < 0n) ? aZn + nBigInt : aZn
|
||||||
|
}
|
37
test/abs.js
37
test/abs.js
|
@ -1,37 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
value: BigInt(1),
|
|
||||||
abs: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt(-2),
|
|
||||||
abs: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'),
|
|
||||||
abs: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'),
|
|
||||||
abs: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('abs', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`abs(${input.value})`, function () {
|
|
||||||
it(`should return ${input.abs}`, function () {
|
|
||||||
const ret = _pkg.abs(input.value)
|
|
||||||
chai.expect(ret).to.equal(input.abs)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
describe('abs', function () {
|
||||||
|
const inputs = [
|
||||||
|
{
|
||||||
|
value: BigInt(1),
|
||||||
|
abs: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: BigInt(-2),
|
||||||
|
abs: BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'),
|
||||||
|
abs: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'),
|
||||||
|
abs: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
for (const input of inputs) {
|
||||||
|
describe(`abs(${input.value})`, function () {
|
||||||
|
it(`should return ${input.abs}`, function () {
|
||||||
|
const ret = _pkg.abs(input.value)
|
||||||
|
chai.expect(ret).to.equal(input.abs)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,34 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
value: BigInt(1),
|
|
||||||
bitLength: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt(-2),
|
|
||||||
bitLength: 2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt(11592217955149597331),
|
|
||||||
abs: BigInt(11592217955149597331),
|
|
||||||
bitLength: 64
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('bitLength', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`bitLength(${input.value})`, function () {
|
|
||||||
it(`should return ${input.bitLength}`, function () {
|
|
||||||
const ret = _pkg.bitLength(input.value)
|
|
||||||
chai.expect(ret).to.equal(input.bitLength)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
describe('bitLength', function () {
|
||||||
|
const inputs = [
|
||||||
|
{
|
||||||
|
value: BigInt(1),
|
||||||
|
bitLength: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: BigInt(-2),
|
||||||
|
bitLength: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: BigInt(11592217955149597331),
|
||||||
|
abs: BigInt(11592217955149597331),
|
||||||
|
bitLength: 64
|
||||||
|
}
|
||||||
|
]
|
||||||
|
for (const input of inputs) {
|
||||||
|
describe(`bitLength(${input.value})`, function () {
|
||||||
|
it(`should return ${input.bitLength}`, function () {
|
||||||
|
const ret = _pkg.bitLength(input.value)
|
||||||
|
chai.expect(ret).to.equal(input.bitLength)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,23 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>bigint-mod-arith - Mocha Tests</title>
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.1.1/mocha.min.css">
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.1.1/mocha.min.js"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div id="mocha"></div>
|
|
||||||
<script>mocha.setup('bdd'); mocha.setup({ timeout: 90000 });</script>
|
|
||||||
|
|
||||||
<script type="module">
|
|
||||||
import * as _pkg from '../../../lib/index.browser.bundle.mod.js'
|
|
||||||
window._pkg = _pkg;
|
|
||||||
import './tests.js';
|
|
||||||
mocha.run();
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
|
@ -1,522 +0,0 @@
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
value: BigInt(1),
|
|
||||||
abs: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt(-2),
|
|
||||||
abs: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'),
|
|
||||||
abs: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'),
|
|
||||||
abs: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('abs', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`abs(${input.value})`, function () {
|
|
||||||
it(`should return ${input.abs}`, function () {
|
|
||||||
const ret = _pkg.abs(input.value);
|
|
||||||
chai.expect(ret).to.equal(input.abs);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs$1 = [
|
|
||||||
{
|
|
||||||
value: BigInt(1),
|
|
||||||
bitLength: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt(-2),
|
|
||||||
bitLength: 2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: BigInt(11592217955149597331),
|
|
||||||
abs: BigInt(11592217955149597331),
|
|
||||||
bitLength: 64
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('bitLength', function () {
|
|
||||||
for (const input of inputs$1) {
|
|
||||||
describe(`bitLength(${input.value})`, function () {
|
|
||||||
it(`should return ${input.bitLength}`, function () {
|
|
||||||
const ret = _pkg.bitLength(input.value);
|
|
||||||
chai.expect(ret).to.equal(input.bitLength);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs$2 = [
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
b: BigInt(1),
|
|
||||||
gcd: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
b: BigInt(189),
|
|
||||||
gcd: BigInt(189)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(189),
|
|
||||||
b: BigInt(0),
|
|
||||||
gcd: BigInt(189)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
b: BigInt(0),
|
|
||||||
gcd: BigInt(0)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
b: BigInt('14546149867129487614601346814'),
|
|
||||||
gcd: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(27),
|
|
||||||
b: BigInt(18),
|
|
||||||
gcd: BigInt(9)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-27),
|
|
||||||
b: BigInt(18),
|
|
||||||
gcd: BigInt(9)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(256),
|
|
||||||
b: BigInt(128),
|
|
||||||
gcd: BigInt(128)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
|
|
||||||
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
|
|
||||||
gcd: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109')
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('gcd', function () {
|
|
||||||
for (const input of inputs$2) {
|
|
||||||
describe(`gcd(${input.a}, ${input.b})`, function () {
|
|
||||||
it(`should return ${input.gcd}`, function () {
|
|
||||||
const ret = _pkg.gcd(input.a, input.b);
|
|
||||||
chai.expect(ret).to.equal(input.gcd);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs$3 = [
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
b: BigInt(0),
|
|
||||||
lcm: BigInt(0)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
b: BigInt(1),
|
|
||||||
lcm: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
b: BigInt('14546149867129487614601346814'),
|
|
||||||
lcm: BigInt('14546149867129487614601346814')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(27),
|
|
||||||
b: BigInt(18),
|
|
||||||
lcm: BigInt(27) * BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-27),
|
|
||||||
b: BigInt(18),
|
|
||||||
lcm: BigInt(27) * BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
|
|
||||||
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
|
|
||||||
lcm: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243')
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('lcm', function () {
|
|
||||||
for (const input of inputs$3) {
|
|
||||||
describe(`lcm(${input.a}, ${input.b})`, function () {
|
|
||||||
it(`should return ${input.lcm}`, function () {
|
|
||||||
const ret = _pkg.lcm(input.a, input.b);
|
|
||||||
chai.expect(ret).to.equal(input.lcm);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs$4 = [
|
|
||||||
{
|
|
||||||
value: [BigInt(1), BigInt(2)],
|
|
||||||
max: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(2), BigInt(1)],
|
|
||||||
max: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(2), BigInt(2)],
|
|
||||||
max: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(1), BigInt(-2)],
|
|
||||||
max: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(-2), BigInt(1)],
|
|
||||||
max: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(-2), BigInt(-2)],
|
|
||||||
max: BigInt(-2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
|
||||||
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
max: BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('max', function () {
|
|
||||||
for (const input of inputs$4) {
|
|
||||||
describe(`max(${input.value[0]}, ${input.value[1]})`, function () {
|
|
||||||
it(`should return ${input.max}`, function () {
|
|
||||||
const ret = _pkg.max(input.value[0], input.value[1]);
|
|
||||||
chai.expect(ret).to.equal(input.max);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs$5 = [
|
|
||||||
{
|
|
||||||
value: [BigInt(1), BigInt(2)],
|
|
||||||
min: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(2), BigInt(1)],
|
|
||||||
min: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(2), BigInt(2)],
|
|
||||||
min: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(1), BigInt(-2)],
|
|
||||||
min: BigInt(-2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(-2), BigInt(1)],
|
|
||||||
min: BigInt(-2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(-2), BigInt(-2)],
|
|
||||||
min: BigInt(-2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
|
||||||
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
min: BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('min', function () {
|
|
||||||
for (const input of inputs$5) {
|
|
||||||
describe(`min(${input.value[0]}, ${input.value[1]})`, function () {
|
|
||||||
it(`should return ${input.min}`, function () {
|
|
||||||
const ret = _pkg.min(input.value[0], input.value[1]);
|
|
||||||
chai.expect(ret).to.equal(input.min);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs$6 = [
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
n: BigInt(19),
|
|
||||||
modInv: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(2),
|
|
||||||
n: BigInt(5),
|
|
||||||
modInv: BigInt(3)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-2),
|
|
||||||
n: BigInt(5),
|
|
||||||
modInv: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(2),
|
|
||||||
n: BigInt(4),
|
|
||||||
modInv: NaN
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
n: BigInt(0),
|
|
||||||
modInv: NaN
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
n: BigInt(37),
|
|
||||||
modInv: NaN
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('modInv', function () {
|
|
||||||
for (const input of inputs$6) {
|
|
||||||
describe(`modInv(${input.a}, ${input.n})`, function () {
|
|
||||||
it(`should return ${input.modInv}`, function () {
|
|
||||||
const ret = _pkg.modInv(input.a, input.n);
|
|
||||||
// chai.assert( String(ret) === String(input.modInv) );
|
|
||||||
chai.expect(String(ret)).to.be.equal(String(input.modInv));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs$7 = [
|
|
||||||
{
|
|
||||||
a: BigInt(4),
|
|
||||||
b: BigInt(-1),
|
|
||||||
n: BigInt(0),
|
|
||||||
modPow: NaN
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(4),
|
|
||||||
b: BigInt(-1),
|
|
||||||
n: BigInt(1),
|
|
||||||
modPow: BigInt(0)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(4),
|
|
||||||
b: BigInt(-1),
|
|
||||||
n: BigInt(19),
|
|
||||||
modPow: BigInt(5)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-5),
|
|
||||||
b: BigInt(2),
|
|
||||||
n: BigInt(7),
|
|
||||||
modPow: BigInt(4)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(2),
|
|
||||||
b: BigInt(255),
|
|
||||||
n: BigInt(64),
|
|
||||||
modPow: BigInt(0)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(3),
|
|
||||||
b: BigInt(3),
|
|
||||||
n: BigInt(25),
|
|
||||||
modPow: BigInt(2)
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('modPow', function () {
|
|
||||||
this.timeout(90000);
|
|
||||||
for (const input of inputs$7) {
|
|
||||||
describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () {
|
|
||||||
it(`should return ${input.modPow}`, function () {
|
|
||||||
const ret = _pkg.modPow(input.a, input.b, input.n);
|
|
||||||
chai.expect(String(ret)).to.equal(String(input.modPow));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
describe('Time profiling', function () {
|
|
||||||
let iterations = 500;
|
|
||||||
it(`just testing ${iterations} iterations of a big modular exponentiation (1024 bits)`, function () {
|
|
||||||
const p = BigInt('103920301461718841589267304263845359224454055603847417021399996422142529929535423886894599506329362009085557636432288745748144369296043048325513558512136442971686130986388589421125262751724362880217790112013162815676017250234401214198365302142787009943498370856167174244675719638815809347261773472114842038647');
|
|
||||||
const b = BigInt('313632271690673451924314047671460131678794095260951233878123501752357966284491455239133687519908410656818506813151659324961829045286402303082891913186909806785080978448037486178337722667190743610785429936585699831407575170854873682955317589189564880931807976657385223632835801016017549762825562427694700595');
|
|
||||||
const e = BigInt('452149997592306202232720864363485824701879487303880767747217308770351197801836846325633986474037061753983278534192061455638289551714281047915315943771002615269860312318606105460307037327329178890486613832051027105330475852552183444938408408863970975090778239473049899109989825645608770309107015209564444316');
|
|
||||||
while (iterations > 0) {
|
|
||||||
_pkg.modPow(b, e, p);
|
|
||||||
iterations--;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
|
|
||||||
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs$8 = [
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
n: BigInt(19),
|
|
||||||
toZn: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-25),
|
|
||||||
n: BigInt(9),
|
|
||||||
toZn: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt('12359782465012847510249'),
|
|
||||||
n: BigInt(5),
|
|
||||||
toZn: BigInt(4)
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('toZn', function () {
|
|
||||||
for (const input of inputs$8) {
|
|
||||||
describe(`toZn(${input.a}, ${input.n})`, function () {
|
|
||||||
it(`should return ${input.toZn}`, function () {
|
|
||||||
const ret = _pkg.toZn(input.a, input.n);
|
|
||||||
chai.expect(ret).to.equal(input.toZn);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
66
test/gcd.js
66
test/gcd.js
|
@ -1,66 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
b: BigInt(1),
|
|
||||||
gcd: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
b: BigInt(189),
|
|
||||||
gcd: BigInt(189)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(189),
|
|
||||||
b: BigInt(0),
|
|
||||||
gcd: BigInt(189)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
b: BigInt(0),
|
|
||||||
gcd: BigInt(0)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
b: BigInt('14546149867129487614601346814'),
|
|
||||||
gcd: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(27),
|
|
||||||
b: BigInt(18),
|
|
||||||
gcd: BigInt(9)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-27),
|
|
||||||
b: BigInt(18),
|
|
||||||
gcd: BigInt(9)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(256),
|
|
||||||
b: BigInt(128),
|
|
||||||
gcd: BigInt(128)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
|
|
||||||
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
|
|
||||||
gcd: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109')
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('gcd', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`gcd(${input.a}, ${input.b})`, function () {
|
|
||||||
it(`should return ${input.gcd}`, function () {
|
|
||||||
const ret = _pkg.gcd(input.a, input.b)
|
|
||||||
chai.expect(ret).to.equal(input.gcd)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
describe('gcd', function () {
|
||||||
|
const inputs = [
|
||||||
|
{
|
||||||
|
a: BigInt(1),
|
||||||
|
b: BigInt(1),
|
||||||
|
gcd: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(0),
|
||||||
|
b: BigInt(189),
|
||||||
|
gcd: BigInt(189)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(189),
|
||||||
|
b: BigInt(0),
|
||||||
|
gcd: BigInt(189)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(0),
|
||||||
|
b: BigInt(0),
|
||||||
|
gcd: BigInt(0)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(1),
|
||||||
|
b: BigInt('14546149867129487614601346814'),
|
||||||
|
gcd: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(27),
|
||||||
|
b: BigInt(18),
|
||||||
|
gcd: BigInt(9)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(-27),
|
||||||
|
b: BigInt(18),
|
||||||
|
gcd: BigInt(9)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(256),
|
||||||
|
b: BigInt(128),
|
||||||
|
gcd: BigInt(128)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
|
||||||
|
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
|
||||||
|
gcd: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
for (const input of inputs) {
|
||||||
|
describe(`gcd(${input.a}, ${input.b})`, function () {
|
||||||
|
it(`should return ${input.gcd}`, function () {
|
||||||
|
const ret = _pkg.gcd(input.a, input.b)
|
||||||
|
chai.expect(ret).to.equal(input.gcd)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
51
test/lcm.js
51
test/lcm.js
|
@ -1,51 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
b: BigInt(0),
|
|
||||||
lcm: BigInt(0)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
b: BigInt(1),
|
|
||||||
lcm: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
b: BigInt('14546149867129487614601346814'),
|
|
||||||
lcm: BigInt('14546149867129487614601346814')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(27),
|
|
||||||
b: BigInt(18),
|
|
||||||
lcm: BigInt(27) * BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-27),
|
|
||||||
b: BigInt(18),
|
|
||||||
lcm: BigInt(27) * BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
|
|
||||||
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
|
|
||||||
lcm: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243')
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('lcm', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`lcm(${input.a}, ${input.b})`, function () {
|
|
||||||
it(`should return ${input.lcm}`, function () {
|
|
||||||
const ret = _pkg.lcm(input.a, input.b)
|
|
||||||
chai.expect(ret).to.equal(input.lcm)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
describe('lcm', function () {
|
||||||
|
const inputs = [
|
||||||
|
{
|
||||||
|
a: BigInt(0),
|
||||||
|
b: BigInt(0),
|
||||||
|
lcm: BigInt(0)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(1),
|
||||||
|
b: BigInt(1),
|
||||||
|
lcm: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(1),
|
||||||
|
b: BigInt('14546149867129487614601346814'),
|
||||||
|
lcm: BigInt('14546149867129487614601346814')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(27),
|
||||||
|
b: BigInt(18),
|
||||||
|
lcm: BigInt(27) * BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(-27),
|
||||||
|
b: BigInt(18),
|
||||||
|
lcm: BigInt(27) * BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
|
||||||
|
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
|
||||||
|
lcm: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
for (const input of inputs) {
|
||||||
|
describe(`lcm(${input.a}, ${input.b})`, function () {
|
||||||
|
it(`should return ${input.lcm}`, function () {
|
||||||
|
const ret = _pkg.lcm(input.a, input.b)
|
||||||
|
chai.expect(ret).to.equal(input.lcm)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
93
test/max.js
93
test/max.js
|
@ -1,93 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
value: [BigInt(1), BigInt(2)],
|
|
||||||
max: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(2), BigInt(1)],
|
|
||||||
max: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(2), BigInt(2)],
|
|
||||||
max: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(1), BigInt(-2)],
|
|
||||||
max: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(-2), BigInt(1)],
|
|
||||||
max: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(-2), BigInt(-2)],
|
|
||||||
max: BigInt(-2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
|
||||||
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
max: BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
max: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('max', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`max(${input.value[0]}, ${input.value[1]})`, function () {
|
|
||||||
it(`should return ${input.max}`, function () {
|
|
||||||
const ret = _pkg.max(input.value[0], input.value[1])
|
|
||||||
chai.expect(ret).to.equal(input.max)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
describe('max', function () {
|
||||||
|
const inputs = [
|
||||||
|
{
|
||||||
|
value: [BigInt(1), BigInt(2)],
|
||||||
|
max: BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(2), BigInt(1)],
|
||||||
|
max: BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(2), BigInt(2)],
|
||||||
|
max: BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(1), BigInt(-2)],
|
||||||
|
max: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(-2), BigInt(1)],
|
||||||
|
max: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(-2), BigInt(-2)],
|
||||||
|
max: BigInt(-2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
||||||
|
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
||||||
|
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
||||||
|
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
||||||
|
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
||||||
|
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
||||||
|
max: BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
max: BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
max: BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
max: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
for (const input of inputs) {
|
||||||
|
describe(`max(${input.value[0]}, ${input.value[1]})`, function () {
|
||||||
|
it(`should return ${input.max}`, function () {
|
||||||
|
const ret = _pkg.max(input.value[0], input.value[1])
|
||||||
|
chai.expect(ret).to.equal(input.max)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
93
test/min.js
93
test/min.js
|
@ -1,93 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
value: [BigInt(1), BigInt(2)],
|
|
||||||
min: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(2), BigInt(1)],
|
|
||||||
min: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(2), BigInt(2)],
|
|
||||||
min: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(1), BigInt(-2)],
|
|
||||||
min: BigInt(-2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(-2), BigInt(1)],
|
|
||||||
min: BigInt(-2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt(-2), BigInt(-2)],
|
|
||||||
min: BigInt(-2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
|
||||||
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
|
||||||
min: BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
|
||||||
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('min', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`min(${input.value[0]}, ${input.value[1]})`, function () {
|
|
||||||
it(`should return ${input.min}`, function () {
|
|
||||||
const ret = _pkg.min(input.value[0], input.value[1])
|
|
||||||
chai.expect(ret).to.equal(input.min)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
describe('min', function () {
|
||||||
|
const inputs = [
|
||||||
|
{
|
||||||
|
value: [BigInt(1), BigInt(2)],
|
||||||
|
min: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(2), BigInt(1)],
|
||||||
|
min: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(2), BigInt(2)],
|
||||||
|
min: BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(1), BigInt(-2)],
|
||||||
|
min: BigInt(-2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(-2), BigInt(1)],
|
||||||
|
min: BigInt(-2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt(-2), BigInt(-2)],
|
||||||
|
min: BigInt(-2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
||||||
|
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
||||||
|
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
||||||
|
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
||||||
|
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
|
||||||
|
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
|
||||||
|
min: BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
min: BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
min: BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
min: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
|
||||||
|
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
for (const input of inputs) {
|
||||||
|
describe(`min(${input.value[0]}, ${input.value[1]})`, function () {
|
||||||
|
it(`should return ${input.min}`, function () {
|
||||||
|
const ret = _pkg.min(input.value[0], input.value[1])
|
||||||
|
chai.expect(ret).to.equal(input.min)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,52 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
n: BigInt(19),
|
|
||||||
modInv: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(2),
|
|
||||||
n: BigInt(5),
|
|
||||||
modInv: BigInt(3)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-2),
|
|
||||||
n: BigInt(5),
|
|
||||||
modInv: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(2),
|
|
||||||
n: BigInt(4),
|
|
||||||
modInv: NaN
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
n: BigInt(0),
|
|
||||||
modInv: NaN
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(0),
|
|
||||||
n: BigInt(37),
|
|
||||||
modInv: NaN
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('modInv', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`modInv(${input.a}, ${input.n})`, function () {
|
|
||||||
it(`should return ${input.modInv}`, function () {
|
|
||||||
const ret = _pkg.modInv(input.a, input.n)
|
|
||||||
// chai.assert( String(ret) === String(input.modInv) );
|
|
||||||
chai.expect(String(ret)).to.be.equal(String(input.modInv))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
describe('modInv', function () {
|
||||||
|
const inputs = [
|
||||||
|
{
|
||||||
|
a: BigInt(1),
|
||||||
|
n: BigInt(19),
|
||||||
|
modInv: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(2),
|
||||||
|
n: BigInt(5),
|
||||||
|
modInv: BigInt(3)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(-2),
|
||||||
|
n: BigInt(5),
|
||||||
|
modInv: BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(2),
|
||||||
|
n: BigInt(4),
|
||||||
|
modInv: NaN
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(0),
|
||||||
|
n: BigInt(0),
|
||||||
|
modInv: NaN
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(0),
|
||||||
|
n: BigInt(37),
|
||||||
|
modInv: NaN
|
||||||
|
}
|
||||||
|
]
|
||||||
|
for (const input of inputs) {
|
||||||
|
describe(`modInv(${input.a}, ${input.n})`, function () {
|
||||||
|
it(`should return ${input.modInv}`, function () {
|
||||||
|
const ret = _pkg.modInv(input.a, input.n)
|
||||||
|
// chai.assert( String(ret) === String(input.modInv) );
|
||||||
|
chai.expect(String(ret)).to.be.equal(String(input.modInv))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,11 +1,4 @@
|
||||||
'use strict'
|
describe('modPow', function () {
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
const inputs = [
|
||||||
{
|
{
|
||||||
a: BigInt(4),
|
a: BigInt(4),
|
||||||
|
@ -45,7 +38,6 @@ const inputs = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
describe('modPow', function () {
|
|
||||||
this.timeout(90000)
|
this.timeout(90000)
|
||||||
for (const input of inputs) {
|
for (const input of inputs) {
|
||||||
describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () {
|
describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () {
|
36
test/toZn.js
36
test/toZn.js
|
@ -1,36 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
// Every test file (you can create as many as you want) should start like this
|
|
||||||
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
||||||
const _pkg = require('../lib/index.node')
|
|
||||||
const chai = require('chai')
|
|
||||||
// <--
|
|
||||||
|
|
||||||
const inputs = [
|
|
||||||
{
|
|
||||||
a: BigInt(1),
|
|
||||||
n: BigInt(19),
|
|
||||||
toZn: BigInt(1)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt(-25),
|
|
||||||
n: BigInt(9),
|
|
||||||
toZn: BigInt(2)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: BigInt('12359782465012847510249'),
|
|
||||||
n: BigInt(5),
|
|
||||||
toZn: BigInt(4)
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('toZn', function () {
|
|
||||||
for (const input of inputs) {
|
|
||||||
describe(`toZn(${input.a}, ${input.n})`, function () {
|
|
||||||
it(`should return ${input.toZn}`, function () {
|
|
||||||
const ret = _pkg.toZn(input.a, input.n)
|
|
||||||
chai.expect(ret).to.equal(input.toZn)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
describe('toZn', function () {
|
||||||
|
const inputs = [
|
||||||
|
{
|
||||||
|
a: BigInt(1),
|
||||||
|
n: BigInt(19),
|
||||||
|
toZn: BigInt(1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt(-25),
|
||||||
|
n: BigInt(9),
|
||||||
|
toZn: BigInt(2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: BigInt('12359782465012847510249'),
|
||||||
|
n: BigInt(5),
|
||||||
|
toZn: BigInt(4)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
for (const input of inputs) {
|
||||||
|
describe(`toZn(${input.a}, ${input.n})`, function () {
|
||||||
|
it(`should return ${input.toZn}`, function () {
|
||||||
|
const ret = _pkg.toZn(input.a, input.n)
|
||||||
|
chai.expect(ret).to.equal(input.toZn)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/tsconfig",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||||
|
"lib": [ "es2020" ], /* Specify library files to be included in the compilation. */
|
||||||
|
"allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
|
"checkJs": true, /* Report errors in .js files. */
|
||||||
|
// "jsx": "preserve", /* Specify JSX code generation: 'react', 'react-jsx', 'react-jsxdev', 'preserve' or 'react-native'. */
|
||||||
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
|
|
||||||
|
/* Additional Checks */
|
||||||
|
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||||
|
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||||
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||||
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||||
|
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
||||||
|
|
||||||
|
/* Module Resolution Options */
|
||||||
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||||
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
|
"typeRoots": [ "./build/typings", "./node_modules/@types" ], /* List of folders to include type definitions from. */
|
||||||
|
// "types": [], /* Type declaration files to be included in compilation. */
|
||||||
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||||
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
|
||||||
|
/* Experimental Options */
|
||||||
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
|
|
||||||
|
/* Advanced Options */
|
||||||
|
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||||
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||||
|
},
|
||||||
|
"include": ["src/**/*", "build/typings/**/*", "test/**/*"]
|
||||||
|
}
|
|
@ -1,105 +0,0 @@
|
||||||
/**
|
|
||||||
* A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*/
|
|
||||||
export type egcdReturn = {
|
|
||||||
g: bigint;
|
|
||||||
x: bigint;
|
|
||||||
y: bigint;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* Some common functions for modular arithmetic using native JS implementation of BigInt
|
|
||||||
* @module bigint-mod-arith
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
*
|
|
||||||
* @returns {bigint} the absolute value of a
|
|
||||||
*/
|
|
||||||
export function abs(a: number | bigint): bigint;
|
|
||||||
/**
|
|
||||||
* Returns the bitlength of a number
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @returns {number} - the bit length
|
|
||||||
*/
|
|
||||||
export function bitLength(a: number | bigint): number;
|
|
||||||
/**
|
|
||||||
* @typedef {Object} egcdReturn A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
* @property {bigint} g
|
|
||||||
* @property {bigint} x
|
|
||||||
* @property {bigint} y
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
|
|
||||||
* Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {egcdReturn} A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|
||||||
*/
|
|
||||||
export function eGcd(a: number | bigint, b: number | bigint): egcdReturn;
|
|
||||||
/**
|
|
||||||
* Greatest-common divisor of two integers based on the iterative binary algorithm.
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} The greatest common divisor of a and b
|
|
||||||
*/
|
|
||||||
export function gcd(a: number | bigint, b: number | bigint): bigint;
|
|
||||||
/**
|
|
||||||
* The least common multiple computed as abs(a*b)/gcd(a,b)
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} The least common multiple of a and b
|
|
||||||
*/
|
|
||||||
export function lcm(a: number | bigint, b: number | bigint): bigint;
|
|
||||||
/**
|
|
||||||
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} maximum of numbers a and b
|
|
||||||
*/
|
|
||||||
export function max(a: number | bigint, b: number | bigint): bigint;
|
|
||||||
/**
|
|
||||||
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a
|
|
||||||
* @param {number|bigint} b
|
|
||||||
*
|
|
||||||
* @returns {bigint} minimum of numbers a and b
|
|
||||||
*/
|
|
||||||
export function min(a: number | bigint, b: number | bigint): bigint;
|
|
||||||
/**
|
|
||||||
* Modular inverse.
|
|
||||||
*
|
|
||||||
* @param {number|bigint} a The number to find an inverse for
|
|
||||||
* @param {number|bigint} n The modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint|NaN} the inverse modulo n or NaN if it does not exist
|
|
||||||
*/
|
|
||||||
export function modInv(a: number | bigint, n: number | bigint): number | bigint;
|
|
||||||
/**
|
|
||||||
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
|
||||||
*
|
|
||||||
* @param {number|bigint} b base
|
|
||||||
* @param {number|bigint} e exponent
|
|
||||||
* @param {number|bigint} n modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint} b**e mod n
|
|
||||||
*/
|
|
||||||
export function modPow(b: number | bigint, e: number | bigint, n: number | bigint): bigint;
|
|
||||||
/**
|
|
||||||
* Finds the smallest positive element that is congruent to a in modulo n
|
|
||||||
* @param {number|bigint} a An integer
|
|
||||||
* @param {number|bigint} n The modulo
|
|
||||||
*
|
|
||||||
* @returns {bigint} The smallest positive representation of a in modulo n
|
|
||||||
*/
|
|
||||||
export function toZn(a: number | bigint, n: number | bigint): bigint;
|
|
Loading…
Reference in New Issue