polarstoat / bigint-factorial Goto Github PK
View Code? Open in Web Editor NEWTiny JS factorial function using BigInt
License: MIT License
Tiny JS factorial function using BigInt
License: MIT License
During the performance testing for #2 , it was discovered that very large factorial calculations using the current method of recursion can cause the call stack size to be exceeded.
A Stack Overflow answer suggests this can be fixed by wrapping the recursive function call in a setImmediate
function.
It's not yet known at exactly what size factorial calculation the maximum call stack size will be exceeded.
Currently the package only accepts input as type BigInt
, it would be potentially be more useful to also accept input as type Number
.
This would need checks to ensure the Number
is correctly converted to a BigInt
.
It may be faster to use a for
loop to calculate the factorial, rather than the current method of recursion.
Some basic performance testing should be done to find which is the fastest.
Negative factorials cannot be computed.
The factorials of negative integers cannot be computed, since for n = 0, the recurrence relation,
involves a division by zero. (Thukral, 2014)
However, the idea of applying the concept of factorials to negative integers has been raised before (Thukral, 2014), but there does not appear to be a consensus on how this should be done, or even if it can be done whilst still being considered a factorial. This kind of maths is highly complex and far beyond the scope of this package, so negative input should throw a RangeError
.
Thukral, A.K. Factorials of real negative and imaginary numbers - A new perspective. SpringerPlus 3, 658 (2014). https://doi.org/10.1186/2193-1801-3-658
Currently the package only supports the CommonJS style module.exports
syntax. Node.js (and modern browsers) now support ES modules natively, and have done for a while. Supporting this style of import could those using ES module syntax.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.