1.1.1 • Published 2 years ago

true-math v1.1.1

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
2 years ago

true-math

True Math - math library for numbers of arbitrary length

Install

npm install true-math --save

Usage

Just import need functions from true-math library and use them

Available functions:

Example

Import {needFuntions} from true-math in the file test.js

import {sum, subtract, ...} from 'true-math';

then call them like shown below:

const testData = ['0.1001', '0.0002'];

console.log('\nTest for:', testData);
console.log('Sum is : ', sum(testData));
console.log('Difference is : ', subtract(testData));

Documentation

Notations

NaN - Not a Number

Inf or +Inf - Infinity

-Inf - -Infinity

Any - Number or NaN or Inf or -Inf

-Number - Number < 0

+Number - Number > 0

Number - -Number or +Number or 0

Functions

abs(num: string): string

Returns absolute value of number

Table of specific values:

NumReturn
NaNNaN
±InfInf

ceil(num: string): string

If number has decimal part then returns the closest next integer

Table of specific values:

NumReturn
NaNNaN
±Inf±Inf

compare(num1: string, num2: string): string

Returns -1 if num1 < num2

Returns 0 if num1 = num2

Returns 1 if num1 > num2

Table of specific values (permutation does not change the result):

Num1Num2Return
NaNAnyNaN
Inf±InfInf
InfNumberInf
-Inf-Inf-Inf
-InfNumberNumber

difference(nums: [string]): string

Returns difference of first number and others

Table of specific values:

Num1Num2Return
NaNAnyNaN
AnyNaNNaN
InfInfNaN
Inf-InfInf
-InfInf-Inf
-Inf-InfNaN
±InfNumber±Inf
Number±InfInf

floor(num: string): string

If number has decimal part then returns the closest previous integer

Table of specific values:

NumReturn
NaNNaN
±Inf±Inf

product(nums: [string]): string

Returns product of first number and others

Table of specific values (permutation does not change the result):

Num1Num2Return
NaNAnyNaN
Inf±Inf±Inf
Inf±Number±Inf
-Inf±InfInf
-Inf±NumberInf
±Inf0NaN

sum(nums: [string]): string

Returns sum of first number and others

Table of specific values (permutation does not change the result):

Num1Num2Return
NaNAnyNaN
InfInfInf
Inf-InfNaN
-Inf-Inf-Inf
Number±Inf±Inf

quotient(nums: [string], accuracy: string): string

Returns quotient of first number and others

accuracy must be a non-negative integer number and equal '8' if not defined

Table of specific values:

Num1Num2Return
NaNAnyNaN
AnyNaNNaN
Inf±Number±Inf
-Inf±NumberInf
±Inf±InfNaN
±Inf0±Inf
0±Inf0
±Number0±Inf
00NaN

License

GPL-3.0-only

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago