PHPackages                             jstewmc/almost-equals - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. jstewmc/almost-equals

ActiveLibrary

jstewmc/almost-equals
=====================

Compare floats for equality

v0.1.0(9y ago)117MITPHPPHP ^7.0

Since Mar 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jstewmc/almost-equals)[ Packagist](https://packagist.org/packages/jstewmc/almost-equals)[ RSS](/packages/jstewmc-almost-equals/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

almost-equals
=============

[](#almost-equals)

Compare floats for equality.

```
namespace Jstewmc\AlmostEquals;

// instantiate the service
$service = new AlmostEquals();

// compare stuff!
$service(1/10, 0.1);  // returns true (0.1 === 0.1)
$service(2/10, 0.1);  // returns false (0.2 !== 0.1)
```

Floating point numbers should never be compared for equivalence because of the way they are stored internally. They have limited precision, and many numbers that are representable as floating point numbers in base-10 (e.g., `0.1` or `0.7`) do not have an exact representation in base-2.

Epsilon
-------

[](#epsilon)

To test floating point values for equality, an upper bound on the relative error due to rounding is used. This value is known as the machine epsilon, and is the largest acceptable difference in calculations (exclusive).

The service's epsilon can be set on instantiation. If omitted, it will default to `0.00001`. Keep in mind, the epsilon value should be proportional to the differences in the values you're comparing. If very small differences matter to your application, use a very small epsilon.

```
namespace Jstewmc\AlmostEquals;

// defaults to an epsilon of 0.00001
$service = new AlmostEquals();

$service(1/10, 0.1);      // returns true
$service(0.10002, 0.1);   // returns false (0.00002 > 0.00001)
$service(0.100002, 0.1);  // returns true (0.000002 < 0.00001)
```

Integers
--------

[](#integers)

To increase ease-of-use, this library supports integer comparison as well. It will use PHP's default type coercion to convert integers to floats before comparison.

That's about it!

Author
------

[](#author)

[Jack Clayton](mailto:clayjs0@gmail.com)

License
-------

[](#license)

[MIT](https://github.com/jstewmc/almost-equals/blob/master/LICENSE)

Version
-------

[](#version)

### 0.1.0, March 5, 2017

[](#010-march-5-2017)

- Initial release

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3351d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/50fecae0a7fd2119681bc133e496e7166b01a59f850a3c909e100bd427c6b28b?d=identicon)[Jstewmc](/maintainers/Jstewmc)

---

Top Contributors

[![jstewmc](https://avatars.githubusercontent.com/u/1192893?v=4)](https://github.com/jstewmc "jstewmc (2 commits)")

---

Tags

phpequalitycomparefloatsjstewmc

### Embed Badge

![Health badge](/badges/jstewmc-almost-equals/health.svg)

```
[![Health](https://phpackages.com/badges/jstewmc-almost-equals/health.svg)](https://phpackages.com/packages/jstewmc-almost-equals)
```

###  Alternatives

[sebastian/comparator

Provides the functionality to compare PHP values for equality

7.0k879.8M145](/packages/sebastian-comparator)[icecave/parity

A customizable deep comparison library.

516.8M10](/packages/icecave-parity)[yncki/php-fast-image-compare

Image Comparer with different aspect ratios and sizes. Can extract duplicate and unique images in directory and much more.

1869.4k](/packages/yncki-php-fast-image-compare)[fjw/color-compare

A library for converting colors (Hex, RGB, HSL, CIELAB (LAB), DIN-99) and calculating color distances based on DIN-99.

1310.0k](/packages/fjw-color-compare)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
