Skip to content

Commit 796dbd9

Browse files
committed
refactor: use powf and truncf for float32 operations in truncbf
- Replace pow with powf in JavaScript and C implementations - Replace trunc with truncf in JavaScript and C implementations - Update variable types from double to float in C code - Update manifest.json dependencies to powf and truncf - Ensures proper single-precision floating-point operations throughout
1 parent b60cbf1 commit 796dbd9

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2424
var isInfinitef = require( '@stdlib/math/base/assert/is-infinitef' );
25-
var pow = require( '@stdlib/math/base/special/pow' );
26-
var trunc = require( '@stdlib/math/base/special/trunc' );
25+
var powf = require( '@stdlib/math/base/special/powf' );
26+
var truncf = require( '@stdlib/math/base/special/truncf' );
2727
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
2828

2929

@@ -71,10 +71,10 @@ function truncbf( x, n, b ) {
7171
}
7272

7373
// Compute scale factor: s = b^n
74-
s = pow( b, n );
74+
s = powf( b, n );
7575

7676
// Multiply by scale, truncate, then divide by scale
77-
y = trunc( x * s ) / s;
77+
y = truncf( x * s ) / s;
7878

7979
return float64ToFloat32( y );
8080
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"libraries": [],
4040
"libpath": [],
4141
"dependencies": [
42-
"@stdlib/math/base/special/pow",
43-
"@stdlib/math/base/special/trunc",
42+
"@stdlib/math/base/special/powf",
43+
"@stdlib/math/base/special/truncf",
4444
"@stdlib/math/base/assert/is-nanf",
4545
"@stdlib/math/base/assert/is-infinitef"
4646
]

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/truncbf.h"
20-
#include "stdlib/math/base/special/pow.h"
21-
#include "stdlib/math/base/special/trunc.h"
20+
#include "stdlib/math/base/special/powf.h"
21+
#include "stdlib/math/base/special/truncf.h"
2222
#include "stdlib/math/base/assert/is-nanf.h"
2323
#include "stdlib/math/base/assert/is-infinitef.h"
2424
#include <stdint.h>
@@ -36,8 +36,8 @@
3636
* // returns 3.14f
3737
*/
3838
float stdlib_base_truncbf( const float x, const int32_t n, const int32_t b ) {
39-
double s;
40-
double y;
39+
float s;
40+
float y;
4141

4242
if ( x == 0.0f || stdlib_base_is_nanf( x ) || stdlib_base_is_infinitef( x ) ) {
4343
return x;
@@ -46,11 +46,11 @@ float stdlib_base_truncbf( const float x, const int32_t n, const int32_t b ) {
4646
return 0.0f / 0.0f; // NaN
4747
}
4848

49-
// Compute scale factor: s = b^n using double precision
50-
s = stdlib_base_pow( (double)b, (double)n );
49+
// Compute scale factor: s = b^n using single precision
50+
s = stdlib_base_powf( (float)b, (float)n );
5151

5252
// Multiply by scale, truncate, then divide by scale
53-
y = stdlib_base_trunc( (double)x * s ) / s;
53+
y = stdlib_base_truncf( x * s ) / s;
5454

55-
return (float)y;
55+
return y;
5656
}

0 commit comments

Comments
 (0)