https://github.com/abrie/ieee754
Typescript helpers to compare numbers by ULP distance.
https://github.com/abrie/ieee754
ieee754 javascript-library npm-package ulp
Last synced: 3 months ago
JSON representation
Typescript helpers to compare numbers by ULP distance.
- Host: GitHub
- URL: https://github.com/abrie/ieee754
- Owner: abrie
- License: mit
- Created: 2020-05-01T13:47:54.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T17:43:03.000Z (over 2 years ago)
- Last Synced: 2025-03-17T22:29:03.899Z (3 months ago)
- Topics: ieee754, javascript-library, npm-package, ulp
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@eirba/ieee754
- Size: 1.79 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IEEE754 ULP Comparision Utilities
A collection of functions to compare `Number` types by [ULP](https://en.wikipedia.org/wiki/Unit_in_the_last_place) distance.
- `ulpDistance(a:number,b:number):bigint`
- `ulpAlmostEqual(a:number, b:number, maxDistance:number):boolean`
- `ulpEqual(a:number, b:number):boolean`Note the use of `BigInt` to represent the ULP value of a `Number`. This is necessary because the library internally converts the float64 to a biased int64. See the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) for the syntax and limitations of BigInt numbers.
If you plan to use this library in unit tests, check out the [Jest companion library](https://github.com/abrie/jest-ieee754).
## Install
`yarn add eirba@ieee754`
or
`npm install eirba@ieee754`
## Import
## Example
```
import {ulpAlmostEqual} from 'eirbe@ieee754'const isTrue = ulpAlmostEqual(0.1+0.2, 0.3, 1n)
```