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: reduce tolerance, correct castings for math/base/special/lnf #2356

Merged
merged 3 commits into from
Jun 10, 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
24 changes: 10 additions & 14 deletions lib/node_modules/@stdlib/math/base/special/lnf/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

var toWordf = require( '@stdlib/number/float32/base/to-word' );
var fromWordf = require( '@stdlib/number/float32/base/from-word' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var FLOAT32_EXPONENT_MASK = require( '@stdlib/constants/float32/exponent-mask' );
var FLOAT32_EXPONENT_BIAS = require( '@stdlib/constants/float32/exponent-bias' );
Expand Down Expand Up @@ -87,7 +87,6 @@ function lnf( x ) {
var ix;
var t2;
var t1;
var dk;
var k;
var R;
var f;
Expand All @@ -100,7 +99,7 @@ function lnf( x ) {
if ( x === 0.0 ) {
return NINF;
}
if ( isnan( x ) || x < 0.0 ) {
if ( isnanf( x ) || x < 0.0 ) {
return NaN;
}
x = float64ToFloat32( x );
Expand All @@ -109,7 +108,7 @@ function lnf( x ) {

// x < 2**-126
if ( ix < 0x00800000 ) {
k = float64ToFloat32( k - 25 );
k -= 25;

// Subnormal number, scale up x
x = float64ToFloat32( x * TWO25 );
Expand All @@ -120,7 +119,7 @@ function lnf( x ) {
}
k = float64ToFloat32( k + float64ToFloat32( ( ix >> 23 ) - FLOAT32_EXPONENT_BIAS ) ); // eslint-disable-line max-len
ix &= FLOAT32_SIGNIFICAND_MASK;
i = float64ToFloat32( ix + ( 0x95f64 << 3 ) ) & 0x800000;
i = ( ix + ( 0x95f64 << 3 ) ) & 0x800000;

// Normalize x or x/2
x = fromWordf( ix | ( i ^ 0x3f800000 ) );
Expand All @@ -133,22 +132,19 @@ function lnf( x ) {
if ( k === 0 ) {
return 0.0;
}
dk = k;
return float64ToFloat32( float64ToFloat32( dk * LN2_HI ) + float64ToFloat32( dk * LN2_LO ) ); // eslint-disable-line max-len
return float64ToFloat32( float64ToFloat32( k * LN2_HI ) + float64ToFloat32( k * LN2_LO ) ); // eslint-disable-line max-len
}
R = float64ToFloat32( float64ToFloat32( f * f ) * float64ToFloat32( 0.5 - float64ToFloat32( ONE_THIRD * f ) ) ); // eslint-disable-line max-len
if ( k === 0 ) {
return float64ToFloat32( f - R );
}
dk = k;
return float64ToFloat32( float64ToFloat32( dk * LN2_HI ) - float64ToFloat32( float64ToFloat32( R - float64ToFloat32( dk * LN2_LO ) ) - f ) ); // eslint-disable-line max-len
return float64ToFloat32( float64ToFloat32( k * LN2_HI ) - float64ToFloat32( float64ToFloat32( R - float64ToFloat32( k * LN2_LO ) ) - f ) ); // eslint-disable-line max-len
}
s = float64ToFloat32( f / float64ToFloat32( 2.0 + f ) );
dk = k;
z = float64ToFloat32( s * s );
i = float64ToFloat32( ix - ( 0x6147a << 3 ) );
i = ix - ( 0x6147a << 3 );
w = float64ToFloat32( z * z );
j = float64ToFloat32( ( 0x6b851 << 3 ) - ix );
j = ( 0x6b851 << 3 ) - ix;
t1 = float64ToFloat32( w * float64ToFloat32( polyvalP( w ) ) );
t2 = float64ToFloat32( z * float64ToFloat32( polyvalQ( w ) ) );
i |= j;
Expand All @@ -158,12 +154,12 @@ function lnf( x ) {
if ( k === 0 ) {
return float64ToFloat32( f - float64ToFloat32( hfsq - float64ToFloat32( s * float64ToFloat32( hfsq + R ) ) ) ); // eslint-disable-line max-len
}
return float64ToFloat32( float64ToFloat32( dk * LN2_HI ) - float64ToFloat32( float64ToFloat32( hfsq - float64ToFloat32( ( s * float64ToFloat32( hfsq + R ) ) + float64ToFloat32( dk * LN2_LO ) ) ) - f ) ); // eslint-disable-line max-len
return float64ToFloat32( float64ToFloat32( k * LN2_HI ) - float64ToFloat32( float64ToFloat32( hfsq - float64ToFloat32( ( s * float64ToFloat32( hfsq + R ) ) + float64ToFloat32( k * LN2_LO ) ) ) - f ) ); // eslint-disable-line max-len
}
if ( k === 0 ) {
return float64ToFloat32( f - float64ToFloat32( s * float64ToFloat32( f - R ) ) ); // eslint-disable-line max-len
}
return float64ToFloat32( float64ToFloat32( dk * LN2_HI ) - float64ToFloat32( float64ToFloat32( float64ToFloat32( s * float64ToFloat32( f - R ) ) - float64ToFloat32( dk * LN2_LO ) ) - f ) ); // eslint-disable-line max-len
return float64ToFloat32( float64ToFloat32( k * LN2_HI ) - float64ToFloat32( float64ToFloat32( float64ToFloat32( s * float64ToFloat32( f - R ) ) - float64ToFloat32( k * LN2_LO ) ) - f ) ); // eslint-disable-line max-len
}


Expand Down
3 changes: 0 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/lnf/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@stdlib/math/base/napi/unary",
"@stdlib/number/float32/base/to-word",
"@stdlib/number/float32/base/from-word",
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float32/ninf",
"@stdlib/constants/float32/exponent-bias",
"@stdlib/constants/float32/exponent-mask",
Expand All @@ -60,7 +59,6 @@
"dependencies": [
"@stdlib/number/float32/base/to-word",
"@stdlib/number/float32/base/from-word",
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float32/ninf",
"@stdlib/constants/float32/exponent-bias",
"@stdlib/constants/float32/exponent-mask",
Expand All @@ -81,7 +79,6 @@
"dependencies": [
"@stdlib/number/float32/base/to-word",
"@stdlib/number/float32/base/from-word",
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float32/ninf",
"@stdlib/constants/float32/exponent-bias",
"@stdlib/constants/float32/exponent-mask",
Expand Down
7 changes: 3 additions & 4 deletions lib/node_modules/@stdlib/math/base/special/lnf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "stdlib/math/base/special/lnf.h"
#include "stdlib/number/float32/base/to_word.h"
#include "stdlib/number/float32/base/from_word.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/constants/float32/ninf.h"
#include "stdlib/constants/float32/exponent_bias.h"
#include "stdlib/constants/float32/exponent_mask.h"
Expand Down Expand Up @@ -152,18 +151,18 @@ float stdlib_base_lnf( const float x ) {
if ( k == 0 ) {
return 0.0f;
}
dk = k;
dk = (float)k;
return ( ( dk * LN2_HI ) + ( dk * LN2_LO ) );
}
R = ( ( f * f ) * ( 0.5f - ( ONE_THIRD * f ) ) );
if ( k == 0 ) {
return ( f - R );
}
dk = k;
dk = (float)k;
return ( ( dk * LN2_HI ) - ( ( R - ( dk * LN2_LO ) ) - f ) );
}
s = ( f / ( 2.0f + f ) );
dk = k;
dk = (float)k;
z = ( s * s );
i = ( ix - ( 0x6147a << 3 ) );
w = ( z * z );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ file = @__FILE__;
dir = dirname( file );

# Subnormal values:
x = range( 1.0e-39, stop = 1.4e-45, length = 500 );
x = range( 1.0e-39, stop = 1.40129846e-45, length = 500 );
out = joinpath( dir, "subnormal.json" );
gen( x, out );

Expand Down
Loading
Loading