You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 31, 2024. It is now read-only.
a bn.js factory wrapper that constrains numbers to a fixed width
9
10
10
11
# USAGE
12
+
11
13
```javascript
12
14
constFixedBN=require('fixed-bn.js')
13
15
@@ -22,85 +24,88 @@ bnNum.toBuffer()
22
24
23
25
// you can also create an arbitary fixed lenght bn
24
26
// max bit lenght is 199 bits and min length is 2 bits
25
-
constI199=FixedBN(199, 2)
27
+
constI199=FixedBN(199, 2)
26
28
constnewBnNum=newI199(390248)
27
29
```
28
30
29
31
# API
30
-
Since this module extends [BN.js](https://github.com/indutny/bn.js/) it has the methods as it does plus a few extras.
31
32
33
+
Since this module extends [BN.js](https://github.com/indutny/bn.js/) it has the methods as it does plus a few extras.
32
34
33
35
## factory
34
36
35
-
[./index.js:11-87](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L11-L87"Source code on GitHub")
37
+
[./index.js:11-87](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L11-L87'Source code on GitHub')
36
38
37
39
A factory that produces BN.js constructors for a given width
38
40
39
41
**Parameters**
40
42
41
-
-`maxWidth`**Integer** the max length in bits that the bn.js instance can handle
42
-
-`minWidth`**Integer** the min length in bits that the bn.js instance can handle
43
+
-`maxWidth`**Integer** the max length in bits that the bn.js instance can handle
44
+
-`minWidth`**Integer** the min length in bits that the bn.js instance can handle
43
45
44
46
Returns **bn.js** returns a bn.js constuctor that that is constained to `maxWidth` and `minWidth`
45
47
46
48
## builtin length
49
+
47
50
the factory has the following builtins
51
+
48
52
-`FixedBN.U64`
49
53
-`FixedBN.U128`
50
54
-`FixedBN.U160`
51
55
-`FixedBN.U256`
52
56
53
57
## bn.js instance
58
+
54
59
Each instance has the following additional methods
55
60
56
61
## maxWidth
57
62
58
-
[./index.js:35-37](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L35-L37"Source code on GitHub")
63
+
[./index.js:35-37](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L35-L37'Source code on GitHub')
59
64
60
65
retuns Max Width
61
66
62
-
Returns **integer**
67
+
Returns **integer**
63
68
64
69
## minWidth
65
70
66
-
[./index.js:43-45](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L43-L45"Source code on GitHub")
71
+
[./index.js:43-45](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L43-L45'Source code on GitHub')
67
72
68
73
retuns Min Width
69
74
70
-
Returns **integer**
75
+
Returns **integer**
71
76
72
77
## fromBuffer
73
78
74
-
[./index.js:66-68](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L66-L68"Source code on GitHub")
79
+
[./index.js:66-68](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L66-L68'Source code on GitHub')
[./index.js:74-76](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L74-L76"Source code on GitHub")
91
+
[./index.js:74-76](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L74-L76'Source code on GitHub')
87
92
88
93
checks if a BN instance is a fixed BN instance
89
94
90
95
**Parameters**
91
96
92
-
-`bn`**bn.js**
97
+
-`bn`**bn.js**
93
98
94
99
## isSameWidth
95
100
96
-
[./index.js:82-84](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L82-L84"Source code on GitHub")
101
+
[./index.js:82-84](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L82-L84'Source code on GitHub')
97
102
98
103
checks if a fixed-bn instance is the same width as the contructor
0 commit comments