-
-
Notifications
You must be signed in to change notification settings - Fork 456
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
Conversation
There was a problem hiding this 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.
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>
|
||
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' ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 ) ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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' ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments.
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>
PR-URL: stdlib-js#2356 Ref: stdlib-js#2315 Reviewed-by: Athan Reines <kgryte@gmail.com>
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>
PR-URL: stdlib-js#2356 Ref: stdlib-js#2315 Reviewed-by: Athan Reines <kgryte@gmail.com>
Description
This pull request:
math/base/special/lnf
, which is the single-precision version formath/base/special/ln
.I have referred the
FreeBSD
implementation forlogf
: https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_logf.c?revision=367086&view=markupRelated Issues
None.
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers