Git Product home page Git Product logo

js-bigint's Introduction

BigInt Build Status Image

Enables working with integers beyond 53 bits (the upper limit of what JavaScript's Number type can accurately represent).

This is a pure JavaScript library, unlike other libraries that do the same thing. The main benefit of being pure JavaScript is that you can use it in a browser environment:

Browser compatibility

For Node.js-only projects, consider looking into these C extensions:

Example

> var bigint = require('bigintjs');

> bigint('99999999999999999999999999999').add('1').toString();
'100000000000000000000000000000'

> bigint('123456789012345678901234567890').multiply('98765432109876543210987654321').toString();
'12193263113702179522618503273362292333223746380111126352690'

> // Bitwise operations on a big number (JavaScript only supports up to 32 bits)
> bigint('0xFFFFFFFFFFFFFFFF').and('0xF0F0F0F0F0F0F0F0').shiftLeft(8).toString();
'4444580219171430789120'

This project is in an early state

Some basic operations are still missing. Most notably:

  • Division (and modulus), but you can use bit shifting for powers of 2
  • Comparison (greater than / less than)
  • Square root

Feel free to submit a pull request for any of the above.

Using this package

You can install this package with NPM:

npm install --save bigintjs

To be able to run this in a browser, you need to use a framework that supports CommonJS modules (for example: Browserify).

js-bigint's People

Contributors

blixt avatar

Watchers

 avatar

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.