Skip to content

Commit 19edd05

Browse files
chore: removing lx and hx from special cases
1 parent 892d7c1 commit 19edd05

File tree

11 files changed

+84
-141
lines changed

11 files changed

+84
-141
lines changed

lib/node_modules/@stdlib/math/base/special/powf/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var powf = require( '@stdlib/math/base/special/powf' );
5555

5656
#### powf( base, exponent )
5757

58-
Evaluates the [exponential function][exponential-function] for single-precision values.
58+
Evaluates the [exponential function][exponential-function] for single-precision floating-point values.
5959

6060
```javascript
6161
var v = powf( 2.0, 3.0 );
@@ -141,7 +141,7 @@ for ( i = 0; i < 100; i++ ) {
141141

142142
#### stdlib_base_powf( base, exponent )
143143

144-
Evaluates the exponential function for single-precision values.
144+
Evaluates the exponential function for single-precision floating-point values.
145145

146146
```c
147147
float out = stdlib_base_powf( 3.1415927410125732f, 5.0f );

lib/node_modules/@stdlib/math/base/special/powf/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{{alias}}( b, x )
3-
Evaluates the exponential function `bˣ` for single-precision values.
3+
Evaluates the exponential function `bˣ` for single-precision floating-point values.
44

55
Parameters
66
----------

lib/node_modules/@stdlib/math/base/special/powf/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// TypeScript Version: 4.1
2020

2121
/**
22-
* Evaluates the exponential function for single-precision values.
22+
* Evaluates the exponential function for single-precision floating-point values.
2323
*
2424
* @param b - base
2525
* @param x - exponent

lib/node_modules/@stdlib/math/base/special/powf/examples/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
var randu = require( '@stdlib/random/base/randu' );
2222
var roundf = require( '@stdlib/math/base/special/roundf' );
23-
var powf = require( './../lib' );
23+
var powf = require('./../lib');
2424

2525
var b;
2626
var x;

lib/node_modules/@stdlib/math/base/special/powf/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Evaluate the exponential function for single-precision values.
22+
* Evaluate the exponential function for single-precision floating-point values.
2323
*
2424
* @module @stdlib/math/base/special/powf
2525
*
@@ -53,7 +53,7 @@
5353

5454
// MODULES //
5555

56-
var main = require( '@stdlib/math/base/special/powf/lib/log2ax' );
56+
var main = require( './main.js' );
5757

5858

5959
// EXPORTS //

lib/node_modules/@stdlib/math/base/special/powf/lib/log2ax.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* ## Notice
2020
*
21-
* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/e_powf.c}. The implementation follows the original, but has been modified for JavaScript.
21+
* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_powf.c}. The implementation follows the original, but has been modified for JavaScript.
2222
*
2323
* ```text
2424
* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
@@ -39,6 +39,7 @@ var toWordf = require( '@stdlib/number/float32/base/to-word' );
3939
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
4040
var FLOAT32_EXPONENT_BIAS = require( '@stdlib/constants/float32/exponent-bias' );
4141
var FLOAT32_SIGNIFICAND_MASK = require( '@stdlib/constants/float32/significand-mask' );
42+
var FLOAT32_PRECISION = require( '@stdlib/constants/float32/precision' );
4243
var polyvalL = require( '@stdlib/math/base/special/powf/lib/polyval_l.js' );
4344

4445

@@ -59,8 +60,6 @@ var HIGH_SIGNIFICAND_HALF = 0x20000000; // asm type annotation
5960
// 0x00400000 = 4194304 => 0 00000000000 10000000000000000000
6061
var HIGH_MIN_NORMAL_EXP_HALF = 0x00400000; // asm type annotation
6162

62-
var HIGH_NUM_SIGNIFICAND_BITS = 23; // asm type annotation
63-
6463
var TWO24 = 16777216.0; // 0x4b800000
6564

6665
// 2/(3*LN2)
@@ -134,7 +133,7 @@ function log2ax( out, ax, ahx ) {
134133
ahx = fromWordf( ax );
135134
}
136135
// Extract the unbiased exponent of `x`:
137-
n += ((ahx >> HIGH_NUM_SIGNIFICAND_BITS) - FLOAT32_EXPONENT_BIAS); // asm type annotation
136+
n += ((ahx >> (FLOAT32_PRECISION -1) ) - FLOAT32_EXPONENT_BIAS); // asm type annotation
138137

139138
// Isolate the significand bits of `x`:
140139
j = (ahx & FLOAT32_SIGNIFICAND_MASK); // asm type annotation
@@ -152,7 +151,7 @@ function log2ax( out, ax, ahx ) {
152151
else if ( j < 0x5db3d7 ) { // 0 00000000010 11101101100111110111
153152
k = 1;
154153
}
155-
// |x| >= sqrtf(3)
154+
// |x| >= sqrt(3)
156155
else {
157156
k = 0;
158157
n += 1; // asm type annotation

lib/node_modules/@stdlib/math/base/special/powf/lib/logx.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* ## Notice
2020
*
21-
* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/e_powf.c}. The implementation follows the original, but has been modified for JavaScript.
21+
* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_powf.c}. The implementation follows the original, but has been modified for JavaScript.
2222
*
2323
* ```text
2424
* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
@@ -48,7 +48,7 @@ var HIGH_BIASED_EXP_NEG_64 = 0xfffff000; // asm type annotation
4848
// 1/LN2
4949
var INV_LN2 = 1.4426950216e+00; // 0x3fb8aa3b =1/ln2
5050

51-
// High (24 bits): 1/LN2
51+
// High (16 bits): 1/LN2
5252
var INV_LN2_HI = 1.4426879883e+00; // 0x3fb8aa00 =16b 1/ln2
5353

5454
// Low: 1/LN2

lib/node_modules/@stdlib/math/base/special/powf/lib/main.js

Lines changed: 38 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* ## Notice
2020
*
21-
* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/e_powf.c}. The implementation follows the original, but has been modified for JavaScript.
21+
* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_powf.c}. The implementation follows the original, but has been modified for JavaScript.
2222
*
2323
* ```text
2424
* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
@@ -36,7 +36,7 @@
3636

3737
var isOddf = require( '@stdlib/math/base/assert/is-oddf' );
3838
var isInfinitef = require( '@stdlib/math/base/assert/is-infinitef' );
39-
var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' );
39+
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
4040
var sqrtf = require( '@stdlib/math/base/special/sqrtf' );
4141
var absf = require( '@stdlib/math/base/special/absf' );
4242
var fromWordf = require( '@stdlib/number/float32/base/from-word' );
@@ -78,7 +78,7 @@ var SMALL_NEG_60 = 0xc3160000>>>0; // asm type annotation
7878
var HUGE = 1.0e30;
7979
var TINY = 1.0e-30;
8080

81-
// -(1024-log2(ovfl+.5ulp))
81+
// -(128-log2(ovfl+.5ulp))
8282
var OVT = 4.2995665694e-08;
8383

8484
// Log workspace:
@@ -88,67 +88,7 @@ var LOG_WORKSPACE = 0.0;
8888
// MAIN //
8989

9090
/**
91-
* Evaluates the exponential function for single-precision values.
92-
*
93-
* ## Method
94-
*
95-
* 1. Let \\(x = 2^n (1+f)\\).
96-
*
97-
* 2. Compute \\(\operatorname{log2}(x)\\) as
98-
*
99-
* ```tex
100-
* \operatorname{log2}(x) = w_1 + w_2
101-
* ```
102-
*
103-
* where \\(w_1\\) has \\(53 - 24 = 29\\) bit trailing zeros.
104-
*
105-
* 3. Compute
106-
*
107-
* ```tex
108-
* y \cdot \operatorname{log2}(x) = n + y^\prime
109-
* ```
110-
*
111-
* by simulating multi-precision arithmetic, where \\(|y^\prime| \leq 0.5\\).
112-
*
113-
* 4. Return
114-
*
115-
* ```tex
116-
* x^y = 2^n e^{y^\prime \cdot \mathrm{log2}}
117-
* ```
118-
*
119-
* ## Special Cases
120-
*
121-
* ```tex
122-
* \begin{align*}
123-
* x^{\mathrm{NaN}} &= \mathrm{NaN} & \\
124-
* (\mathrm{NaN})^y &= \mathrm{NaN} & \\
125-
* 1^y &= 1 & \\
126-
* x^0 &= 1 & \\
127-
* x^1 &= x & \\
128-
* (\pm 0)^\infty &= +0 & \\
129-
* (\pm 0)^{-\infty} &= +\infty & \\
130-
* (+0)^y &= +0 & \mathrm{if}\ y > 0 \\
131-
* (+0)^y &= +\infty & \mathrm{if}\ y < 0 \\
132-
* (-0)^y &= -\infty & \mathrm{if}\ y\ \mathrm{is\ an\ odd\ integer\ and}\ y < 0 \\
133-
* (-0)^y &= +\infty & \mathrm{if}\ y\ \mathrm{is\ not\ an\ odd\ integer\ and}\ y < 0 \\
134-
* (-0)^y &= -0 & \mathrm{if}\ y\ \mathrm{is\ an\ odd\ integer\ and}\ y > 0 \\
135-
* (-0)^y &= +0 & \mathrm{if}\ y\ \mathrm{is\ not\ an\ odd\ integer\ and}\ y > 0 \\
136-
* (-1)^{\pm\infty} &= \mathrm{NaN} & \\
137-
* x^{\infty} &= +\infty & |x| > 1 \\
138-
* x^{\infty} &= +0 & |x| < 1 \\
139-
* x^{-\infty} &= +0 & |x| > 1 \\
140-
* x^{-\infty} &= +\infty & |x| < 1 \\
141-
* (-\infty)^y &= (-0)^y & \\
142-
* \infty^y &= +0 & y < 0 \\
143-
* \infty^y &= +\infty & y > 0 \\
144-
* x^y &= \mathrm{NaN} & \mathrm{if}\ y\ \mathrm{is\ not\ a\ finite\ integer\ and}\ x < 0
145-
* \end{align*}
146-
* ```
147-
*
148-
* ## Notes
149-
*
150-
* - \\(\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.
151-
* - 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.
91+
* Evaluates the exponential function for single-precision floating-point values.
15292
*
15393
* @param {number} x - base
15494
* @param {number} y - exponent
@@ -202,10 +142,13 @@ function powf( x, y ) {
202142
var hp;
203143
var lp;
204144
var z; // y prime
145+
var t;
205146
var j;
206147

207-
hx = fromWordf( x );
208-
hy = fromWordf( y );
148+
x = float64ToFloat32( x );
149+
hx = toWordf( x );
150+
y = float64ToFloat32( y );
151+
hy = toWordf( y );
209152

210153
// Special cases `y`...
211154
if ( y === 0.0 ) {
@@ -233,41 +176,39 @@ function powf( x, y ) {
233176
x *= x;
234177
return x * x;
235178
}
236-
if ( isInfinitef( y ) ) {
179+
if ( isInfinitef( y ) ) { // y is +-inf
237180
return yIsInfinite( x, y );
238181
}
239182

240183
// Special cases `x`...
241-
if ( lx === 0 ) {
242-
if ( hx === 0 ) {
243-
return xIsZero( x, y );
244-
}
245-
if ( x === 1.0 ) {
246-
return 1.0;
247-
}
248-
if (
249-
x === -1.0 &&
250-
isOddf( y )
251-
) {
252-
return -1.0;
184+
if ( hx === 0 ) {
185+
return xIsZero( x, y );
186+
}
187+
if ( x === 1.0 ) {
188+
return 1.0;
189+
}
190+
if (
191+
x === -1.0 &&
192+
isOddf( y )
193+
) {
194+
return -1.0;
195+
}
196+
if ( isInfinitef( x ) ) {
197+
if ( x === NINF ) {
198+
// `pow( 1/x, -y )`
199+
return powf( -0.0, -y );
253200
}
254-
if ( isInfinitef( x ) ) {
255-
if ( x === NINF ) {
256-
// `pow( 1/x, -y )`
257-
return powf( -0.0, -y );
258-
}
259-
if ( y < 0.0 ) {
260-
return 0.0;
261-
}
262-
return PINF;
201+
if ( y < 0.0 ) {
202+
return 0.0;
263203
}
204+
return PINF;
264205
}
265206
if (
266207
x < 0.0 &&
267-
isIntegerf( y ) === false
208+
isInteger( y ) === false
268209
) {
269210
// Signal NaN...
270-
return (x-x)/(x-x);
211+
return (x-x)/(x-x); // (-1)**non-int is NaN
271212
}
272213
ax = absf( x );
273214

@@ -280,7 +221,7 @@ function powf( x, y ) {
280221
} else {
281222
sn = 1.0;
282223
}
283-
// |y| is huge
224+
// Case 1: `|y|` is huge
284225

285226
// if |y| > 2^27
286227
if( ahy > HIGH_BIASED_EXP_27 ) {
@@ -314,12 +255,13 @@ function powf( x, y ) {
314255
ahs = fromWordf( y );
315256
ahs = float64ToFloat32( ahs & HIGH_BIASED_EXP_NEG_64 );
316257
y1 = toWordf( ahs );
317-
lp = float64ToFloat32(( float64ToFloat32(y-y1)*t1 ) + float64ToFloat32( y*t2 )); // eslint-disable-line max-len
258+
lp = float64ToFloat32(float64ToFloat32( float64ToFloat32(y-y1)*t1 ) + float64ToFloat32( y*t2 )); // eslint-disable-line max-len
318259
hp = float64ToFloat32( y1 * t1 );
319260
z = float64ToFloat32( lp + hp );
320261
j = fromWordf( z );
321262

322-
// z >= 128
263+
264+
// z > 128
323265
if ( j > SMALL_BIASED_EXP_10 ) {
324266
// Signal overflow
325267
return sn * HUGE * HUGE;
@@ -332,10 +274,11 @@ function powf( x, y ) {
332274
}
333275
}
334276
// z <= -150
335-
else if ( (j&FLOAT32_ABS_MASK) >= SMALL_60 ) {
277+
else if ( (j&FLOAT32_ABS_MASK) > SMALL_60 ) {
336278
// Signal underflow...
337279
return sn * TINY * TINY;
338280
}
281+
// z == -150
339282
else if ( j === SMALL_NEG_60 ) {
340283
if( lp <= (z-hp) ) {
341284
// Signal underflow...
@@ -345,7 +288,7 @@ function powf( x, y ) {
345288
// Compute `2^(hp+lp)`...
346289
z = pow2( j, hp, lp );
347290

348-
return sx * z;
291+
return sn * z;
349292
}
350293

351294

lib/node_modules/@stdlib/math/base/special/powf/lib/native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Evaluates the exponential function for single-precision values.
29+
* Evaluates the exponential function for single-precision floating-point values.
3030
*
3131
* @private
3232
* @param {number} x - base

0 commit comments

Comments
 (0)