Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

almost-equal

Package Overview
Dependencies
Maintainers
7
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

almost-equal

Test if two floats are almost equal

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
215K
decreased by-0.76%
Maintainers
7
Weekly downloads
 
Created
Source

almost-equal

Checks when two floats are almost equal.

Use

First install using npm:

npm install almost-equal

Then use as follows:

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

Keywords

FAQs

Package last updated on 09 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc