Skip to content

Commit eb92dc7

Browse files
committed
feat: add C implementation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 104fb3a commit eb92dc7

File tree

9 files changed

+306
-348
lines changed

9 files changed

+306
-348
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#ifndef STDLIB_MATH_BASE_SPECIAL_POWF_H
20+
#define STDLIB_MATH_BASE_SPECIAL_POWF_H
21+
22+
/*
23+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
24+
*/
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/**
30+
* Evaluates the exponential function for a single-precision floating-point number.
31+
*/
32+
float stdlib_base_powf( const float x, const float y );
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
38+
#endif // !STDLIB_MATH_BASE_SPECIAL_POWF_H

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var THREE = f32( 3.0 );
9696
* @private
9797
* @param {Array} out - output array
9898
* @param {number} ax - absolute value of `x`
99-
* @param {number} ahx - high word of `ax`
99+
* @param {number} ahx - word of `ax`
100100
* @returns {Array} output array containing a tuple comprised of high and low parts
101101
*
102102
* @example

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ var INV_LN2_HI = f32( 1.4426879883e+00 ); // 0x3fb8aa00
5454
// Low: 1/LN2
5555
var INV_LN2_LO = f32( 7.0526075433e-06 ); // 0x36eca570
5656

57+
var ONE = f32( 1.0 );
58+
5759

5860
// MAIN //
5961

@@ -67,7 +69,7 @@ var INV_LN2_LO = f32( 7.0526075433e-06 ); // 0x36eca570
6769
*
6870
* @example
6971
* var t = logxf( [ 0.0, 0.0 ], 9.0 );
70-
* // Expected output: [ -1265.7236328125, -0.0008163940840404393 ]
72+
* // returns [ -1265.5, ~-0.224 ]
7173
*/
7274
function logxf( out, ax ) {
7375
var tmp;
@@ -78,7 +80,7 @@ function logxf( out, ax ) {
7880
var u;
7981
var v;
8082

81-
t = f32( ax - 1.0 ); // `t` has `20` trailing zeros
83+
t = f32( ax - ONE ); // `t` has `20` trailing zeros
8284
w = f32( f32( t * t ) * polyvalW( t ) );
8385
u = f32( INV_LN2_HI * t ); // `INV_LN2_HI` has `16` significant bits
8486
v = f32( f32( t*INV_LN2_LO ) - f32( w*INV_LN2 ) );

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ var HALF = f32( 0.5 );
6060
var ONE = f32( 1.0 );
6161
var TWO = f32( 2.0 );
6262
var THREE = f32( 3.0 );
63-
var FOUR = f32( 4.0 );
6463
var NEG_ZERO = f32( -0.0 );
6564
var NEG_HALF = f32( -0.5 );
6665
var NEG_ONE = f32( -1.0 );
@@ -141,9 +140,9 @@ function powf( x, y ) {
141140
var ahx; // absolute value word `x`
142141
var ahy; // absolute value word `y`
143142
var ax; // absolute value `x`
144-
var hx; // word representation of `x `
143+
var hx; // word representation of `x`
145144
var hy; // word representation of `y`
146-
var sn;
145+
var sn; // sign of the result
147146
var y1;
148147
var hp;
149148
var lp;
@@ -183,10 +182,6 @@ function powf( x, y ) {
183182
if ( y === THREE ) {
184183
return f32( f32( x * x ) * x );
185184
}
186-
if ( y === FOUR ) {
187-
x = f32( x * x );
188-
return f32( x * x );
189-
}
190185
if ( isInfinitef( y ) ) { // y is +-inf
191186
return yIsInfinitef( x, y );
192187
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ var TWO = f32( 2.0 );
8383
* // returns ~0.79
8484
*/
8585
function pow2f( j, hp, lp ) {
86-
var ahs;
8786
var tmp;
8887
var t1;
8988
var t;
@@ -100,21 +99,21 @@ function pow2f( j, hp, lp ) {
10099
k = ((i>>NUM_SIGNIFICAND_BITS) - BIAS)|0; // asm type annotation
101100
n = 0;
102101

103-
// `|z| > 0.5`, set `n = [z+0.5]`
102+
// `|z| > 0.5`, set `n = z+0.5`
104103
if ( i > HALF_WORD ) {
105104
n = (j + (MIN_NORM_WORD>>(k+1)))|0; // asm type annotation
106105
k = (((n & ABS_MASK)>>NUM_SIGNIFICAND_BITS) - BIAS)|0; // new k for n
107106
tmp = ((n & ~(SIGNIFICAND_MASK >> k)))|0; // asm type annotation
108107
t = fromWordf( tmp );
109-
n = (((n & SIGNIFICAND_MASK)|MIN_NORM_WORD) >> (NUM_SIGNIFICAND_BITS-k))>>>0; // eslint-disable-line max-len
108+
n = (((n & SIGNIFICAND_MASK)|MIN_NORM_WORD) >> (NUM_SIGNIFICAND_BITS-k))|0; // eslint-disable-line max-len
110109
if ( j < 0 ) {
111110
n = -n;
112111
}
113112
hp = f32( hp - t );
114113
}
115114
t = f32( lp + hp );
116-
ahs = toWordf( t );
117-
t = fromWordf( ahs & TRUNC_MASK_15 );
115+
tmp = toWordf( t )|0; // asm type annotation
116+
t = fromWordf( tmp & TRUNC_MASK_15 );
118117
u = f32( t * LN2_HI );
119118
v = f32( f32( f32( lp - f32(t-hp) )*LN2 ) + f32( t*LN2_LO ) );
120119
z = f32( u + v );
@@ -124,7 +123,7 @@ function pow2f( j, hp, lp ) {
124123
r = f32( f32( f32(z*t1) / f32(t1-TWO) ) - f32( w + f32(z*w) ) );
125124
z = f32( ONE - f32(r - z) );
126125
j = toWordf( z ) |0; // asm type annotation
127-
j += ( (n>>>0) << NUM_SIGNIFICAND_BITS) |0; // asm type annotation
126+
j += ( (n>>>0) << NUM_SIGNIFICAND_BITS ) |0; // asm type annotation
128127

129128
// Check for subnormal output...
130129
if ( (j>>NUM_SIGNIFICAND_BITS) <= 0 ) {

lib/node_modules/@stdlib/math/base/special/powf/src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2024 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/math/base/special/powf/src/addon.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/special/pow.h"
19+
#include "stdlib/math/base/special/powf.h"
2020
#include "stdlib/math/base/napi/binary.h"
2121

22-
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_pow )
22+
STDLIB_MATH_BASE_NAPI_MODULE_FF_F( stdlib_base_powf )

0 commit comments

Comments
 (0)