Closed formula1 closed 2 years ago
Perhaps this is too ambitious at the moment. Would love some feedback but this isn't a priority and nobody probably is in dire need of any of these features.
I'll let the issues be real issues and let this sit. It can still be found if someone is interested
So, this is probably above my pay grade and probably not useful for most applications but...
bignumber.js
is impressive, it is still limitedbignumber.js
can handlebignumber.js
can handle a monster number, but after a test, yes it can : ) so I guess that can't be used as an excuseBasic Idea
For adds, multiplies and exponents greater than 1
For subtract, divides and exponents less than 1
Threading
Since the library is syncronous, it may be a good idea to run it in a background thread for absurd numbers. Maybe store the result number in the main thread but allow a background thread to do all the work. Additionally there may be the opportunity to offload adds to multiple threads, although we do need to handle overflow from a previous chunk to the next chunk making some operations needing to be done twice. What's nice is that threads are available in a variety of javascript environments. WebWorker, Child Process even react native has workers. I know people like immutable instances better than mutable but at least its a start.
Heres some incomplete code relating to some abstraction and convienience functions
Streams
Nested arrays make things interesting, threading makes things managable but streaming chunks take it to the next level. As a stream, instead of holding giant objects in memory, we can store them in one or multiple files. Instead of sending the entire workload for one worker to do, we can send a peice of work to each of them, get the return value, get the overflow, and send the overflow to the next worker available along with the work result of the next peice. After that, we can pipe the readable stream into a writable stream and that writable writes one or multiple files based off the chunks. Perhaps one NumberChunk per file. perhaps one ChunkHolder per file. Or if the person want to live dangerously, they can turn the stream into the a promise and turn the streaming number into an async big number. Each number that is being worked on could have its own description that gets saved to a folder. When the application loads up, it can read the folder and allow the mathmatician to continue where they left off without having to lose their mind.
I know this is kinda pie in the sky type thinking and I already like what this library is capable of. But I like progress and I think this library has a lot of potential.
A Monster Number in action
If anyones interested in BigNumber handling a monster number, heres some code to get it done. Big number seemed to be able to hande it without issue