# almost-equal

> Test if two floats are almost equal

Latest version **1.1.0** (published 2016-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install almost-equal
pnpm add almost-equal
yarn add almost-equal
bun add almost-equal
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-03-09 |
| First published | 2013-04-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/almost-equal) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Mikola Lysenko |
| Maintainers | dfcreative, hughsk, jaspervdg, mikolalysenko, planeshifter, rreusser, substack |
| Keywords | float, compare, double, round, equal, almost, near, tolerance, epsilon, FLT_EPSILON, DBL_EPSILON |

## Links

- npm: https://www.npmjs.com/package/almost-equal
- Repository: https://github.com/mikolalysenko/almost-equal
- Homepage: https://github.com/mikolalysenko/almost-equal#readme
- Issues: https://github.com/mikolalysenko/almost-equal/issues
- npm.io page: https://npm.io/package/almost-equal

## Recent versions

- 1.1.0 (latest) — 2016-03-09
- 1.0.0 — 2015-05-15
- 0.0.0 — 2013-04-03

## README

almost-equal
============
Checks when two floats are almost equal.

Use
===
First install using npm:

    npm install almost-equal
    
Then use as follows:

```javascript
var almostEqual = require("almost-equal")

var a = 100
  , b = 100 + 1e-12

//Check if a == b up to float precision
console.log(almostEqual(a, b, almostEqual.FLT_EPSILON, almostEqual.FLT_EPSILON))

//Check if a == b up to double precision
console.log(almostEqual(a, b, almostEqual.DBL_EPSILON, almostEqual.DBL_EPSILON))
```

### `almostEqual(a, b[, absoluteTolerance [, relativeTolerance]])`
Checks if two floats are within the given tolerances of one another using the formula:

    |a - b| < max(absoluteTolerance, min(|a|, |b|) * relativeTolerance)

* `a` and `b` are the two numbers to comapre
* `absoluteTolerance` is a fixed minimal tolerance (set to 0 to ignore)
* `relativeTolerance` is a tolerance that scales with a/b (set to 0 to ignore)

**Returns** `true` if `a` and `b` are approximately equal.

If tolerance argument is omitted, `almostEqual.DBL_EPSILON` value is used by default.

### `almostEqual.FLT_EPSILON`
Floating point (32-bit) epsilon

### `almostEqual.DBL_EPSILON`
Double precision (64-bit) epsilon

Credits
=======
(c) 2013 Mikola Lysenko. MIT License

---
_Source: https://npm.io/package/almost-equal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
