Skip to content

Commit 2906134

Browse files
committed
feat: temp commit
1 parent 1199d15 commit 2906134

File tree

2 files changed

+11
-104
lines changed
  • lib/node_modules/@stdlib/number/float32/base/ulp-difference

2 files changed

+11
-104
lines changed

lib/node_modules/@stdlib/number/float32/base/ulp-difference/examples/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
'use strict';
2020

21-
var EPS = require( '@stdlib/constants/float64/eps' );
22-
var SMALLEST_SUBNORMAL = require( '@stdlib/constants/float64/smallest-subnormal' );
21+
var EPS = require( '@stdlib/constants/float32/eps' );
22+
var SMALLEST_SUBNORMAL = require( '@stdlib/constants/float32/smallest-subnormal' );
2323
var ulpdiff = require( './../lib' );
2424

2525
var d = ulpdiff( 1.0, 1.0+EPS );

lib/node_modules/@stdlib/number/float32/base/ulp-difference/lib/main.js

Lines changed: 9 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -24,114 +24,23 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2424
var SIGN_MASK = require( '@stdlib/constants/float32/sign-mask' );
2525
var toWordf = require( '@stdlib/number/float32/base/to-word' );
2626
var abs = require( '@stdlib/math/base/special/abs' );
27-
var Uint32Array = require( '@stdlib/array/uint32' );
28-
29-
30-
// VARIABLES //
31-
32-
var WX = new Uint32Array( 2 ); // WARNING: not thread safe
33-
var WY = new Uint32Array( 2 );
34-
var WZ = new Uint32Array( 2 );
35-
36-
// 2^32:
37-
var TWO_32 = 4294967296;
3827

3928

4029
// FUNCTIONS //
4130

4231
/**
43-
* Converts the high and low words of a single-precision floating-point number to a lexicographically ordered integer.
44-
*
45-
* ## Notes
46-
*
47-
* - This function mutates the input array.
32+
* Converts an unsigned 32-bit integer corresponding to the IEEE 754 binary representation of a single-precision floating-point number to a lexicographically ordered integer.
4833
*
4934
* @private
50-
* @param {Array<integer>} words - high and low words
51-
* @returns {Array<integer>} input array
35+
* @param {unsigned32} word - unsigned 32-bit integer
36+
* @returns {integer} lexicographically ordered integer
5237
*/
5338
function monotoneKey( word ) {
5439
if ( word & SIGN_MASK ) { // x < 0
55-
return ( ~word + 1 ) >>> 0; // maps -∞ to 0
56-
}
57-
return ( word | SIGN_MASK ) >>> 0; // maps +∞ to 2^32-1
58-
}
59-
60-
/**
61-
* Perform two's-complement negation.
62-
*
63-
* ## Notes
64-
*
65-
* - This function mutates the input array.
66-
*
67-
* @private
68-
* @param {Array<integer>} words - high and low words
69-
* @returns {Array<integer>} input array
70-
*/
71-
function negate( words ) {
72-
words[ 0 ] = ~words[ 0 ];
73-
words[ 1 ] = ~words[ 1 ];
74-
words[ 1 ] += 1;
75-
76-
// Handle the carry into the high word...
77-
if ( words[ 1 ] === 0 ) {
78-
words[ 0 ] += 1;
79-
}
80-
return words;
81-
}
82-
83-
/**
84-
* Returns the ordering of two single-precision floating-point numbers according to their lexicographically ordered high and low words.
85-
*
86-
* @private
87-
* @param {Array<integer>} wa - high and low words for first value
88-
* @param {Array<integer>} wb - high and low words for second value
89-
* @returns {integer} relative ordering
90-
*/
91-
function compare( wa, wb ) {
92-
if ( wa[ 0 ] > wb[ 0 ] ) {
93-
return 1;
94-
}
95-
if ( wa[ 0 ] < wb[ 0 ] ) {
96-
return -1;
97-
}
98-
if ( wa[ 1 ] > wb[ 1 ] ) {
99-
return 1;
100-
}
101-
if ( wa[ 1 ] < wb[ 1 ] ) {
102-
return -1;
103-
}
104-
return 0;
105-
}
106-
107-
/**
108-
* Performs double-word subtraction.
109-
*
110-
* @private
111-
* @param {Array<integer>} wa - high and low words for first value
112-
* @param {Array<integer>} wb - high and low words for second value
113-
* @param {Array<integer>} wc - output array
114-
* @returns {Array<integer>} output array
115-
*/
116-
function subtract( wa, wb, wc ) {
117-
var ha;
118-
var hb;
119-
var la;
120-
var lb;
121-
122-
ha = wa[ 0 ];
123-
la = wa[ 1 ];
124-
hb = wb[ 0 ];
125-
lb = wb[ 1 ];
126-
127-
if ( la >= lb ) {
128-
wc[ 0 ] = ha - hb;
129-
wc[ 1 ] = la - lb;
130-
} else {
131-
wc[ 0 ] = ( ha - hb - 1 ); // wrap
132-
wc[ 1 ] = ( la + TWO_32 ) - lb; // borrow
40+
return ( ~word + 1 );
13341
}
134-
return wc;
42+
// x >= 0
43+
return ( word | SIGN_MASK ) >>> 0; // push +0 to just above -0
13544
}
13645

13746

@@ -171,23 +80,21 @@ function subtract( wa, wb, wc ) {
17180
* // returns NaN
17281
*/
17382
function ulpdiff( x, y ) {
174-
var ord;
17583
var wx;
17684
var wy;
177-
var wz;
17885

17986
if ( isnanf( x ) || isnanf( y ) ) {
18087
return NaN;
18188
}
182-
// Convert input values to high and low words:
89+
// Convert input values to unsigned 32-bit integers corresponding to the IEEE 754 binary representation of single-precision floating-point numbers:
18390
wx = toWordf( x );
18491
wy = toWordf( y );
18592

186-
// Convert the values to lexicographically order integers:
93+
// Convert the words to lexicographically order integers:
18794
wx = monotoneKey( wx );
18895
wy = monotoneKey( wy );
18996

190-
// Return a double as a result, which is fine for ≤2^53 ulps:
97+
// Return a double as a result, which can exactly represent the ULP difference for all representable single-precision floating-point numbers:
19198
return abs( wx - wy );
19299
}
193100

0 commit comments

Comments
 (0)