Skip to content

Commit a3855eb

Browse files
committed
Refactor to use a single function call to extract high/low words
1 parent 3c38848 commit a3855eb

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

  • lib/node_modules/@stdlib/math/base/special/pow/lib

lib/node_modules/@stdlib/math/base/special/pow/lib/pow.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ var isInteger = require( '@stdlib/math/base/assert/is-integer' );
2626
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2727
var abs = require( '@stdlib/math/base/special/abs' );
2828
var toWords = require( '@stdlib/number/float64/base/to-words' );
29-
var getHighWord = require( '@stdlib/number/float64/base/get-high-word' );
30-
var getLowWord = require( '@stdlib/number/float64/base/get-low-word' );
3129
var setLowWord = require( '@stdlib/number/float64/base/set-low-word' );
3230
var uint32ToInt32 = require( '@stdlib/number/uint32/base/to-int32' );
3331
var NINF = require( '@stdlib/constants/math/float64-ninf' );
@@ -74,13 +72,16 @@ var TINY = 1.0e-300;
7472
// -(1024-log2(ovfl+.5ulp))
7573
var OVT = 8.0085662595372944372e-17;
7674

75+
// High/low words workspace:
76+
var WORDS = [ 0, 0 ]; // WARNING: not thread safe
77+
7778

7879
// MAIN //
7980

8081
/**
8182
* Evaluates the exponential function.
8283
*
83-
* #### Method
84+
* ## Method
8485
*
8586
* 1. Let \\(x = 2^n (1+f)\\).
8687
*
@@ -106,7 +107,7 @@ var OVT = 8.0085662595372944372e-17;
106107
* x^y = 2^n e^{y^\prime \cdot \mathrm{log2}}
107108
* ```
108109
*
109-
* #### Special Cases
110+
* ## Special Cases
110111
*
111112
* ```tex
112113
* \begin{align*}
@@ -136,10 +137,10 @@ var OVT = 8.0085662595372944372e-17;
136137
* ```
137138
*
138139
*
139-
* #### Notes
140+
* ## Notes
140141
*
141-
* - \\(\operatorname{pow}(x,y)\\) returns \\(x^y\\) nearly rounded. In particular, \\(\operatorname{pow}(<\mathrm{integer}>,<\mathrm{integer}>)\\) __always__ returns the correct integer, provided the value is representable.
142-
* - The hexadecimal values shown in the source code are the intended values for used constants. Decimal values may be used, provided the compiler will accurately convert decimal to binary in order to produce the hexadecimal values.
142+
* - \\(\operatorname{pow}(x,y)\\) returns \\(x^y\\) nearly rounded. In particular, \\(\operatorname{pow}(<\mathrm{integer}>,<\mathrm{integer}>)\\) __always__ returns the correct integer, provided the value is representable.
143+
* - The hexadecimal values shown in the source code are the intended values for used constants. Decimal values may be used, provided the compiler will accurately convert decimal to binary in order to produce the hexadecimal values.
143144
*
144145
*
145146
* @param {number} x - base
@@ -191,7 +192,6 @@ function pow( x, y ) {
191192
var y1;
192193
var hp;
193194
var lp;
194-
var w;
195195
var t;
196196
var z; // y prime
197197
var j;
@@ -200,8 +200,9 @@ function pow( x, y ) {
200200
return NaN;
201201
}
202202
// Split `y` into high and low words:
203-
hy = getHighWord( y );
204-
ly = getLowWord( y );
203+
toWords( WORDS, y );
204+
hy = WORDS[ 0 ];
205+
ly = WORDS[ 1 ];
205206

206207
// Special cases `y`...
207208
if ( ly === 0 ) {
@@ -235,8 +236,9 @@ function pow( x, y ) {
235236
}
236237
}
237238
// Split `x` into high and low words:
238-
hx = getHighWord( x );
239-
lx = getLowWord( x );
239+
toWords( WORDS, x );
240+
hx = WORDS[ 0 ];
241+
lx = WORDS[ 1 ];
240242

241243
// Special cases `x`...
242244
if ( lx === 0 ) {
@@ -328,9 +330,9 @@ function pow( x, y ) {
328330
z = lp + hp;
329331

330332
// Note: *can* be more performant to use `getHighWord` and `getLowWord` directly, but using `toWords` looks cleaner.
331-
w = toWords( z );
332-
j = uint32ToInt32( w[0] );
333-
i = uint32ToInt32( w[1] );
333+
toWords( WORDS, z );
334+
j = uint32ToInt32( WORDS[0] );
335+
i = uint32ToInt32( WORDS[1] );
334336

335337
// z >= 1024
336338
if ( j >= HIGH_BIASED_EXP_10 ) {

0 commit comments

Comments
 (0)