Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87518

Re: More or less code in python?

Date 2015-03-16 03:32 -0400
From Dave Angel <davea@davea.name>
Subject Re: More or less code in python?
References <8412cc81-fbd2-4590-9db3-12c65ba2ee35@googlegroups.com> <mailman.399.1426444300.21433.python-list@python.org> <53b202e7-327b-412a-a5e0-debca5c3b489@googlegroups.com> <87h9tmt796.fsf@jester.gateway.sonic.net> <dbdd7715-7418-49d1-9c52-e7cfdf16d733@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.418.1426491168.21433.python-list@python.org> (permalink)

Show all headers | View raw


On 03/15/2015 03:09 PM, jonas.thornvall@gmail.com wrote:
> Den söndag 15 mars 2015 kl. 20:01:36 UTC+1 skrev Paul Rubin:
>> jonas.thornvall@gmail.com writes:
>>> I though it would be interesting doing comparissons in timing adding
>>> massive digits in different bases. Especially in Python.
>>
>> Python has built-in bignums.  Try "print 2**500".
>
> I will try implement the common operators + - * / pow sqrt operators mod floor and and a generic parser taking arguments in any base.
>

Why on earth would you bother?  Use the int(x, base) to convert a string 
in an arbitrary base to an int.  Write a similar function to convert an 
int back into a string of the desired base.  Of course, your strings 
aren't in a standard form, so you'd have to do some work to get those 
instead.  Are you really intending to use a base beyond 36?

Then to add two numbers, use +     To multiply, use *, and so on.

Assuming Python 3.x of course.  if you're in Python 2, you'd use "long" 
rather than int.

-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 11:07 -0700
  Re: More or less code in python? Joel Goldstick <joel.goldstick@gmail.com> - 2015-03-15 14:31 -0400
    Re: More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 11:56 -0700
    Re: More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 12:00 -0700
      Re: More or less code in python? Paul Rubin <no.email@nospam.invalid> - 2015-03-15 12:01 -0700
        Re: More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 12:03 -0700
        Re: More or less code in python? jonas.thornvall@gmail.com - 2015-03-15 12:09 -0700
          Re: More or less code in python? Dave Angel <davea@davea.name> - 2015-03-16 03:32 -0400
          Re: More or less code in python? Chris Angelico <rosuav@gmail.com> - 2015-03-16 18:36 +1100
          Re: More or less code in python? Dave Angel <davea@davea.name> - 2015-03-16 03:44 -0400
  Re: More or less code in python? Peter Otten <__peter__@web.de> - 2015-03-15 20:15 +0100

csiph-web