-
Notifications
You must be signed in to change notification settings - Fork 166
Implemented multiplication of integer by a power of 10 #320
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
Implemented multiplication of integer by a power of 10 #320
Conversation
Please keep the pull request to a minimum. Do not refactor the code needlessly. This is a thoroughly tested code base. The assumption I have when reviewing code is that you are likely to make things worse, not better. If you think you can make it better, please use separate pull requests, and include benchmarks. |
3d9d012
to
cc90f24
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@lemire, so, are you interested in such functionality in this library? If yes, I will add draft docs in the README and whatnot, and ensure CI passes and there is no degradation in performance. |
@toughengineer Please see toughengineer#1
This is a community-driven project. If you complete it a bit with documentation, and if it seems solid, then I will merge it. Note that I ran benchmarks and your small changes do not appear to affect (much) the performance of our main functions. |
Got it. @lemire, what do you think about the name |
and it seems to bring performance to the level before the changes somewhat
Possible names:
My favourite is What do you think? |
Of these I like Searching "times", "times_pow" and "timespow" in C++ code on GitHub shows that it is something that people use yielding results like "smthng_times_2", "smthng_time_pow_of_2", "SmthngTimesPowerOfTwo" and the like. Thank you for ideas, gotta think about that. |
added example code test executable
Added more changes, I think it's ready for review. Things to pay attention to:
Unfortunately we generally can't construct a MACRO(1, , 1) // produces 1e1
MACRO(1, -, 1) // produces 1e-1 is too ugly, |
We are getting build errors:
|
Apparently |
It is fine if we don't implement going to float or |
I meant that given double integer_times_pow10(std::integral auto, int) {/*implementation*/} to extend it to be able to get different floating point types as return types you would reimplement it in the following way: template<std::floating_point F>
F integer_times_pow10(std::integral auto, int) {/*implementation*/}
double integer_times_pow10(std::integral auto m, int e) { return integer_times_pow10<double>(m, e); } (I use concepts as shorthand.) This way you still can call the ordinary version and get double d = integer_times_pow10(12, 34);
float f = integer_times_pow10<float>(12, 34);
float16_t f16 = integer_times_pow10<float16_t>(12, 34); Since you have this concern now, I will implement it in the next PR so the solution is complete and tidy. Or is there something else that you have in mind, @lemire? |
Sorry for the delay. Merging. This will be part of the next release. |
See details in #319.
The new functions use the same code that the existing functionality uses, so I don't know which tests should be added other than the most basic ones checking the correctness of the interface.
More documentation will be added later if needed.
There are unrelated changes leftover from development which are still useful IMHO,
I can roll them back if you don't want them.