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

feat: add math/base/special/lnf #2315

Merged
merged 7 commits into from
Jun 10, 2024
Merged

feat: add math/base/special/lnf #2315

merged 7 commits into from
Jun 10, 2024

Conversation

gunjjoshi
Copy link
Member

@gunjjoshi gunjjoshi commented Jun 7, 2024

Description

What is the purpose of this pull request?

This pull request:

float stdlib_base_lnf( const float x )

I have referred the FreeBSD implementation for logf: https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_logf.c?revision=367086&view=markup

Related Issues

Does this pull request have any related issues?

None.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added the Math Issue or pull request specific to math functionality. label Jun 7, 2024
@Planeshifter Planeshifter self-requested a review June 8, 2024 18:42
Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gunjjoshi for this PR! Looked all good to me, except for a few if-blocks which should be safe to remove.

@kgryte kgryte added the Feature Issue or pull request for adding a new feature. label Jun 9, 2024
gunjjoshi and others added 6 commits June 10, 2024 08:43
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: GUNJ JOSHI <gunjjoshi8372@gmail.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: GUNJ JOSHI <gunjjoshi8372@gmail.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: GUNJ JOSHI <gunjjoshi8372@gmail.com>
Signed-off-by: GUNJ JOSHI <gunjjoshi8372@gmail.com>
Signed-off-by: GUNJ JOSHI <gunjjoshi8372@gmail.com>
@Planeshifter Planeshifter merged commit b6edfd8 into stdlib-js:develop Jun 10, 2024
8 checks passed

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' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single-precision so use is-nanf.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k is an integer value and does not need float32 emulation. In C, k is int32?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is int32 in C.

}
k = float64ToFloat32( k + float64ToFloat32( ( ix >> 23 ) - FLOAT32_EXPONENT_BIAS ) ); // eslint-disable-line max-len
ix &= FLOAT32_SIGNIFICAND_MASK;
i = float64ToFloat32( ix + ( 0x95f64 << 3 ) ) & 0x800000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also doesn't need float32 emulation based on my reading.

if ( k === 0 ) {
return 0.0;
}
dk = k;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, int32 k is being cast to double in the C implementation. We prob don't need this assignment in the JS version.

if ( k === 0 ) {
return float64ToFloat32( f - R );
}
dk = k;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment. dk assignment is not necessary.

return float64ToFloat32( float64ToFloat32( dk * LN2_HI ) - float64ToFloat32( float64ToFloat32( R - float64ToFloat32( dk * LN2_LO ) ) - f ) ); // eslint-disable-line max-len
}
s = float64ToFloat32( f / float64ToFloat32( 2.0 + f ) );
dk = k;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

s = float64ToFloat32( f / float64ToFloat32( 2.0 + f ) );
dk = k;
z = float64ToFloat32( s * s );
i = float64ToFloat32( ix - ( 0x6147a << 3 ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

z = float64ToFloat32( s * s );
i = float64ToFloat32( ix - ( 0x6147a << 3 ) );
w = float64ToFloat32( z * z );
j = float64ToFloat32( ( 0x6b851 << 3 ) - ix );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment.

"@stdlib/math/base/napi/unary",
"@stdlib/number/float32/base/to-word",
"@stdlib/number/float32/base/from-word",
"@stdlib/math/base/assert/is-nan",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is-nanf here and below

if ( k == 0 ) {
return ( f - R );
}
dk = k;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment.

return ( ( dk * LN2_HI ) - ( ( R - ( dk * LN2_LO ) ) - f ) );
}
s = ( f / ( 2.0f + f ) );
dk = k;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

// MODULES //

var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is-nanf

t.equal( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
} else {
delta = abs( y - e );
tol = 75.0 * EPS * abs( e );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit large. What is the delta of the double-precision variant for subnormals?


var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments.

@gunjjoshi
Copy link
Member Author

@kgryte I've made a PR incorporating these changes at #2356.

kgryte pushed a commit that referenced this pull request Jun 10, 2024
PR-URL: #2356
Ref: #2315
Reviewed-by: Athan Reines <kgryte@gmail.com>
aman-095 pushed a commit to aman-095/stdlib that referenced this pull request Jun 11, 2024
PR-URL: stdlib-js#2315

---------

Signed-off-by: GUNJ JOSHI <gunjjoshi8372@gmail.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Athan Reines <kgryte@gmail.com> 
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
aman-095 pushed a commit to aman-095/stdlib that referenced this pull request Jun 11, 2024
PR-URL: stdlib-js#2356
Ref: stdlib-js#2315
Reviewed-by: Athan Reines <kgryte@gmail.com>
aman-095 pushed a commit to aman-095/stdlib that referenced this pull request Jun 13, 2024
PR-URL: stdlib-js#2315

---------

Signed-off-by: GUNJ JOSHI <gunjjoshi8372@gmail.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Athan Reines <kgryte@gmail.com> 
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
aman-095 pushed a commit to aman-095/stdlib that referenced this pull request Jun 13, 2024
PR-URL: stdlib-js#2356
Ref: stdlib-js#2315
Reviewed-by: Athan Reines <kgryte@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue or pull request for adding a new feature. Math Issue or pull request specific to math functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants