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.
You can use break_infinity.js directly from a CDN via a script tag:
<!-- You can load it as a minified file (recommended) -->
<!-- ...or as a non-minified file (for debugging) -->
or as a JS module using import
import Decimal from "break_infinity.js";
or as a Node.js module using require.
var Decimal = require("break_infinity.js");
For the module approaches, 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).
The library exports a single class Decimal, constructor of which accepts a
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")
Antimatter Dimensions script time improved by 4.5x after swapping from decimal.js to break_infinity.js. This could be your incremental game:
First, clone the repo
git clone git://github.com/Patashu/break_infinity.js.git
Then install npm dependencies
And then run build command which will build all targets to the dist directory.
npm run build
Dedicated to Hevipelle, and all the CPUs that struggled to run Antimatter Dimensions.
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.
Generated using TypeDoc