true-math

1.1.1 • Public • Published

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:

Num Return
NaN NaN
±Inf Inf

ceil(num: string): string

If number has decimal part then returns the closest next integer

Table of specific values:

Num Return
NaN NaN
±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):

Num1 Num2 Return
NaN Any NaN
Inf ±Inf Inf
Inf Number Inf
-Inf -Inf -Inf
-Inf Number Number

difference(nums: [string]): string

Returns difference of first number and others

Table of specific values:

Num1 Num2 Return
NaN Any NaN
Any NaN NaN
Inf Inf NaN
Inf -Inf Inf
-Inf Inf -Inf
-Inf -Inf NaN
±Inf Number ±Inf
Number ±Inf ∓Inf

floor(num: string): string

If number has decimal part then returns the closest previous integer

Table of specific values:

Num Return
NaN NaN
±Inf ±Inf

product(nums: [string]): string

Returns product of first number and others

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

Num1 Num2 Return
NaN Any NaN
Inf ±Inf ±Inf
Inf ±Number ±Inf
-Inf ±Inf ∓Inf
-Inf ±Number ∓Inf
±Inf 0 NaN

sum(nums: [string]): string

Returns sum of first number and others

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

Num1 Num2 Return
NaN Any NaN
Inf Inf Inf
Inf -Inf NaN
-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:

Num1 Num2 Return
NaN Any NaN
Any NaN NaN
Inf ±Number ±Inf
-Inf ±Number ∓Inf
±Inf ±Inf NaN
±Inf 0 ±Inf
0 ±Inf 0
±Number 0 ±Inf
0 0 NaN

License

GPL-3.0-only

Package Sidebar

Install

npm i true-math

Weekly Downloads

1

Version

1.1.1

License

GPL-3.0-only

Unpacked Size

61.5 kB

Total Files

38

Last publish

Collaborators

  • ezio_mercer