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

Use macro to reduce code duplication #3

Open
1011X opened this issue Feb 11, 2019 · 1 comment
Open

Use macro to reduce code duplication #3

1011X opened this issue Feb 11, 2019 · 1 comment

Comments

@1011X
Copy link
Owner

1011X commented Feb 11, 2019

Right now the code between r32 and r64 is pretty much the same (as a result of copy-pasting it) except for some modifications to handle larger numbers in r64. Ideally tho, there should be a macro that handles implementations for both types in order to reduce code reuse and possible inconsistencies between them.

Such a macro should only rely on:

  • the name of the type (given to the macro)
  • some constants defined specifically for each type:
    • TOTAL_SIZE – gives the total number of bits of the internal type; e.g. for r32, it's 32 bits (note: not currently defined in code)
    • FRACTION_SIZE – gives the size of the fraction field

Everything else (including other necessary constants) should be derivable from the ones above.

@1011X
Copy link
Owner Author

1011X commented May 9, 2021

Tried out using macros to reduce some boilerplate recently. They helped reduce test code and trait implementations, but when using them for inherit methods they messed the documentation up a bit too much for my liking, so I copied the inherit methods back to each type for now. So far this way of doing things works well enough, although the tests macro should be modified slightly to allow for tests that can only be done by certain types.

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

No branches or pull requests

1 participant