I believe it is as efficient as possible, though I didn't check this. About the only overhead should be some kind of branch which depends on what base you want. Let us know if it becomes a bottleneck for you and we'll see if there are any other options.
On 9 March 2011 18:40, Steve <sjh_goo...@shic.co.uk> wrote: > On 09/03/2011 17:55, Bill Hart wrote: >> There is the C function mpz_sizeinbase. If you do it in base 2 it will >> extremely efficiently tell you the bit length. Your algorithm will >> actually be O(n^2) time, whereas mpz_sizeinbase for base a power of 2 >> is O(1). > > Many thanks - mpx_sizeinbase() with mpz_class::get_mpz_t() looks a lot > more sane as an implementation than my prototype... even when I correct > the assert to be "BOOST_ASSERT(number>0);" - as I originally intended. > > I found mpz_class::get_prec() - though I could neither make sense of the > returned values, nor find its documentation. > > While mpz_sizeinbase() is obviously far more efficient than my reference > implementation - is it as efficient as possible - given that I only care > about the degenerate binary case? > > > -- > You received this message because you are subscribed to the Google Groups > "mpir-devel" group. > To post to this group, send email to mpir-devel@googlegroups.com. > To unsubscribe from this group, send email to > mpir-devel+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/mpir-devel?hl=en. > > -- You received this message because you are subscribed to the Google Groups "mpir-devel" group. To post to this group, send email to mpir-devel@googlegroups.com. To unsubscribe from this group, send email to mpir-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/mpir-devel?hl=en.