https://github.com/ethereumjs/fixed-bn.js
a bn.js wrapper that constrains numbers to a fixed width
https://github.com/ethereumjs/fixed-bn.js
Last synced: 2 months ago
JSON representation
a bn.js wrapper that constrains numbers to a fixed width
- Host: GitHub
- URL: https://github.com/ethereumjs/fixed-bn.js
- Owner: ethereumjs
- Archived: true
- Created: 2017-03-20T18:33:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-31T09:29:51.000Z (8 months ago)
- Last Synced: 2025-03-30T16:02:09.136Z (3 months ago)
- Language: TypeScript
- Size: 37.1 KB
- Stars: 8
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SYNOPSIS
> [!WARNING]
> This package has been deprecated and is not maintained.
---[](https://www.npmjs.org/package/fixed-bn.js)
[](https://travis-ci.org/ewasm/fixed-bn.js)
[](https://coveralls.io/r/ewasm/fixed-bn.js)[](https://github.com/feross/standard)
a bn.js factory wrapper that constrains numbers to a fixed width
# USAGE
```javascript
const FixedBN = require('fixed-bn.js')// there are some built in sizes `U64`, `U128`, `U160`, `U256`
const bnNum = new FixedBN.U64('0x5555555')
// use normal bn.js methods
bnNum.iaddn(55)// toBuffer and toArray allways produces a fixed length result
bnNum.toBuffer()
//// you can also create an arbitary fixed lenght bn
// max bit lenght is 199 bits and min length is 2 bits
const I199 = FixedBN(199, 2)
const newBnNum = new I199(390248)
```# API
Since this module extends [BN.js](https://github.com/indutny/bn.js/) it has the methods as it does plus a few extras.
## factory
[./index.js:11-87](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L11-L87 'Source code on GitHub')
A factory that produces BN.js constructors for a given width
**Parameters**
- `maxWidth` **Integer** the max length in bits that the bn.js instance can handle
- `minWidth` **Integer** the min length in bits that the bn.js instance can handleReturns **bn.js** returns a bn.js constuctor that that is constained to `maxWidth` and `minWidth`
## builtin length
the factory has the following builtins
- `FixedBN.U64`
- `FixedBN.U128`
- `FixedBN.U160`
- `FixedBN.U256`## bn.js instance
Each instance has the following additional methods
## maxWidth
[./index.js:35-37](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L35-L37 'Source code on GitHub')
retuns Max Width
Returns **integer**
## minWidth
[./index.js:43-45](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L43-L45 'Source code on GitHub')
retuns Min Width
Returns **integer**
## fromBuffer
[./index.js:66-68](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L66-L68 'Source code on GitHub')
converts a buffer to a fixed-bn.js
**Parameters**
- `value` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | integer)**
- `endain` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `endian` (optional, default `'be'`)## isFixBN
[./index.js:74-76](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L74-L76 'Source code on GitHub')
checks if a BN instance is a fixed BN instance
**Parameters**
- `bn` **bn.js**
## isSameWidth
[./index.js:82-84](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L82-L84 'Source code on GitHub')
checks if a fixed-bn instance is the same width as the contructor
**Parameters**
- `fixBN` **bn.js**
# LICENSE
[MPL-2.0]()