Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 2.56 KB

README.md

File metadata and controls

41 lines (35 loc) · 2.56 KB

Decimal System

CodeFactor Codecov Build Downloads

DecimalSystem is a powerful base conversion library that can convert any (real) number to any base (over 1), including non-integer bases like base PI.

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.