Skip to content

Commit 252ec3a

Browse files
committed
refactor: remove redundant exponent check and replace magic number with constant
--- 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: na - 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 84d2f1d commit 252ec3a

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

lib/node_modules/@stdlib/math/base/special/modff/lib/assign.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var fromWord = require( '@stdlib/number/float32/base/from-word' );
2626
var f32 = require( '@stdlib/number/float64/base/to-float32' );
2727
var PINF = require( '@stdlib/constants/float32/pinf' );
2828
var FLOAT32_EXPONENT_BIAS = require( '@stdlib/constants/float32/exponent-bias' );
29+
var FLOAT32_NUM_SIGNIFICAND_BITS = require( '@stdlib/constants/float32/num-significand-bits' ); // eslint-disable-line id-length
2930
var FLOAT32_HIGH_WORD_EXPONENT_MASK = require( '@stdlib/constants/float32/exponent-mask' ); // eslint-disable-line id-length
3031
var FLOAT32_HIGH_WORD_SIGNIFICAND_MASK = require( '@stdlib/constants/float32/significand-mask' ); // eslint-disable-line id-length
3132

@@ -92,11 +93,11 @@ function modff( x, out, stride, offset ) {
9293
word = toWord( x );
9394

9495
// Extract the unbiased exponent:
95-
exp = ((word & FLOAT32_HIGH_WORD_EXPONENT_MASK) >> 23)|0; // asm type annotation
96+
exp = ((word & FLOAT32_HIGH_WORD_EXPONENT_MASK) >> FLOAT32_NUM_SIGNIFICAND_BITS)|0; // asm type annotation
9697
exp -= FLOAT32_EXPONENT_BIAS|0; // asm type annotation
9798

9899
// Handle smaller values (x < 2**23 = 8388608)...
99-
if ( exp < 23 ) {
100+
if ( exp < FLOAT32_NUM_SIGNIFICAND_BITS ) {
100101
i = (FLOAT32_HIGH_WORD_SIGNIFICAND_MASK >> exp)|0; // asm type annotation
101102

102103
// Determine if `x` is integral by checking for significand bits which cannot be exponentiated away...
@@ -116,13 +117,10 @@ function modff( x, out, stride, offset ) {
116117
out[ offset + stride ] = f32( x - i );
117118
return out;
118119
}
119-
// Check if `x` can even have a fractional part...
120-
if ( exp >= 23 ) {
121-
// `x` is integral:
122-
out[ offset ] = x;
123-
out[ offset + stride ] = ZERO;
124-
return out;
125-
}
120+
// `x` is integral:
121+
out[ offset ] = x;
122+
out[ offset + stride ] = ZERO;
123+
return out;
126124
}
127125

128126

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"@stdlib/constants/float32/pinf",
4747
"@stdlib/constants/float32/exponent-bias",
4848
"@stdlib/constants/float32/exponent-mask",
49-
"@stdlib/constants/float32/significand-mask"
49+
"@stdlib/constants/float32/significand-mask",
50+
"@stdlib/constants/float32/num-significand-bits"
5051
]
5152
},
5253
{
@@ -66,7 +67,8 @@
6667
"@stdlib/constants/float32/pinf",
6768
"@stdlib/constants/float32/exponent-bias",
6869
"@stdlib/constants/float32/exponent-mask",
69-
"@stdlib/constants/float32/significand-mask"
70+
"@stdlib/constants/float32/significand-mask",
71+
"@stdlib/constants/float32/num-significand-bits"
7072
]
7173
},
7274
{
@@ -86,7 +88,8 @@
8688
"@stdlib/constants/float32/pinf",
8789
"@stdlib/constants/float32/exponent-bias",
8890
"@stdlib/constants/float32/exponent-mask",
89-
"@stdlib/constants/float32/significand-mask"
91+
"@stdlib/constants/float32/significand-mask",
92+
"@stdlib/constants/float32/num-significand-bits"
9093
]
9194
}
9295
]

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
#include "stdlib/constants/float32/exponent_bias.h"
2525
#include "stdlib/constants/float32/exponent_mask.h"
2626
#include "stdlib/constants/float32/significand_mask.h"
27+
#include "stdlib/constants/float32/num_significand_bits.h"
2728

2829
/**
29-
* Decomposes a single-precision floating-point number into integral and fractional parts, each having the same type and sign as the input value, and assigns results to a provided output array.
30+
* Decomposes a single-precision floating-point number into integral and fractional parts, each having the same type and sign as the input value.
3031
*
3132
* @param x input value
3233
* @param integral destination pointer for the integral part
@@ -78,11 +79,11 @@ void stdlib_base_modff( const float x, float* integral, float* frac ) {
7879
stdlib_base_float32_to_word( x, &word );
7980

8081
// Extract the unbiased exponent:
81-
exp = ( ( word & STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK ) >> 23 );
82+
exp = ( ( word & STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK ) >> STDLIB_CONSTANT_FLOAT32_NUM_SIGNIFICAND_BITS );
8283
exp -= ( STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS );
8384

8485
// Handle smaller values (x < 2**23 = 8388608)...
85-
if( exp < 23 ) {
86+
if( exp < STDLIB_CONSTANT_FLOAT32_NUM_SIGNIFICAND_BITS ) {
8687
i = ( STDLIB_CONSTANT_FLOAT32_SIGNIFICAND_MASK >> exp );
8788

8889
// Determine if `x` is integral by checking for significand bits which cannot be exponentiated away...
@@ -100,11 +101,8 @@ void stdlib_base_modff( const float x, float* integral, float* frac ) {
100101
*frac = x - j;
101102
return;
102103
}
103-
// Check if `x` can even have a fractional part...
104-
else {
105-
// `x` is integral:
106-
*integral = x;
107-
*frac = 0.0f;
108-
return;
109-
}
104+
// `x` is integral:
105+
*integral = x;
106+
*frac = 0.0f;
107+
return;
110108
}

0 commit comments

Comments
 (0)