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: update math/base/special/log10 to follow FreeBSD version 12.2.0 #2215

Merged
merged 4 commits into from
May 30, 2024

Conversation

gunjjoshi
Copy link
Contributor

@gunjjoshi gunjjoshi commented Apr 28, 2024

Description

What is the purpose of this pull request?

This pull request:

  • updates existing JavaScript implementation to follow FreeBSD version 12.2.0.
  • adds a corresponding test.

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.

  • Code coverage report:
Screenshot 2024-04-28 at 09 29 44

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 Apr 28, 2024
@Planeshifter Planeshifter self-requested a review May 29, 2024 00:43
@kgryte kgryte added the C Issue involves or relates to C. label May 29, 2024
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.

Left two small comments with regards to the code comments, otherwise looks good to me!

@gunjjoshi
Copy link
Contributor Author

Left two small comments with regards to the code comments, otherwise looks good to me!

Thanks, I've made the changes in both main.c and main.js.

@Planeshifter Planeshifter merged commit d3215eb into stdlib-js:develop May 30, 2024
5 of 6 checks passed
if ( ( ( ihx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | ilx ) == 0 ) {
if ( hx < HIGH_MIN_NORMAL_EXP ) {
// Case: x < 2**-1022
if ( ( ( hx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | lx ) == 0 ) {
Copy link
Member

@kgryte kgryte May 30, 2024

Choose a reason for hiding this comment

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

@gunjjoshi @Planeshifter Correct me if I'm wrong, but hx is uint32_t here. Bitwise ops are defined for signed integers. Meaning, we should still be using ihx and ilx here and below.

Copy link
Member

Choose a reason for hiding this comment

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

I see that we do this in log2 (https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/math/base/special/log2/src/main.c#L75), but I am not sure that is correct or works as intended.

Copy link
Member

Choose a reason for hiding this comment

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

In

, we do the explicit cast to int32_t. IIRC, the failure to explicitly cast words to signed integers resulted in test failures in other packages.

Update: after digging around a bit, looks like all bitwise operators are defined for unsigned integers. The issue arises when mixing signed and unsigned integer values. In that instance, unsigned integers will cast to signed integers which can cause unexpected behavior. My sense is that wherever FreeBSD uses signed integers, we should also use signed integers. In that case, we should use ihx (see https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_log10.c?view=markup).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes @kgryte, the process of casting hx to a signed integer after these operations seems correct. I'll try to reiterate over this implementation once again, keeping this in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Issue involves or relates to C. Math Issue or pull request specific to math functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants