@lvlte/ulp 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +44 -0
- package/dist/cjs/package.json +3 -0
- package/package.json +12 -8
- package/readme.md +9 -3
- /package/dist/{index.cjs → cjs/index.js} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The smallest positive normal number representable by IEEE-754 float64.
|
|
3
|
+
*/
|
|
4
|
+
export declare const FLOAT64_MIN: number;
|
|
5
|
+
/**
|
|
6
|
+
* Return the unit in the last place or unit of least precision (ulp) of x, that
|
|
7
|
+
* is, the distance between two consecutive representable floating-point numbers
|
|
8
|
+
* at x. If x is a power of 2, the distance on either side of x is different, in
|
|
9
|
+
* which case the larger distance is returned.
|
|
10
|
+
*
|
|
11
|
+
* @param x The input number (default: 1)
|
|
12
|
+
* @returns The ulp of x, or `NaN` if `x` is not a finite number.
|
|
13
|
+
*/
|
|
14
|
+
export declare function eps(x?: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* @borrows eps as ulp
|
|
17
|
+
*/
|
|
18
|
+
export declare const ulp: typeof eps;
|
|
19
|
+
/**
|
|
20
|
+
* Exponent of a normalized floating-point number x.
|
|
21
|
+
*
|
|
22
|
+
* @param x The input number
|
|
23
|
+
* @returns The largest integer `y` such that `2^y ≤ |x|`. If `x` is not a
|
|
24
|
+
* finite number or equals ±0, returns `NaN`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function exponent(x: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Return the smallest representable floating-point number that comes after `x`
|
|
29
|
+
* on the float64 number line (towards +∞).
|
|
30
|
+
*
|
|
31
|
+
* @param x The input number
|
|
32
|
+
* @returns The smallest floating-point number `y` such that `y > x`. If `x` is
|
|
33
|
+
* `±Infinity` or `NaN`, returns `x`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function nextFloat(x: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Return the largest representable floating-point number that comes before `x`
|
|
38
|
+
* on the float64 number line (towards -∞).
|
|
39
|
+
*
|
|
40
|
+
* @param x The input number
|
|
41
|
+
* @returns The largest floating-point number `y` such that `y < x`. If `x` is
|
|
42
|
+
* `±Infinity` or `NaN`, returns `x`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function prevFloat(x: number): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvlte/ulp",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Compute the ULP of a given number / Get the closest representable number that comes before/after it on the float64 number line",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eric Lavault <lvlte.code@gmail.com>",
|
|
@@ -9,13 +9,17 @@
|
|
|
9
9
|
"url": "git+https://github.com/lvlte/ulp.git"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"main": "./dist/index.
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
12
|
+
"main": "./dist/cjs/index.js",
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/cjs/index.d.ts",
|
|
21
|
+
"default": "./dist/cjs/index.js"
|
|
22
|
+
}
|
|
19
23
|
}
|
|
20
24
|
},
|
|
21
25
|
"engines": {
|
|
@@ -28,8 +32,8 @@
|
|
|
28
32
|
"test": "jest",
|
|
29
33
|
"prebuild": "rimraf dist && make-dir dist",
|
|
30
34
|
"build": "tsc && tsc -p tsconfig-cjs.json",
|
|
31
|
-
"postbuild": "
|
|
32
|
-
"prepublishOnly": "npm test && npm run build && tsc --emitDeclarationOnly true --removeComments false"
|
|
35
|
+
"postbuild": "(echo { && echo \"type\": \"commonjs\" && echo }) > ./dist/cjs/package.json",
|
|
36
|
+
"prepublishOnly": "npm test && npm run build && tsc --emitDeclarationOnly true --removeComments false && tsc -p tsconfig-cjs.json --emitDeclarationOnly true --removeComments false"
|
|
33
37
|
},
|
|
34
38
|
"keywords": [
|
|
35
39
|
"number",
|
package/readme.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# ulp (epsilon function)
|
|
2
2
|
|
|
3
|
-
> Compute the [
|
|
4
|
-
of a given IEEE-754 64-bit number
|
|
3
|
+
> Compute the [ULP](https://en.wikipedia.org/wiki/Unit_in_the_last_place)
|
|
4
|
+
of a given IEEE-754 64-bit number: `eps(x)` (alias: `ulp(x)`).<br>
|
|
5
5
|
> Get the closest representable number that comes before/after it on the float64
|
|
6
|
-
number line
|
|
6
|
+
number line: `nextFloat(x)`, `prevFloat(x)`.
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
## Install
|
|
@@ -14,6 +14,8 @@ npm install @lvlte/ulp
|
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
+
### Import
|
|
18
|
+
|
|
17
19
|
```js
|
|
18
20
|
// ESM
|
|
19
21
|
import { eps, nextFloat, prevFloat } from '@lvlte/ulp';
|
|
@@ -22,6 +24,8 @@ import { eps, nextFloat, prevFloat } from '@lvlte/ulp';
|
|
|
22
24
|
// CJS
|
|
23
25
|
const { eps, nextFloat, prevFloat } = require('@lvlte/ulp');
|
|
24
26
|
```
|
|
27
|
+
|
|
28
|
+
### eps(x) / ulp(x) (alias)
|
|
25
29
|
```js
|
|
26
30
|
console.log( eps() ); // 2.220446049250313e-16
|
|
27
31
|
console.log( eps() === eps(1) ); // true
|
|
@@ -35,6 +39,8 @@ console.log( eps(0) === Number.MIN_VALUE ); // true
|
|
|
35
39
|
|
|
36
40
|
console.log( eps(Infinity) ); // NaN
|
|
37
41
|
```
|
|
42
|
+
|
|
43
|
+
### nextFloat(x) / prevFloat(x)
|
|
38
44
|
```js
|
|
39
45
|
console.log( nextFloat(0) ); // 5e-324
|
|
40
46
|
console.log( nextFloat(0) === Number.MIN_VALUE ); // true
|
|
File without changes
|