Thanks to visit codestin.com
Credit goes to github.com

Skip to content

base_repr(243, 3) returns '30000' (Trac #1549) #2146

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

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 7 comments
Closed

base_repr(243, 3) returns '30000' (Trac #1549) #2146

numpy-gitbot opened this issue Oct 19, 2012 · 7 comments

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/1549 on 2010-07-17 by trac user kmaglione, assigned to unknown.

Calling base_repr(343, 3) returns '30000' rather than the expected '100000'.

NumPy 1.4.1
%python -V
Python 2.6.5
%uname -a
Linux jg 2.6.34-ARCH #1 SMP PREEMPT Sat Jun 19 00:07:49 CEST 2010 x86_64 AMD Athlon(tm) 64 X2 Dual-Core Processor TK-55 AuthenticAMD GNU/Linux

@numpy-gitbot
Copy link
Author

@rgommers wrote on 2010-07-24

I'm assuming you meant 243:

In [22]: np.base_repr(3**4, 3)
Out[22]: '10000'

In [23]: np.base_repr(3**5, 3)
Out[23]: '30000'

In [24]: np.base_repr(3**6, 3)
Out[24]: '1000000'

In [25]: 3**5
Out[25]: 243

Something does look wrong.

@numpy-gitbot
Copy link
Author

trac user kmaglione wrote on 2010-07-24

Sorry, you're right. I meant 243/3**5. For what it's worth, the following returns the correct answer, and 5 times faster:

#!python
def base_repr(num, base, padding=0):
    digits='0123456789abcdef'
    s=[]
    while num:
        s.append(digits[num % base])
        num /= base
    res = ''.join(reversed(s or '0'))
    if padding:
        res = '0' * padding + res
    return res

@numpy-gitbot
Copy link
Author

@rgommers wrote on 2010-07-25

"digits" needs to include all letters, not just a-f. A new test for 3**5 should be included as well.

@numpy-gitbot
Copy link
Author

Attachment added by trac user kmaglione on 2010-07-25: numpy.core.base_repr.diff

@numpy-gitbot
Copy link
Author

trac user kmaglione wrote on 2010-07-25

Let me know if you need more or less tests.

@numpy-gitbot
Copy link
Author

@rgommers wrote on 2010-07-28

Committed in r8530 and r8531. Thanks!

@numpy-gitbot
Copy link
Author

Milestone changed to 1.6.0 by @mwiebe on 2011-05-24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant