Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use constant package in math/base/special/fmodf #3120

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"@stdlib/constants/float32/exponent-bias",
"@stdlib/constants/float32/exponent-mask",
"@stdlib/constants/float32/abs-mask",
"@stdlib/constants/float32/min-base2-exponent"
"@stdlib/constants/float32/min-base2-exponent",
"@stdlib/constants/float32/precision"
]
},
{
Expand All @@ -63,7 +64,8 @@
"@stdlib/constants/float32/exponent-bias",
"@stdlib/constants/float32/exponent-mask",
"@stdlib/constants/float32/abs-mask",
"@stdlib/constants/float32/min-base2-exponent"
"@stdlib/constants/float32/min-base2-exponent",
"@stdlib/constants/float32/precision"
]
},
{
Expand All @@ -83,7 +85,8 @@
"@stdlib/constants/float32/exponent-bias",
"@stdlib/constants/float32/exponent-mask",
"@stdlib/constants/float32/abs-mask",
"@stdlib/constants/float32/min-base2-exponent"
"@stdlib/constants/float32/min-base2-exponent",
"@stdlib/constants/float32/precision"
]
}
]
Expand Down
12 changes: 8 additions & 4 deletions lib/node_modules/@stdlib/math/base/special/fmodf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
#include "stdlib/constants/float32/exponent_mask.h"
#include "stdlib/constants/float32/exponent_bias.h"
#include "stdlib/constants/float32/min_base2_exponent.h"
#include "stdlib/constants/float32/precision.h"
#include <stdint.h>

static const float ZERO[] = { 0.0f, -0.0f };

/**
* Evaluates the modulus function for single-precision floating-point numbers.
*
Expand All @@ -52,7 +55,6 @@
* // returns 2.9f
*/
float stdlib_base_fmodf( const float x, const float y ) {
const float ZERO[] = { 0.0f, -0.0f };
uint32_t uhx;
uint32_t uhy;
int32_t hx;
Expand Down Expand Up @@ -101,7 +103,7 @@ float stdlib_base_fmodf( const float x, const float y ) {
ix -= 1;
}
} else {
ix = ( hx >> 23 ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
ix = ( hx >> ( STDLIB_CONSTANT_FLOAT32_PRECISION - 1 ) ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
}

// determine iy = ilogb(y)
Expand All @@ -111,7 +113,9 @@ float stdlib_base_fmodf( const float x, const float y ) {
for ( i = ( hy << 8 ); i >= 0; i <<= 1 ) {
iy -= 1;
}
} else iy = ( hy >> 23 ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
} else {
iy = ( hy >> ( STDLIB_CONSTANT_FLOAT32_PRECISION - 1 ) ) - STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS;
}

// set up {hx,lx}, {hy,ly} and align y to x
if ( ix >= STDLIB_CONSTANT_FLOAT32_MIN_BASE2_EXPONENT ) {
Expand Down Expand Up @@ -160,7 +164,7 @@ float stdlib_base_fmodf( const float x, const float y ) {
}
if ( iy >= STDLIB_CONSTANT_FLOAT32_MIN_BASE2_EXPONENT ) {
// normalize output
hx = ( ( hx - 0x00800000 ) | ( ( iy + STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS ) << 23 ) );
hx = ( ( hx - 0x00800000 ) | ( ( iy + STDLIB_CONSTANT_FLOAT32_EXPONENT_BIAS ) << ( STDLIB_CONSTANT_FLOAT32_PRECISION - 1 ) ) );
stdlib_base_float32_from_word( (uint32_t)( hx | sx ), &xc );
} else {
// subnormal output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ julia> gen( x, y, \"data.json\" );
"""
function gen( x, y, name )
z = Array{Float32}( undef, length( x ) );
for i in eachindex(x)
z[ i ] = Float32(rem( Float32(x[ i ]), Float32(y[ i ])) )
for i in eachindex( x )
z[ i ] = Float32( rem( Float32( x[ i ] ), Float32( y[ i ] ) ) );
end

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

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

# x small, y small:
x = rand( 5001 ) .* 100
y = rand( 5001 ) .* 100
x = rand( 5001 ) .* 100;
y = rand( 5001 ) .* 100;
gen( x, y, "small_small.json" );

# x small, y large:
Expand Down
Loading