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

Move double method to func in math #1050

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Move double method to func in math #1050

wants to merge 6 commits into from

Conversation

qazxcdswe123
Copy link
Contributor

@qazxcdswe123 qazxcdswe123 commented Sep 30, 2024

This pull request focuses on deprecating several mathematical functions in the Double type and moving their implementations to the math module. Key changes include marking functions as deprecated, adding new implementations, and updating tests accordingly.

Deprecation and Implementation Changes:

  • double/double.mbti: Marked exp, log10, log2, min_normal, and nan as deprecated. [1] [2]
  • double/exp_js.mbt and double/exp_nonjs.mbt: Added deprecation alerts for exp and provided new implementations. [1] [2]
  • double/log.mbt: Commented out deprecation for ln and added deprecation alerts for log2 and log10. [1] [2] [3]

New Implementations in math Module:

  • math/exp_js.mbt and math/exp_nonjs.mbt: Added new implementations for exp function. [1] [2]
  • math/log.mbt: Added new implementations for ln, log2, and log10 functions.

Test Updates:

Other Changes:

  • math/math.mbti: Added function signatures for exp, ln, log10, and log2.
  • math/moon.pkg.json: Updated package configuration to include new targets for exp_js.mbt and exp_nonjs.mbt.
    Some problems encounterd
  1. double::ln is used by log2 and log10, so a deprecation notice will persist since we also want to deprecate ln
  2. sqrt is implemented as method (and overloaded to support both float and double) and function argument cannot be overloaded, so it's not possible to migrate this.

close #1046

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@qazxcdswe123 qazxcdswe123 marked this pull request as ready for review September 30, 2024 07:17
Copy link

peter-jerry-ye-code-review bot commented Sep 30, 2024

Here are three potential issues or improvements I've identified from the git diff output:

  1. Duplicate License Notice:

    • In the NOTICE file, the license notice for the exp.mbt file is duplicated for both double/exp.mbt and math/exp.mbt. While this isn't necessarily a problem, it could be streamlined for clarity and consistency.
    • Suggestion: Update the NOTICE file to reflect that math/exp.mbt and double/exp.mbt share the same source and license, rather than listing them separately.
  2. Test File Deletion and Addition:

    • The test file double/exp_test.mbt was deleted, while new test files math/exp_test.mbt and others were added. This might indicate a refactoring or consolidation of test cases.
    • Suggestion: Ensure that all test cases from the deleted double/exp_test.mbt are either moved or replaced in the new test files to maintain coverage.
  3. Code Porting and Normalization:

    • In math/exp_nonjs.mbt, the function normalize checks if the absolute value of f is less than @double.min_positive. If so, it multiplies f by a large number and adjusts an exponent. This approach duplicates the functionality of frexp, which is used later in the same file.
    • Suggestion: Consider refactoring the code to use frexp directly for normalization, which could simplify the implementation and possibly reduce redundancy.

These suggestions aim to improve clarity, consistency, and efficiency in the codebase.

@coveralls
Copy link
Collaborator

coveralls commented Sep 30, 2024

Pull Request Test Coverage Report for Build 3311

Details

  • 37 of 42 (88.1%) changed or added relevant lines in 2 files are covered.
  • 22 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.4%) to 82.805%

Changes Missing Coverage Covered Lines Changed/Added Lines %
math/exp_nonjs.mbt 22 27 81.48%
Files with Coverage Reduction New Missed Lines %
double/exp_nonjs.mbt 22 0.0%
Totals Coverage Status
Change from base Build 3301: -0.4%
Covered Lines: 4103
Relevant Lines: 4955

💛 - Coveralls

@qazxcdswe123 qazxcdswe123 force-pushed the move-to-math branch 2 times, most recently from 318e716 to 7baf756 Compare September 30, 2024 07:21
@bobzhang
Copy link
Contributor

the CI failure looks weird

@qazxcdswe123
Copy link
Contributor Author

qazxcdswe123 commented Sep 30, 2024

the CI failure looks weird

Because fromjson tojson for record with Option inside changed, so bleeding and current release's compiler behave differently.

See:

struct Opt {

@hackwaly
Copy link
Contributor

hackwaly commented Sep 30, 2024

I think it's better to make math.xxx call Double::xxx to provide generic interface. And not just move Double::xxx to math package.

As there may be sqrt func in BigInt, BigDecimal...

// math package

trait Num {
  sqrt() -> Self
}

fn sqrt[T: Num](self: T) -> T {
  self.sqrt()
}

@tonyfettes
Copy link
Contributor

Please make sure to update NOTICE file to include updated path for the exp implementation (as per this comment, math/exp_nonjs.mbt).

@tonyfettes
Copy link
Contributor

This may or may not be in the scope of this PR, but for consistency, math functions in float shloud be moved into math package as well.

@qazxcdswe123
Copy link
Contributor Author

qazxcdswe123 commented Oct 8, 2024

This may or may not be in the scope of this PR, but for consistency, math functions in float shloud be moved into math package as well.

Unfortunately unless we bring back Num trait in X and make it generic, it's not possible to overload the function with different argument and same name.

@tonyfettes
Copy link
Contributor

tonyfettes commented Oct 8, 2024

Unfortunately unless we bring back Num trait in X and make it generic, it's not possible to overload the function with different argument and same name.

IMO adding f to every Float function looks good enough, like:

  • lnf
  • logf
  • sinf
  • cosf
  • ...

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.

Proposal: move exp, log to @math instead of @double
5 participants