-
Notifications
You must be signed in to change notification settings - Fork 214
Extension of mp_log to bigint bases #497
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
Conversation
cb60d1e to
bafa536
Compare
|
The proof isn't in the pudding anymore, I removed my…uhm… concatenation of notes because it is three years now and if I haven't done it by now, I never will. It is a bit more complicated now but it is reasonable fast and gives valid results for the full range, the old binary search method overflowed quickly and was rather slow (a lot of expensive exponentiations). |
sjaeckel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just compared the two mp_log() implementations side-by-side and they're basically the same, besides some small differences ... I think it would be better suited if they were refactored into
tommath_private.h:
---
#if ((UINT_MAX == UINT32_MAX) && (MP_WORD_SIZE > 4)) \
|| ((UINT_MAX == UINT16_MAX) && (MP_WORD_SIZE > 2))
#define S_MP_FP_LOG_D_POSSIBLE_C
#endif
---
s_mp_fp_log.c
---
static mp_err s_mp_fp_log_fraction(const mp_int *a, int p, mp_int *c) {...}
mp_err s_mp_fp_log(const mp_int *a, mp_int *c) {...}
---
s_mp_fp_log_d.c
---
static mp_word s_mp_flog2_mp_word(mp_word value) {...}
static mp_err s_mp_fp_log_fraction(mp_word x, int p, mp_word *c) {...}
mp_err s_mp_fp_log_d(const mp_int *a, mp_word *c) {...}
---
mp_log.c:
---
static mp_err s_approx_log(...) {
...
s_mp_fp_log(...)
...
}
static mp_err s_approx_log_d(...) {
...
s_mp_fp_log_d(...)
...
}
mp_err mp_log(const mp_int *a, const mp_int *b, int *lb)
{
/* preamble ... error checks, mp_count_bits(), etc */
if (MP_HAS(S_MP_LOG_D_POSSIBLE))
s_approx_log_d(...);
else
s_approx_log(...);
/* Check result. Result is wrong by 2(two) at most. */
/* ... and so on */
---Like that we always compile all versions of the API and could in theory even write tests against both s_mp_fp_log() and s_mp_fp_log_d().
What do you think?
Makes sense, will refactor as recommended. BTW: where's the rest of the gang? Always there when it is all new and interesting with chances to shine but once it's time to shove the broom through the shop they are all gone and the dirty work of lubing the machines is left to the old warhorses like us, eh? ;-) |
|
Did the refactoring as I understood it. Tests for the fixed point log_2 functions need a couple of testvalues (don't want to write a fixed point exponential function) that have to be contructed to cover the full range (as long as reasonable, a number with |
Thanks! I've refactored a bit further, can you please have a look? |
6303a41 to
e5f0330
Compare
|
(Took the liberty to change the label from "finished" to "in progress" ) Ah, it was the all the same, wasn't sure when I moved it all around (I'm not a morning person, sorry ;-) ), good.
I'm not the greatest fan of negative conditions, but…
…that's a very good reason.
I think that programmers should abstain from naming things ;-)
Conclusion: I think that programmers should abstain from naming things. Why did "-m64" choke just because that |
Because I shouldn't trust the Github GUI. Why do I always make the same error? There, in the logs, it clearly states: "test.c:1500" where we test the small edgecases and from that is was obvious that |
This code was duplicated as well. Signed-off-by: Steffen Jaeckel <[email protected]>
it's not used Signed-off-by: Steffen Jaeckel <[email protected]>
Signed-off-by: Steffen Jaeckel <[email protected]>
it's not required in the public header Signed-off-by: Steffen Jaeckel <[email protected]>
|
Argh, overlooked, *grr* |
|
Yepp, that's nice, let's take it. |
Too much wiggle room for innuendos, sorry. On the other side: "Too small for what?" if we use |
I've just tried it out locally and defining |
Yes, the The construct resolves to Try giving it an empty string explicitely But I don't know if that is the correct workaround. |
|
Put it up to the community but don't hold your breath, I rarely have a lot of success with that. And, yes, I am aware of the different code licenses. |
|
Nope, didn't work. *grr* |
|
Yepp, works now. The |
More than I would've done, less than is possible -> perfect :) I took the liberty to squash those last few commits of you together into one. |
(Replaces #495 because I messed that one up, sorry!)
My old method suffers from OVF errors that are not salvageable, at least not easily. Replaced it with a very simple one where the overflow can be caught (hard to explain, see code). It is also possible now to use a bigint as the base. I hope I didn't mess up as much as I do regularly.
The proof is in the pudding.