Skip to content

Inline traits numeric example #17098

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

Merged
merged 9 commits into from
Mar 14, 2023

Conversation

timotheeandres
Copy link
Contributor

Rewrite of the Numeric library. This new version uses inlining to improve performance on basic numeric operations.

Add methods missing in the skeleton

Add given for all primitive types

Add test methods for division, modulo, sign and toInt
Create version of InlineNumeric that extends Numeric. This requires:
- dropping the inline keyword for parameters (cannot override non-inline
parameter with inline parameter)
- dropping abs, sign, zero and one from InlineNumeric (see code for the
errors). Instead, override them in the given instances

Create version of InlineNumeric with extension methods defined in
the traits instead of in the companion objects.
This allows the usage of said methods without having to import them.
The inconvenient is that the overriding must be done with extension
methods, but since an extension method

  object A:
    extension (x: T)
      def foo: U = ???

can be called both like x.foo and A.foo(x), this allows for both forms
when performing operations such as toInt.
Split code into separate files for clarity

Reimplement Numeric and Ordering as inline

Place symbols in the trait
@nicolasstucki nicolasstucki self-assigned this Mar 14, 2023
@nicolasstucki nicolasstucki self-requested a review March 14, 2023 12:42
@nicolasstucki nicolasstucki changed the title Inline traits numeric Inline traits numeric example Mar 14, 2023
@nicolasstucki nicolasstucki merged commit 29e229b into scala:main Mar 14, 2023
@nicolasstucki nicolasstucki deleted the inline-traits-numeric branch March 14, 2023 14:38
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.

2 participants