GithubHelp home page GithubHelp logo

bigint-factorial's People

Contributors

polarstoat avatar

Watchers

 avatar  avatar

bigint-factorial's Issues

Maximum call stack size exceeded with very large factorial calculations

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.

Accept input as type number

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.

Performance testing

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.

Throw a RangeError when passed negative input

Negative factorials cannot be computed.

The factorials of negative integers cannot be computed, since for n = 0, the recurrence relation,
(n-1)!=\frac{n!}{n},
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

Support ES module (ESM) import syntax

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.