Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eziomercer/true-math
https://github.com/eziomercer/true-math
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/eziomercer/true-math
- Owner: EzioMercer
- License: gpl-3.0
- Created: 2021-05-31T14:11:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-26T21:35:47.000Z (about 1 year ago)
- Last Synced: 2024-04-26T13:20:41.694Z (9 months ago)
- Language: JavaScript
- Size: 103 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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:
* [abs](#abs)
* [ceil](#ceil)
* [compare](#compare)
* [difference](#difference)
* [floor](#floor)
* [product](#product)
* [sum](#sum)
* [quotient](#quotient)## 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 othersTable 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