1.0.1 • Published 6 years ago

stringy_numbers v1.0.1

Weekly downloads
3
License
ISC
Repository
-
Last release
6 years ago

Stringy Numbers

see stringy_numbers repo on github

Introduction

Stringy Numbers is a lightweight javascript library that allows basic maths operations on very large numbers.

It works by using strings to bypass javascripts limitation on number sizes. Numbers are input into functions as strings, ie. you have to enclose them in quotes as you would a string. The operations support floating point.

Installation

from terminal,

npm i stringy_numbers

to import..

const {mult,div,add,minus,squared,cubed} = require('path/to/node_modules/stringy_numbers')

Functions

As of version 1.0.1 there are four basic maths operations available:

-mult() - multiplication, -div() - division, -add() - addition, -minus() - subtraction

And now sqaured and cubed functions added:

-squared() - find the square of a number -cubed() - find the cube of a number

mult() takes two string numbers as arguments, multiplies them together and returns the result as a string

e.g

mult("1234","5678");
'7006652' 

div() takes a number as its first argument, this sets the precision number of significant digits for the answer, the next two arguments are the dividend and divisor in that order, entered as strings. e.g

div(10,"1234","5678");
' .2173300457907' 

Note: the leading zero is omitted in answers that are less than one. however answers can be input with leading or trailing 0s.

add() takes two string numbers as arguments, adds them together and returns the result as a string e.g

add("1234","5678");
'6912' 

minus() takes two string numbers as arguments, substracts the second from the first and returns teh result as a string. e.g

minus("1234","5678");
'-4444' 

There is also a test() function that will run two given numbers through each of the maths operations and compare them with the output of javascripts equivalent native operation, e.g.

test(404,3)

logs the following to the console..

-----------------------------------------------
|              BIG FLOAT TEST                  |
-----------------------------------------------
MY MULT:   1212
NATIVE JS: 1212
-----------------------------------------------
MY ADD:    407
NATIVE JS: 407
-----------------------------------------------
MY MINUS:    401
NATIVE JS: 401
-----------------------------------------------
MY DIV:    134.66666666666666666
NATIVE JS: 134.66666666666666 

Additional Notes

Negative numbers are supported simply by appending the string number with a '-' sign. Leading and Trailing zeros are permitted in entered numbers.