https://github.com/lazarljubenovic/epsicheck
A set of functions for comparing floating point numbers.
https://github.com/lazarljubenovic/epsicheck
Last synced: about 1 month ago
JSON representation
A set of functions for comparing floating point numbers.
- Host: GitHub
- URL: https://github.com/lazarljubenovic/epsicheck
- Owner: lazarljubenovic
- Created: 2023-11-03T22:08:13.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-11-05T15:30:55.000Z (over 1 year ago)
- Last Synced: 2023-11-05T23:27:44.150Z (over 1 year ago)
- Language: TypeScript
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# epsicheck
Five simple utilities for comparing two floating point numbers, each with a short alias:
- `equal` or `eq`,
- `lessThan` or `lt`,
- `lessThanOrEqual` or `lte`,
- `greaterThan` or `gt`, and
- `greaterThanOrEqual` or `gte`.The default epsilon is `1e-6` and can be customized using the third parameter.
## Functions Overview
| **`a, b`** | **`eq(a, b)`** | **`lt(a, b)`** | **`lte(a, b)`** | **`gt(a, b)`** | **`gte(a, b)`** |
|---------------|:------------------:|:------------------:|:------------------:|:------------------:|:------------------:|
| `1, 2` | | :white_check_mark: | :white_check_mark: | | |
| `1, 1 + 1e-5` | | :white_check_mark: | :white_check_mark: | | |
| `1, 1 + 1e-7` | :white_check_mark: | | :white_check_mark: | | :white_check_mark: |
| `1, 1` | :white_check_mark: | | :white_check_mark: | | :white_check_mark: |
| `1 + 1e-7, 1` | :white_check_mark: | | :white_check_mark: | | :white_check_mark: |
| `1 + 1e-5, 1` | | | | :white_check_mark: | :white_check_mark: |
| `2, 1` | | | | :white_check_mark: | :white_check_mark: |The above table is assuming the default epsilon of `1e-6`.
## Installation & Usage
```shell
$ npm i epsicheck
``````ts
import { eq } from 'epsicheck'console.assert(eq(0.1 + 0.2, 0.3))
console.assert(0.1 + 0.2 != 0.3)
```