Skip to content

Commit 17bf069

Browse files
committed
feat: explicitly convert values to float32
1 parent 3092b05 commit 17bf069

File tree

1 file changed

+9
-8
lines changed
  • lib/node_modules/@stdlib/math/base/special/exp2f/lib

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var FLOAT32_MIN_BASE2_EXPONENT = require( '@stdlib/constants/float32/min-base2-e
4141
var roundf = require( '@stdlib/math/base/special/roundf' );
4242
var ldexpf = require( '@stdlib/math/base/special/ldexpf' );
4343
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
44+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
4445
var PINF = require( '@stdlib/constants/float32/pinf' );
4546
var polyvalP = require( './polyval_p.js' );
4647
var polyvalQ = require( './polyval_q.js' );
@@ -105,19 +106,19 @@ function exp2f( x ) {
105106
return PINF;
106107
}
107108
if ( x < FLOAT32_MIN_BASE2_EXPONENT ) {
108-
return 0.0;
109+
return float64ToFloat32( 0.0 );
109110
}
110111
// Separate into integer and fractional parts...
111-
n = roundf( x );
112-
x -= n;
112+
n = float64ToFloat32( roundf( x ) );
113+
x -= float64ToFloat32( n );
113114

114-
xx = x * x;
115-
px = x * polyvalP( xx );
116-
x = px / ( polyvalQ( xx ) - px );
117-
x = 1.0 + ldexpf( x, 1 );
115+
xx = float64ToFloat32( x * x );
116+
px = float64ToFloat32( x * polyvalP( xx ) );
117+
x = float64ToFloat32( px / float64ToFloat32( ( polyvalQ( xx ) - px ) ) );
118+
x = float64ToFloat32( 1.0 ) + ldexpf( x, 1 );
118119

119120
// Scale by power of 2:
120-
return ldexpf( x, n );
121+
return float64ToFloat32( ldexpf( x, n ) );
121122
}
122123

123124

0 commit comments

Comments
 (0)