GithubHelp home page GithubHelp logo

hartl3y94 / decimalsystem Goto Github PK

View Code? Open in Web Editor NEW

This project forked from uellenberg/decimalsystem

0.0 0.0 0.0 2.19 MB

A library for converting numbers to any non-integer/decimal (or just integer) base.

Home Page: https://decimalsystem.js.org

License: Apache License 2.0

TypeScript 58.16% JavaScript 41.84%

decimalsystem's Introduction

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.

decimalsystem's People

Contributors

dependabot[bot] avatar uellenberg 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.