1.1.1 • Published 3 years ago

decimalsystem v1.1.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

How?

Using the library is simple. For example, to convert a number to base sqrt(2) is simple:

import {Num} from "decimalsystem";

new Num(9).toBase(Math.sqrt(2)).toString(); //1000000.1001

And to convert it back:

import {Num} from "decimalsystem";

new Num({num: "1000000.1001", base: Math.sqrt(2)}).toBase(10).toString(); //8.957106781186551 (close enough)

Why?

Non-integer number systems are pretty interesting, and the Wikipedia Article (which was very unhelpful towards the development of this library) on the subject is fairly limited. Other than that, there are (to my knowledge) no libraries available to convert to non-integer number systems. So I made this to solve that issue.

Installation

To install it, simply run npm install decimalsystem, then use it with:

import {Num} from "decimalsystem";

Look at the usage instructions above for more information on how to use it.

Notation

While currently not supported, special notation will be used for negative numbers. Any negative sign at the start of a number signifies that it is a negative number. If some of its digits are negative and others are positive, it will not include a negative sign at the beginning of the number. For example, -100 and 1[-1]2 are valid, but -1[-2]3 is not.

Acknowledgments

https://chridd.nfshost.com/convert/original was extremely helpful towards removing decimals from digits (7ed5bcb) as it provided examples of small numbers in non-integer bases which were used to modify the algorithm for converting to non-integer bases to increase precision and remove decimals from digits.