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: use Math for double::{ln,log2,log10} on JS #1489

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

tonyfettes
Copy link
Contributor

Follow up of #1485 .

This PR use Math library on JS backend to implement:

  • Double::ln
  • Double::log2
  • Double::log10

TODO: 15.0.log10() is now inconsistent between JS & Other platforms.

Copy link

peter-jerry-ye-code-review bot commented Jan 16, 2025

‼️ This code review is generated by a bot. Please verify the content before trusting it.

Looking at the git diff, I can point out the following potential issues:

  1. File Extension Inconsistency: The new files are using .mbt extension (log_js.mbt, log_nonjs.mbt) while they appear to contain JavaScript code. This might cause issues with some IDEs or build tools that expect .js files for JavaScript code.

  2. Copyright Year: The copyright year in the new files is set to 2025 (future date), which is likely a mistake. It should probably be the current year or when the code was actually created.

  3. Documentation Inconsistency: In the log2 function documentation, the parameter is described as x but in the actual function signature it's called self. This inconsistency in documentation could be confusing for developers.

These issues don't affect the functionality of the code directly but could impact maintainability and documentation accuracy.

@coveralls
Copy link
Collaborator

coveralls commented Jan 16, 2025

Pull Request Test Coverage Report for Build 5042

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 85.186%

Totals Coverage Status
Change from base Build 5041: 0.0%
Covered Lines: 5233
Relevant Lines: 6143

💛 - Coveralls

@tonyfettes tonyfettes force-pushed the use-js-math-for-log branch 3 times, most recently from e6e0f99 to 9cb3a29 Compare January 16, 2025 12:11
@Kaida-Amethyst
Copy link
Contributor

I noticed that (15.0).log10() exhibits inconsistencies between JS and other platforms. Below is the current implementation:

// current version
pub fn log10(self : Double) -> Double {
  ln(self) / ln10
}

May I propose an improved version with better precision, which I have tested locally and found to perform well?

pub fn log10(x: Double) -> Double {
  if x < 0 || x.is_nan() {
    return not_a_number
  }
  if x.is_inf() {
    return x
  }
  let ivln10 = 4.34294481903251816668e-01
  let log10_2hi = 3.01029995663611771306e-01
  let log10_2lo = 3.69423907715893078616e-13
  let (f, e) = frexp(x)
  let (f, e) = if e >= 1 {
    (f * 2.0, (e - 1).to_double())
  } else {
    (f, e.to_double())
  }
  let z = e * log10_2lo + ivln10 * log(f)
  z + e * log10_2hi
}

@tonyfettes
Copy link
Contributor Author

@Kaida-Amethyst Thank you for your proposal! Could you please open a PR for that?

@Kaida-Amethyst
Copy link
Contributor

@Kaida-Amethyst Thank you for your proposal! Could you please open a PR for that?

Ok, No probelm 👌🏻 , gonna post a PR soon 😸

@Kaida-Amethyst
Copy link
Contributor

@Kaida-Amethyst Thank you for your proposal! Could you please open a PR for that?

PR link: #1499 😸

@bobzhang bobzhang force-pushed the use-js-math-for-log branch from ae2b3fe to 92dd619 Compare January 23, 2025 03:53
@bobzhang bobzhang enabled auto-merge January 23, 2025 03:55
@bobzhang bobzhang added this pull request to the merge queue Jan 23, 2025
Merged via the queue into moonbitlang:main with commit 4612955 Jan 23, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants