Skip to content

Commit eb72182

Browse files
gunjjoshiaayush0325
authored andcommitted
refactor: use external constant and update license in math/base/special/pow
PR-URL: stdlib-js#3082 Reviewed-by: Philipp Burckhardt <[email protected]> Signed-off-by: Gunj Joshi <[email protected]>
1 parent 64ba9a6 commit eb72182

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

lib/node_modules/@stdlib/math/base/special/pow/include/stdlib/math/base/special/pow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern "C" {
2929
/**
3030
* Evaluates the exponential function.
3131
*/
32-
double stdlib_base_pow( const double base, const double exponent );
32+
double stdlib_base_pow( const double x, const double y );
3333

3434
#ifdef __cplusplus
3535
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var getHighWord = require( '@stdlib/number/float64/base/get-high-word' );
3838
var setLowWord = require( '@stdlib/number/float64/base/set-low-word' );
3939
var setHighWord = require( '@stdlib/number/float64/base/set-high-word' );
4040
var BIAS = require( '@stdlib/constants/float64/exponent-bias' );
41+
var HIGH_NUM_SIGNIFICAND_BITS = require( '@stdlib/constants/float64/num-high-word-significand-bits' );
4142
var polyvalL = require( './polyval_l.js' );
4243

4344

@@ -58,9 +59,6 @@ var HIGH_BIASED_EXP_NEG_512 = 0x20000000|0; // asm type annotation
5859
// 0x00080000 = 524288 => 0 00000000000 10000000000000000000
5960
var HIGH_SIGNIFICAND_HALF = 0x00080000|0; // asm type annotation
6061

61-
// TODO: consider making an external constant
62-
var HIGH_NUM_SIGNIFICAND_BITS = 20|0; // asm type annotation
63-
6462
var TWO53 = 9007199254740992.0; // 0x43400000, 0x00000000
6563

6664
// 2/(3*LN2)

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var LN2 = require( '@stdlib/constants/float64/ln-two' );
4343
var BIAS = require( '@stdlib/constants/float64/exponent-bias' );
4444
var ABS_MASK = require( '@stdlib/constants/float64/high-word-abs-mask' );
4545
var HIGH_SIGNIFICAND_MASK = require( '@stdlib/constants/float64/high-word-significand-mask' );
46+
var HIGH_NUM_SIGNIFICAND_BITS = require( '@stdlib/constants/float64/num-high-word-significand-bits' );
4647
var polyvalP = require( './polyval_p.js' );
4748

4849

@@ -54,9 +55,6 @@ var HIGH_MIN_NORMAL_EXP = 0x00100000|0; // asm type annotation
5455
// 0x3fe00000 = 1071644672 => 0 01111111110 00000000000000000000 => biased exponent: 1022 = -1+1023 => 2^-1
5556
var HIGH_BIASED_EXP_NEG_1 = 0x3fe00000|0; // asm type annotation
5657

57-
// TODO: consider making into an external constant
58-
var HIGH_NUM_SIGNIFICAND_BITS = 20|0; // asm type annotation
59-
6058
// High: LN2
6159
var LN2_HI = 6.93147182464599609375e-01; // 0x3FE62E43, 0x00000000
6260

lib/node_modules/@stdlib/math/base/special/pow/manifest.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"@stdlib/math/base/assert/is-infinite",
5555
"@stdlib/math/base/assert/is-integer",
5656
"@stdlib/math/base/special/sqrt",
57-
"@stdlib/number/float64/base/to-words"
57+
"@stdlib/number/float64/base/to-words",
58+
"@stdlib/constants/float64/num-high-word-significand-bits"
5859
]
5960
},
6061
{
@@ -85,7 +86,8 @@
8586
"@stdlib/math/base/assert/is-infinite",
8687
"@stdlib/math/base/assert/is-integer",
8788
"@stdlib/math/base/special/sqrt",
88-
"@stdlib/number/float64/base/to-words"
89+
"@stdlib/number/float64/base/to-words",
90+
"@stdlib/constants/float64/num-high-word-significand-bits"
8991
]
9092
},
9193
{
@@ -116,7 +118,8 @@
116118
"@stdlib/math/base/assert/is-infinite",
117119
"@stdlib/math/base/assert/is-integer",
118120
"@stdlib/math/base/special/sqrt",
119-
"@stdlib/number/float64/base/to-words"
121+
"@stdlib/number/float64/base/to-words",
122+
"@stdlib/constants/float64/num-high-word-significand-bits"
120123
]
121124
}
122125
]

lib/node_modules/@stdlib/math/base/special/pow/src/main.c

+21-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
17+
*
18+
*
19+
* ## Notice
20+
*
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/s_pow.c}. The implementation follows the original, but has been modified for JavaScript.
22+
*
23+
* ```text
24+
* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
25+
*
26+
* Developed at SunPro, a Sun Microsystems, Inc. business.
27+
* Permission to use, copy, modify, and distribute this
28+
* software is freely granted, provided that this notice
29+
* is preserved.
30+
* ```
1731
*/
1832

1933
#include "stdlib/math/base/special/pow.h"
@@ -35,6 +49,7 @@
3549
#include "stdlib/math/base/assert/is_integer.h"
3650
#include "stdlib/math/base/special/sqrt.h"
3751
#include "stdlib/number/float64/base/to_words.h"
52+
#include "stdlib/constants/float64/num_high_word_significand_bits.h"
3853

3954
// 0x3fefffff = 1072693247 => 0 01111111110 11111111111111111111 => biased exponent: 1022 = -1+1023 => 2^-1
4055
static const int32_t HIGH_MAX_NEAR_UNITY = 0x3fefffff;
@@ -49,9 +64,6 @@ static const int32_t HIGH_MIN_NORMAL_EXP = 0x00100000;
4964
// 0x3fe00000 = 1071644672 => 0 01111111110 00000000000000000000 => biased exponent: 1022 = -1+1023 => 2^-1
5065
static const int32_t HIGH_BIASED_EXP_NEG_1 = 0x3fe00000;
5166

52-
// TODO: consider making into an external constant
53-
static const int32_t HIGH_NUM_SIGNIFICAND_BITS = 20;
54-
5567
// High: LN2
5668
static const double LN2_HI = 6.93147182464599609375e-01; // 0x3FE62E43, 0x00000000
5769

@@ -316,18 +328,18 @@ static double pow2( uint32_t j, const double hp, const double lp ) {
316328
hpc = hp;
317329
jc = (int32_t)j;
318330
i = ( j & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK );
319-
k = ( ( i >> HIGH_NUM_SIGNIFICAND_BITS ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
331+
k = ( ( i >> STDLIB_CONSTANT_FLOAT64_NUM_HIGH_WORD_SIGNIFICAND_BITS ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
320332
n = 0;
321333
nc = (int32_t)n;
322334

323335
// `|z| > 0.5`, set `n = z+0.5`
324336
if ( i > HIGH_BIASED_EXP_NEG_1 ) {
325337
n = ( j + ( HIGH_MIN_NORMAL_EXP >> ( k + 1 ) ) );
326-
k = ( ( ( n & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) >> HIGH_NUM_SIGNIFICAND_BITS ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS ); // new k for n
338+
k = ( ( ( n & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) >> STDLIB_CONSTANT_FLOAT64_NUM_HIGH_WORD_SIGNIFICAND_BITS ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS ); // new k for n
327339
tmp = ( ( n & ~( HIGH_SIGNIFICAND_MASK >> k ) ) );
328340
t = 0.0;
329341
stdlib_base_float64_set_high_word( tmp, &t );
330-
n = ( ( ( n & HIGH_SIGNIFICAND_MASK ) | HIGH_MIN_NORMAL_EXP ) >> ( HIGH_NUM_SIGNIFICAND_BITS - k ) );
342+
n = ( ( ( n & HIGH_SIGNIFICAND_MASK ) | HIGH_MIN_NORMAL_EXP ) >> ( STDLIB_CONSTANT_FLOAT64_NUM_HIGH_WORD_SIGNIFICAND_BITS - k ) );
331343
nc = (int32_t)n;
332344
if ( jc < 0 ) {
333345
nc = -nc;
@@ -345,11 +357,11 @@ static double pow2( uint32_t j, const double hp, const double lp ) {
345357
r = ( ( z * t1 ) / ( t1 - 2.0 ) ) - ( w + ( z * w ) );
346358
z = 1.0 - ( r - z );
347359
stdlib_base_float64_get_high_word( z, &j );
348-
j = j + ( nc << HIGH_NUM_SIGNIFICAND_BITS );
360+
j = j + ( nc << STDLIB_CONSTANT_FLOAT64_NUM_HIGH_WORD_SIGNIFICAND_BITS );
349361
jc = (int32_t)j;
350362

351363
// Check for subnormal output...
352-
if ( ( jc >> HIGH_NUM_SIGNIFICAND_BITS ) <= 0 ) {
364+
if ( ( jc >> STDLIB_CONSTANT_FLOAT64_NUM_HIGH_WORD_SIGNIFICAND_BITS ) <= 0 ) {
353365
z = stdlib_base_ldexp( z, nc );
354366
} else {
355367
stdlib_base_float64_set_high_word( j, &z );
@@ -437,7 +449,7 @@ void log2ax( const double ax, const int32_t ahx, double *o1, double *o2 ) {
437449
ahxc = (int32_t)ahxcc;
438450
}
439451
// Extract the unbiased exponent of `x`:
440-
n += ( ( ahxc >> HIGH_NUM_SIGNIFICAND_BITS ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
452+
n += ( ( ahxc >> STDLIB_CONSTANT_FLOAT64_NUM_HIGH_WORD_SIGNIFICAND_BITS ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
441453

442454
// Isolate the significand bits of `x`:
443455
j = ( ahxc & HIGH_SIGNIFICAND_MASK );

0 commit comments

Comments
 (0)