GithubHelp home page GithubHelp logo

tuncay / break_infinity.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from patashu/break_infinity.js

0.0 1.0 0.0 1.61 MB

A replacement for decimal.js for incremental games who want to deal with very large numbers (bigger in magnitude than 1e308, up to as much as 1e(9e15) ) and want to prioritize speed over accuracy.

License: MIT License

TypeScript 100.00%

break_infinity.js's Introduction

NPM

A replacement for https://github.com/MikeMcl/decimal.js/ for incremental games which need to deal with very large numbers (bigger in magnitude than 1e308, up to as much as 1e9e15) and want to prioritize speed over accuracy.

If you want to prioritize accuracy over speed, please use decimal.js instead.

NEW:

Load

The library is a single JavaScript file break_infinity.js (or minified, break_infinity.min.js) which can be found on https://github.com/Patashu/break_infinity.js/releases page.

It can be loaded using a script tag in an HTML document for the browser

    <script src="path/to/break_infinity.js"></script>

or as a Node.js module using require.

    var Decimal = require("break_infinity.js");

For Node, the library is available from the npm registry

    $ npm install --save break_infinity.js

If you are already using decimal.js, just swap out for break_infinity.js and everything will work the same (if there's a missing function or behavioural difference, open an issue and I'll take a look).

Use

The library exports a single class Decimal, constructor of which accepts a Number, String or Decimal.

    const x = new Decimal(123.4567);
    const y = new Decimal("123456.7e-3");
    const z = new Decimal(x);
    const equals = x.equals(y) && y.equals(z) && x.equals(z); // true

The methods that return a Decimal can be chained.

    const short = x.dividedBy(y).plus(z).times(9).floor();
    const long = x.times("1.23456780123456789e+9")
      .plus(9876.5432321)
      .dividedBy("4444562598.111772")
      .ceil();

For the complete list of functions refer to Typescript definitions, decimal.js docs or check out generated API docs

Benchmarks

So how much faster than decimal.js is break_infinity.js? Operations per second comparison using the same computer:

Project decimal.js break_infinity.js Speedup
new Decimal("1.23456789e987654321") 1.5e6 3e6 2x
Decimal.add("1e999", "9e998") 1.5e6 3e6 15x
Decimal.mul("1e999", "9e998") 1.5e6 3e6 66x
Decimal.pow(987.789, 123.321) 8e3 2e6 250x
Decimal.exp(1e10) 4e4 4.5e8 11250x
Decimal.log10("987.654e789") 3e4 5e8 16666x

Antimatter Dimensions script time improved by 4.5x after swapping from decimal.js to break_infinity.js. This could be your incremental game:

image

Build

First, clone the repo

git clone git://github.com/Patashu/break_infinity.js.git
cd break_infinity.js

Then install npm dependencies

npm install

And then run build command which will build all targets to the dist directory.

npm run build

Acknowledgements

Dedicated to Hevipelle, and all the CPUs that struggled to run Antimatter Dimensions.

Related song: https://soundcloud.com/patashu/8-bit-progressive-stoic-platonic-ideal

Special thanks to projects from which I have sourced code or ideas from:

Additional thanks to https://github.com/Razenpok for porting the code to TypeScript and cleaning up this README.

break_infinity.js's People

Contributors

patashu avatar razenpok avatar dependabot[bot] avatar 1234abcdcba4321 avatar edricchan03 avatar heinoustugboat avatar scorzy avatar dependabot-preview[bot] avatar garnet420 avatar

Watchers

James Cloos 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.