All Projects → Patashu → break_infinity.js

Patashu / break_infinity.js

Licence: MIT license
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.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to break infinity.js

klibcpp
kedixa's Cplusplus Library(timer, multiarray, unsigned_bigint, bigint, rational)
Stars: ✭ 17 (-88.28%)
Mutual labels:  bignum, biginteger, bignumber
as-bignum
Fixed length big numbers for AssemblyScript 🚀
Stars: ✭ 49 (-66.21%)
Mutual labels:  bignum, biginteger, bigdecimal
decimal
An arbitrary-precision decimal floating-point arithmetic package for Go
Stars: ✭ 28 (-80.69%)
Mutual labels:  bignum, decimal
nein-math
NeinMath is playing around with arbitrary precision integers, written in pure managed code, not using any unsafe stuff, and a bit faster than the build-in .NET type for integers with a few thousand bits.
Stars: ✭ 14 (-90.34%)
Mutual labels:  biginteger, bignumber
ChangeNumbersJs
Tiny Library for change number from a language in other language.
Stars: ✭ 14 (-90.34%)
Mutual labels:  numbers, number
totominc.github.io
Old repo for my old learning projects (mostly incremental-games).
Stars: ✭ 57 (-60.69%)
Mutual labels:  incremental-game, idle-game
Big.js
A small, fast JavaScript library for arbitrary-precision decimal arithmetic.
Stars: ✭ 3,730 (+2472.41%)
Mutual labels:  bigdecimal, bignumber
Bignumber.js
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic
Stars: ✭ 5,174 (+3468.28%)
Mutual labels:  bigdecimal, bignumber
BigNumber
A really long long long long long long number in C++
Stars: ✭ 37 (-74.48%)
Mutual labels:  biginteger, bignumber
BhimIntegers
BhimIntegers🚀 is a C++ library that is useful when we are dealing with BigIntegers💥💥. We can handle big integers (integers having a size bigger than the long long int data type) and we can perform arithmetic operations📘 like addition, multiplication, subtraction, division, equality check, etc📐📐. Also, there are several functions like factorial, …
Stars: ✭ 43 (-70.34%)
Mutual labels:  biginteger, bignumber
js-big-decimal
Work with large numbers on the client side with high precision.
Stars: ✭ 41 (-71.72%)
Mutual labels:  decimal, bigdecimal
AutoTrimps
AutoTrimps - Zek
Stars: ✭ 37 (-74.48%)
Mutual labels:  incremental-game, idle-game
SurrealNumbers.jl
Implementation of Conway's Surreal Numbers
Stars: ✭ 30 (-79.31%)
Mutual labels:  numbers, number
Decimal.js
An arbitrary-precision Decimal type for JavaScript
Stars: ✭ 4,585 (+3062.07%)
Mutual labels:  bigdecimal, bignumber
GiantShaftEnterprises
Incremental idle game about building businesses and shaft mining asteroids....and maybe conquering the galaxy along the way.
Stars: ✭ 41 (-71.72%)
Mutual labels:  incremental-game, idle-game
beerplop
Repository for the incremental game Beerplop
Stars: ✭ 17 (-88.28%)
Mutual labels:  incremental-game, idle-game
continuum-engine
A Javascript engine to power incremental and idle games
Stars: ✭ 45 (-68.97%)
Mutual labels:  incremental-game, idle-game
BigInteger
Be limited not by the size of your register but by the bulk of your RAM.
Stars: ✭ 13 (-91.03%)
Mutual labels:  biginteger, bignumber
swift-numberkit
Advanced numeric data types for Swift 5, including BigInt, Rational, and Complex numbers.
Stars: ✭ 47 (-67.59%)
Mutual labels:  numbers, biginteger
hebimath
arbitrary precision arithmetic library
Stars: ✭ 37 (-74.48%)
Mutual labels:  bignum, bignumber

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

You can use break_infinity.js directly from a CDN via a script tag:

    <!-- You can load it as a minified file (recommended) -->
    <script src="https://cdn.jsdelivr.net/npm/break_infinity.js"></script>

    <!-- ...or as a non-minified file (for debugging) -->
    <script src="https://cdn.jsdelivr.net/npm/break_infinity.js/dist/break_infinity.js"></script>

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).

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 with these benchmarks link link:

Project decimal.js break_infinity.js Speedup
new Decimal("1.23456789e987654321") 1.6e6 4.5e6 2.8x
Decimal.add("1e999", "9e998") 1.3e6 3.2e6 2.5x
Decimal.mul("1e999", "9e998") 1.3e6 3.8e6 2.9x
Decimal.log10("987.654e789") 3.9e4 4.7e6 121x
Decimal.exp(1e10) 1.1e4 4.3e6 401x
Decimal.pow(987.789, 123.321) 1.3e4 5.8e6 442x

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 ci

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.

Other Number Libraries

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].