Skip to content

Commit 8a03f83

Browse files
authored
refactor: use constant package in math/base/special/fmodf (#3120)
PR-URL: #3120 Ref: 7fd112c Private-ref: stdlib-js/todo#2300 Reviewed-by: Athan Reines <[email protected]>
1 parent f80e82f commit 8a03f83

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"@stdlib/constants/float32/exponent-bias",
4444
"@stdlib/constants/float32/exponent-mask",
4545
"@stdlib/constants/float32/abs-mask",
46-
"@stdlib/constants/float32/min-base2-exponent"
46+
"@stdlib/constants/float32/min-base2-exponent",
47+
"@stdlib/constants/float32/precision"
4748
]
4849
},
4950
{
@@ -63,7 +64,8 @@
6364
"@stdlib/constants/float32/exponent-bias",
6465
"@stdlib/constants/float32/exponent-mask",
6566
"@stdlib/constants/float32/abs-mask",
66-
"@stdlib/constants/float32/min-base2-exponent"
67+
"@stdlib/constants/float32/min-base2-exponent",
68+
"@stdlib/constants/float32/precision"
6769
]
6870
},
6971
{
@@ -83,7 +85,8 @@
8385
"@stdlib/constants/float32/exponent-bias",
8486
"@stdlib/constants/float32/exponent-mask",
8587
"@stdlib/constants/float32/abs-mask",
86-
"@stdlib/constants/float32/min-base2-exponent"
88+
"@stdlib/constants/float32/min-base2-exponent",
89+
"@stdlib/constants/float32/precision"
8790
]
8891
}
8992
]

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
#include "stdlib/constants/float32/exponent_mask.h"
3939
#include "stdlib/constants/float32/exponent_bias.h"
4040
#include "stdlib/constants/float32/min_base2_exponent.h"
41+
#include "stdlib/constants/float32/precision.h"
4142
#include <stdint.h>
4243

44+
static const float ZERO[] = { 0.0f, -0.0f };
45+
4346
/**
4447
* Evaluates the modulus function for single-precision floating-point numbers.
4548
*
@@ -52,7 +55,6 @@
5255
* // returns 2.9f
5356
*/
5457
float stdlib_base_fmodf( const float x, const float y ) {
55-
const float ZERO[] = { 0.0f, -0.0f };
5658
uint32_t uhx;
5759
uint32_t uhy;
5860
int32_t hx;
@@ -101,7 +103,7 @@ float stdlib_base_fmodf( const float x, const float y ) {
101103
ix -= 1;
102104
}
103105
} else {
104-
ix = ( hx >> 23 ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
106+
ix = ( hx >> ( STDLIB_CONSTANT_FLOAT32_PRECISION - 1 ) ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
105107
}
106108

107109
// determine iy = ilogb(y)
@@ -111,7 +113,9 @@ float stdlib_base_fmodf( const float x, const float y ) {
111113
for ( i = ( hy << 8 ); i >= 0; i <<= 1 ) {
112114
iy -= 1;
113115
}
114-
} else iy = ( hy >> 23 ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
116+
} else {
117+
iy = ( hy >> ( STDLIB_CONSTANT_FLOAT32_PRECISION - 1 ) ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
118+
}
115119

116120
// set up {hx,lx}, {hy,ly} and align y to x
117121
if ( ix >= STDLIB_CONSTANT_FLOAT32_MIN_BASE2_EXPONENT ) {
@@ -160,7 +164,7 @@ float stdlib_base_fmodf( const float x, const float y ) {
160164
}
161165
if ( iy >= STDLIB_CONSTANT_FLOAT32_MIN_BASE2_EXPONENT ) {
162166
// normalize output
163-
hx = ( ( hx - 0x00800000 ) | ( ( iy + STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS ) << 23 ) );
167+
hx = ( ( hx - 0x00800000 ) | ( ( iy + STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS ) << ( STDLIB_CONSTANT_FLOAT32_PRECISION - 1 ) ) );
164168
stdlib_base_float32_from_word( (uint32_t)( hx | sx ), &xc );
165169
} else {
166170
// subnormal output

lib/node_modules/@stdlib/math/base/special/fmodf/test/fixtures/julia/runner.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ julia> gen( x, y, \"data.json\" );
3939
"""
4040
function gen( x, y, name )
4141
z = Array{Float32}( undef, length( x ) );
42-
for i in eachindex(x)
43-
z[ i ] = Float32(rem( Float32(x[ i ]), Float32(y[ i ])) )
42+
for i in eachindex( x )
43+
z[ i ] = Float32( rem( Float32( x[ i ] ), Float32( y[ i ] ) ) );
4444
end
4545

4646
# Store data to be written to file as a collection:
@@ -67,13 +67,13 @@ file = @__FILE__;
6767
dir = dirname( file );
6868

6969
# Subnormal results:
70-
x = range(1.18e-38, stop = 1.0e-45, length = 2001)
71-
y = range(1.18e-38, stop = 1.0e-45, length = 2001)
70+
x = range( 1.18e-38, stop = 1.0e-45, length = 2001 );
71+
y = range( 1.18e-38, stop = 1.0e-45, length = 2001 );
7272
gen( x, y, "subnormal_results.json" );
7373

7474
# x small, y small:
75-
x = rand( 5001 ) .* 100
76-
y = rand( 5001 ) .* 100
75+
x = rand( 5001 ) .* 100;
76+
y = rand( 5001 ) .* 100;
7777
gen( x, y, "small_small.json" );
7878

7979
# x small, y large:

0 commit comments

Comments
 (0)