infinityplus 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,157 @@
1
+ export default class InfinityPlus {
2
+ constructor(mantissa = 1, exponent = 0) {
3
+ this.mantissa = mantissa
4
+ this.exponent = exponent
5
+ this.number = `${mantissa.toFixed(2)}e${exponent}`
6
+ this.abs()
7
+ this.fix()
8
+ this.rfix()
9
+ }
10
+ update() {
11
+ if (this.exponent <= 999999) {this.number = `${this.mantissa.toFixed(2)}e${this.exponent}`}
12
+ else {this.number = `${this.mantissa.toFixed(2)}e${this.exponent.toExponential(0).replace("e+", "e")}`}
13
+ }
14
+ fix() {
15
+ return new Promise((resolve, reject) => {
16
+ while (this.mantissa >= 10) {
17
+ this.mantissa /= 10
18
+ this.exponent++
19
+ }
20
+ if (this.mantissa === 0) {this.mantissa++}
21
+ this.update()
22
+ resolve([this.mantissa,this.exponent])
23
+ })
24
+ }
25
+ rfix() {
26
+ return new Promise((resolve, reject) => {
27
+ while (this.mantissa < 1 && this.mantissa > 0) {
28
+ this.mantissa *= 10
29
+ this.exponent--
30
+ }
31
+ if (this.mantissa === 0) {this.mantissa++}
32
+ this.update()
33
+ resolve([this.mantissa,this.exponent])
34
+ })
35
+ }
36
+ async add(mant, exp) {
37
+ const lexp = Math.max(this.exponent, exp)
38
+ let sexp = Math.min(this.exponent, exp)
39
+ let smant = (lexp === this.exponent) ? mant : this.mantissa
40
+ while (sexp < lexp) {
41
+ smant /= 10
42
+ sexp++
43
+ }
44
+ if (lexp === this.exponent) {this.mantissa += smant} else {this.mantissa = mant + smant; this.exponent = lexp}
45
+ await this.fix()
46
+ this.update()
47
+ return [this.mantissa, this.exponent]
48
+ }
49
+ async subtract(mant, exp) {
50
+ const lexp = Math.max(this.exponent, exp)
51
+ let sexp = Math.min(this.exponent, exp)
52
+ let smant = (lexp === this.exponent) ? mant : this.mantissa
53
+ while (sexp < lexp) {
54
+ smant /= 10
55
+ sexp++
56
+ }
57
+ if (lexp === this.exponent) {this.mantissa -= smant} else {this.mantissa = mant - smant; this.exponent = lexp}
58
+ await this.rfix()
59
+ this.update()
60
+ return [this.mantissa, this.exponent]
61
+ }
62
+ async multiply(mant, exp) {
63
+ this.exponent += exp
64
+ this.mantissa *= mant
65
+ await this.fix()
66
+ this.update()
67
+ return [this.mantissa, this.exponent]
68
+ }
69
+ async divide(mant, exp) {
70
+ this.exponent -= exp
71
+ this.mantissa /= mant
72
+ await this.rfix()
73
+ this.update()
74
+ return [this.mantissa, this.exponent]
75
+ }
76
+ async power(exp) {
77
+ this.exponent *= exp
78
+ this.mantissa **= exp
79
+ await this.fix()
80
+ this.update()
81
+ return [this.mantissa, this.exponent]
82
+ }
83
+ async root(n) {
84
+ this.mantissa **= 1/n
85
+ this.exponent /= n
86
+ if (this.mantissa < 1 && this.mantissa > 0) {
87
+ await this.rfix()
88
+ }
89
+ else {
90
+ await this.fix()
91
+ }
92
+ let intExp = Math.floor(this.exponent)
93
+ if (this.exponent - intExp !== 0) {
94
+ let deExp = this.exponent - intExp
95
+ this.mantissa *= 10 ** deExp
96
+ this.exponent = intExp
97
+ }
98
+ this.update()
99
+ return [this.mantissa, this.exponent]
100
+ }
101
+ log10() {
102
+ return Math.log10(this.mantissa) + this.exponent
103
+ }
104
+ log2() {
105
+ return Math.log2(this.mantissa) + this.exponent * Math.log2(10)
106
+ }
107
+ ln() {
108
+ return Math.log(this.mantissa) + this.exponent * Math.log(10)
109
+ }
110
+ async abs() {
111
+ if (this.mantissa < 0) {this.mantissa = -this.mantissa}
112
+ await this.fix()
113
+ this.update()
114
+ return [this.mantissa, this.exponent]
115
+ }
116
+ lessThan(mant, exp) {
117
+ if (this.exponent < exp) {return true}
118
+ else if (this.exponent > exp) {return false}
119
+ else if (this.mantissa < mant) {return true}
120
+ return false
121
+ }
122
+ greaterThan(mant, exp) {
123
+ if (this.exponent > exp) {return true}
124
+ else if (this.exponent < exp) {return false}
125
+ else if (this.mantissa > mant) {return true}
126
+ return false
127
+ }
128
+ equalTo(mant, exp) {
129
+ if (this.exponent === exp && this.mantissa === mant) {return true}
130
+ else {return false}
131
+ }
132
+ async floor() {
133
+ this.mantissa = Math.floor(this.mantissa)
134
+ await this.rfix()
135
+ this.update()
136
+ return [this.mantissa, this.exponent]
137
+ }
138
+ async ceiling() {
139
+ this.mantissa = Math.ceil(this.mantissa)
140
+ await this.fix()
141
+ this.update()
142
+ return [this.mantissa, this.exponent]
143
+ }
144
+ async round() {
145
+ if (this.mantissa < 5.50) {await this.floor()}
146
+ else {await this.ceiling()}
147
+ this.update()
148
+ return [this.mantissa, this.exponent]
149
+ }
150
+ toNumber() {
151
+ if (this.lessThan(1.78,308)) {return this.mantissa * 10 ** this.exponent}
152
+ else {return null}
153
+ }
154
+ seeNumber() {
155
+ return this.number
156
+ }
157
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 unmraindow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # InfinityPlus
2
+ A simple big number library that shouldnt be hard to understand.
3
+ ## Features
4
+ 1. Number storage beyond 1.79e308
5
+ 2. Big number calculations
6
+ 3. Scientific Notation
7
+ 4. Browser Safe operations (async)
8
+ 5. Simple and readable
9
+ ## Documentation
10
+ I shall teach you how to use InfinityPlus, but first:
11
+ ## How to install
12
+ in the terminal, use `npm install infinityplus`, then, in a js file, write
13
+ ```js
14
+ import InfinityPlus from "infinityplus"
15
+ ```
16
+ ## Instanciating the InfinityPlus class
17
+ This is quite simple but its different from Break_infinity.js
18
+ To create an infinityplus class instance:
19
+ ```js
20
+ import InfinityPlus from "infinityplus"
21
+ let variable = new InfinityPlus(2,9)
22
+ ```
23
+ The first number in the Constructor is the mantissa and the second number is the exponent
24
+ Once you do this you can do:
25
+ ```js
26
+ console.log(variable.mantissa) // to see mantissa
27
+ console.log(variable.exponent) // to see exponent
28
+ console.log(variable.number) // to see the full number, you can also use console.log(variable.seeNumber())
29
+ ```
30
+ # InfinityPlus methods
31
+ ## .fix()
32
+ ```js
33
+ variable.fix()
34
+ ```
35
+ This method is used to increase the exponent when the mantissa goes above 10,
36
+ you can just call the method as it does all the necessary calculations.
37
+ **Returns a Promise that contains an array that contains the mantissa and exponent after using fix()** (like [mantissa, exponent])
38
+ ## .rfix()
39
+ ```js
40
+ variable.rfix()
41
+ ```
42
+ This method is used to decrease the exponent when the mantissa is below 1, just call the method and it does everything necessary. **Also returns a Promise that contains an array that contains the mantissa and exponent after using rfix()**
43
+ ## await .add(mantissa, exponent) (async)
44
+ from this point on, some methods are async to protect the browser and wait for fix() and rfix(), if using any async methods. ***PLEASE USE AWAIT***
45
+ ```js
46
+ // dont forget to put await
47
+ let num = new InfinityPlus(1,5)
48
+ await num.add(4,4) // 1e5 + 4e4
49
+ console.log(num.number) // 1.40e5
50
+
51
+ let num2 = new InfinityPlus(3,5)
52
+ await num2.add(num.mantissa, num.exponent) // 3e5 + 1.40e5
53
+ console.log(num2.number) // 4.40e5
54
+ ```
55
+ `add()` accepts 2 parameters: `add(mantissa, exponent)`. This adds 2 numbers from InfinityPlus. You can either put values in or use values from another instance of InfinityPlus, for more understanding, refer to the example above.**Returns an array containing the mantissa and exponent after the operation([mantissa, exponent])**
56
+ ## await .subtract(mantissa, exponent) (async)
57
+ ```js
58
+ let num = new InfinityPlus(1,5)
59
+ await num.subtract(4,4) // 1e5 - 4e4
60
+ console.log(num.number) // 6e4
61
+
62
+ let num2 = new InfinityPlus(3,5)
63
+ await num2.subtract(num.mantissa, num.exponent) // 3e5 - 6e4
64
+ console.log(num2.number) // 2.40e5
65
+ ```
66
+ `subtract()` accepts 2 parameters: `subtract(mantissa, exponent)` this minuses 2 numbers from InfinityPlus, you can manually input values into the method or use values from another instance of InfinityPlus, for more understanding, refer to the above example.**Returns an array containing the mantissa and exponent after the operation([mantissa, exponent])**
67
+ ## await .multiply(mantissa, exponent) (async)
68
+ ```js
69
+ let num = new InfinityPlus(1,432)
70
+ await num.multiply(1,100) // 1e432 * 1e100
71
+ console.log(num.number) // 1e532
72
+
73
+ let num2 = new InfinityPlus(3,500)
74
+ await num2.multiply(num.mantissa, num.exponent) // 3e500 * 1e532
75
+ console.log(num2.number) // 3e1032
76
+ ```
77
+ `multiply()` accepts 2 parameters: `multiply(mantissa, exponent)` this multiplies 2 numbers from InfinityPlus, you can manually input values into the method or use values from another instance of InfinityPlus, for more understanding, refer to the above example.**Returns an array containing the mantissa and exponent after the operation([mantissa, exponent])**
78
+ ## await .divide(mantissa, exponent) (async)
79
+ ```js
80
+ let num = new InfinityPlus(1,432)
81
+ await num.divide(1,60) // 1e432 / 1e60
82
+ console.log(num.number) // 1e372
83
+
84
+ let num2 = new InfinityPlus(3,500)
85
+ await num2.divide(num.mantissa, num.exponent) // 3e500 / 1e372
86
+ console.log(num2.number) // 3e128
87
+ ```
88
+ `divide()` accepts 2 parameters: `divide(mantissa, exponent)` this divides 2 numbers from InfinityPlus, you can manually input values into the method or use values from another instance of InfinityPlus, for more understanding, refer to the above example.**Returns an array containing the mantissa and exponent after the operation([mantissa, exponent])**
89
+ ## await .power(exponent) (async)
90
+ ```js
91
+ let num = new InfinityPlus(1,432)
92
+ await num.power(2) // 1e432 squared
93
+ console.log(num.number) // 1e864
94
+ ```
95
+ power(exponent) accepts an exponent and raises the InfinityPlus number with the exponent.**Returns an array containing the mantissa and exponent after the operation([mantissa, exponent])**
96
+ ## await .root(n) (async)
97
+ ```js
98
+ let num = new InfinityPlus(1,432)
99
+ await num.root(2) // square root of 1e432
100
+ console.log(num.number) // 1e216
101
+ ```
102
+ root(n) takes 1 argument, n, takes the n-th root of a InfinityPlus number. yes that also means:
103
+ ```js
104
+ let num = new InfinityPlus(1,10000)
105
+ await num.root(1000) // 1000-th root of 1e10000
106
+ console.log(num.number) // 1e10
107
+ ```
108
+ **Returns an array containing the mantissa and exponent after the operation([mantissa, exponent])**
109
+ ## .log10()
110
+ ```js
111
+ let num = new InfinityPlus(3,90)
112
+ let result = num.log10() // log10(3e90)
113
+ console.log(result) // log10(3e90) = 90.47712125471966
114
+ ```
115
+ **Note that .log10(), .ln() and .log2() isnt async**, .log10() returns the log10 of a InfinityPlus number
116
+ ## .ln()
117
+ ```js
118
+ let num = new InfinityPlus(3,90)
119
+ let result = num.ln() // ln(3e90)
120
+ console.log(result) // ln(3e90) = 208.33127065813224
121
+ ```
122
+ .ln() returns the natural log of a InfinityPlus number
123
+ ## .log2()
124
+ ```js
125
+ let num = new InfinityPlus(3,90)
126
+ let result = num.log2() // log2(3e90)
127
+ console.log(result) // log2(3e90) = 300.5584910405837
128
+ ```
129
+ .log2() returns the log2 of a InfinityPlus number
130
+ ## await .abs() (async)
131
+ ```js
132
+ let num = new InfinityPlus(-5,10)
133
+ await num.abs()
134
+ console.log(num.number) // 5e10
135
+ ```
136
+ .abs() turns an InfinityPlus number into its absolute value. **Returns a mantissa,exponent array**
137
+ ## .lessThan(mantissa, exponent)
138
+ ```js
139
+ let num = new InfinityPlus(3,90)
140
+ console.log(num.lessThan(5,45)) // 3e90 < 5e45 = false
141
+ console.log(num.lessThan(2,92)) // 3e90 < 2e92 = true
142
+ ```
143
+ Checks if the InfinityPlus number on the left is less than the number on the right, not async.**Returns true or false**
144
+ ## .greaterThan(mantissa, exponent)
145
+ ```js
146
+ let num = new InfinityPlus(3,90)
147
+ console.log(num.greaterThan(5,45)) // 3e90 > 5e45 = true
148
+ console.log(num.greaterThan(2,92)) // 3e90 > 2e92 = false
149
+ ```
150
+ Checks if the InfinityPlus number on the left is greater than the number on the right, not async. **Returns true or false**
151
+ ## .equalTo(mantissa, exponent)
152
+ ```js
153
+ let num = new InfinityPlus(3,90)
154
+ console.log(num.equalTo(3,90)) // 3e90 === 3e90 = true
155
+ console.log(num.equalTo(2,92)) // 3e90 === 2e92 = false
156
+ ```
157
+ Checks if the InfinityPlus number on the left is equal to the number on the right, not async. **Returns true or false**
158
+ ### Creating less than or equal to and greater than or equal to
159
+ ```js
160
+ // less than or equal to
161
+ let num = new InfinityPlus(2,89) // 2e89
162
+ console.log(num.lessThan(2,89) || num.equalTo(2,89)) // true, this is 2e89 <= 2e89
163
+
164
+ // greater than or equal to
165
+ let num2 = new InfinityPlus(1,897)
166
+ console.log(num2.greaterThan(1,765) || num2.equalTo(1,765)) // true, this is 1e897 >= 1e765
167
+ ```
168
+ This can also be used in conditional statements
169
+ ## await .floor() (async)
170
+ ```js
171
+ let num = new InfinityPlus(3.87,70)
172
+ await num.floor()
173
+ console.log(num.number) // 3e70 (3.87e70 -> 3e70)
174
+ ```
175
+ This rounds down an InfinityPlus number.**Returns [mantissa, exponent]**
176
+ ## await .ceiling() (async)
177
+ ```js
178
+ let num = new InfinityPlus(3.32,70)
179
+ await num.ceiling()
180
+ console.log(num.number) // 4e70 (3.32e70 -> 4e70)
181
+ ```
182
+ This rounds up an InfinityPlus number.**Returns [mantissa, exponent]**
183
+ ## await round() (async)
184
+ ```js
185
+ let num = new InfinityPlus(2.7,90)
186
+ await num.round()
187
+ console.log(num.number) // 2e90
188
+
189
+ let num2 = new InfinityPlus(6.2, 34)
190
+ await num2.round()
191
+ console.log(num2.number) // 7e34
192
+
193
+ let num3 = new InfinityPlus(5.5, 22)
194
+ await num3.round()
195
+ console.log(num3.number) // 6e22
196
+ ```
197
+ .round() rounds a number to the nearest mantissa. if the mantissa is less than 5.50, it rounds down and if the mantissa is >= 5.50, it rounds up.
198
+ ## .seeNumber()
199
+ ```js
200
+ let num = new InfinityPlus(3,7832)
201
+ number = num.seeNumber()
202
+ console.log(number) // 3e7832
203
+ ```
204
+ seeNumber() returns the value of the .number property.
205
+ ## .toNumber()
206
+ ```js
207
+ let num = new InfinityPlus(3,90)
208
+ number = num.toNumber()
209
+ console.log(number) // 3e+90
210
+ ```
211
+ .toNumber() turns an InfinityPlus number into the native js Number type if the InfinityPlus number is less than 1.79e308. If the number is higher than 1.79e308, .toNumber() returns null because converting would give Infinity, use .seeNumber() or .number to see numbers beyond infinity
212
+ # Things to note
213
+ - Since the Constructor takes 2 arguments, **every InfinityPlus number must be created in scientific notation**, use .toNumber() to convert it if its below 1.79e308.
214
+ - You can't chain operations because of returning a result or an array
215
+ - Don't forget to use await for all async operations for consistency
216
+ - All methods except .log10(), .ln(), .log2(), .lessThan(), .greaterThan(), .equalTo(), .toNumber() and .seeNumber() automatically use .fix() and .rfix() so there is so need to use .fix() and .rfix() again
217
+ ## License
218
+ MIT
package/desktop.ini ADDED
@@ -0,0 +1,2 @@
1
+ [LocalizedFileNames]
2
+ InfinityPlus.mjs=@InfinityPlus,0
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "infinityplus",
3
+ "version": "1.0.0",
4
+ "description": "A simple big number library that shouldnt be hard to understand",
5
+ "main": "InfinityPlus.mjs",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": ["big-number", "scientific-notation","library", "math", "beyond-infinity", "simple", "exponent", "mantissa"],
10
+ "author": "unmraindow",
11
+ "license": "MIT",
12
+ "type": "module"
13
+ }