-
Notifications
You must be signed in to change notification settings - Fork 206
added integer log with positive integer base #174
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
What is the reasoning for the extra function macro? |
Leftovers. Residual echoes. And I found another one: Will tackle it after lunch. |
3a5db59
to
0814610
Compare
Oh, I broke the couch? I know I need to loose some weight, Travis, no need to put a finger on it! |
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.
first part of the review, more to come later or so
bn_mp_factors_zero.c
Outdated
|
||
if (f->factors != NULL) { | ||
for (i = 0; i < f->length; i++) { | ||
mp_zero(&(f->factors[i])); |
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.
that's not required, mp_clear()
also zeroes the mp before clearing
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.
first part of the review, more to come later or so
Uh oh! ;-)
that's not required, mp_clear() also zeroes the mp before clearing
Yepp, residue from trying out if mp_zero
would suffice here (playing with the heap is always costly) but that results in quite a mess which I found out quickly.
} | ||
|
||
if (all == MP_NO) { | ||
#if 0 |
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.
can this code go or is there a reason this should stay?
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.
The first one is useful for some numbers but will hold up everything for others and I'm benchmarking the other one if it is useful at that place. I'm thinking about adding a flag for the first one to let the caller decide. The latter is needed for the quadratic sieve, but that will come later, much later.
So: should it stay or should it go? Good question. (Why am I hearing The Clash in my head now?)
Oh, nearly forgot: both, mp_isperfpower
and mp_ispower
need a mp_n_root_ex
with a normal runtime to begin with. It does not need the optimized version I have in a different branch (nthroot
I think?) but at least the one I put into this PR. It implements just the standard seed (a bit above the actual root) and a slightly more paranoid check at the end. The usability of the original version is so small, I would consider the one in this PR nothing more than a bug-fix.
bn_mp_factor.c
Outdated
} | ||
|
||
/* Switched off temporarily */ | ||
#if 0 |
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.
same here
*/ | ||
|
||
/* Decrement "a" by one like "a--". Changes input! */ | ||
#ifdef LTM_USE_EXTRA_FUNCTIONS |
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.
IMO this macro can be removed
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.
It changes the input, not a very common thing in LibTomMath, so I was a bit cautious here.
But if that (remove the macro for this function and this function only) is not what you meant drop me a note please.
bn_mp_factors_init.c
Outdated
#ifdef LTM_USE_EXTRA_FUNCTIONS | ||
int mp_factors_init(mp_factors *f) | ||
{ | ||
f->factors = OPT_CAST(mp_int) XMALLOC(sizeof(mp_int) * (size_t)(LTM_TRIAL_GROWTH)); |
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.
this should be cleared, shouldn't it? so it could be a XCALLOC()
!?
which brings me directly into... why aren't mp_init()
and mp_init_size()
using XCALLOC()
?
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.
this should be cleared, shouldn't it?
It is more or less just the backbone and gets overwritten. On the other side: better save than sorry and it doesn't cost much, so I'll clear it.
which brings me directly into... why aren't mp_init() and mp_init_size() using XCALLOC()?
It might have had a reason once but now? Yes. would support a change to XCALLOC here.
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.
Lunchbreak wasn't shortened, so I was able to rebase before I really need to run and that reminded me that XCALLOC
isn't in LTM anymore. Do you want to put it back in?
bn_mp_factors_sort.c
Outdated
for (i = 1 ; i < f->length; i++) { | ||
idx = i; | ||
while ((idx > 0) && (mp_cmp(&(f->factors[idx-1]),&(f->factors[idx])) == MP_GT)) { | ||
if ((e = mp_copy(&(f->factors[idx]), &tmp)) != MP_OKAY) { |
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.
we're deep inside the library, why should we do a deep copy of all mp_int
elements where it would be sufficient to exchange the mp_int
?
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.
Another leftover. I always start with mp_copy
and check later if it can be replaced with mp_exch
.
Thanks for taking the time to go through the whole mess!
(Lunchtime is a bit short today, the whole thing needs to wait till tonight.)
…dded tests for mp_n_root and mp_expt(_d)
d5bc46a
to
da630d8
Compare
Docs still need updates, sorry. |
This one is also huge. Maybe splitting it would help? @sjaeckel What do you think? |
@minad Not all functions are independent from each other in this PR. Do you want one PR per function? Has it pros and cons but the work for me is roughly the same, no matter what, so it's up to you to decide. What I can split off without any problems are Small packets:
The rest are more or less dependent of each other to various degrees, see |
Yes I understand that there are dependencies. Maybe multiple PRs in reverse topological order. No single functions but maybe logical units. This PR adds nearly 20000 lines, that's all I saw when I looked at it first ;) |
First I'd like to see this there are no "extra functions" it's in the library or it isn't :-) and AFAICT for now it looks like this doesn't break backwards compati
👍 I'd start with the simple implementations and keep the complicated stuff for the last PR's
the remaining stuff is ... well interdependent... probably it can at least commit-wise be split up into the factors-related functions and yes, that's a long way, but it's also 20k LOC |
Now, that's something I can work with! ;-)
That was intentional. Anything not backwards compatible in my code shall be considered a bug and it would be nice if I get dropped a note.
Because programmers are really bad at naming things! ;-)
I will have a free weekend this weekend (he says boldly), should suffice for a large part of that work.
That much? Really? Oh. |
@czurnieden Can we close this one? ilogb, incr and decr are already merged. You are proposing more things but I lost sight somehow. I guess you want to reopen smaller separate PRs for those parts. |
Yes. (thought it was already?)
Yeah, it's a bit of a mess, admitted. |
Example for a simple design to add a group of opt-in (independent) functions.