Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101987
| From | Matt Wheeler <m@funkyhat.org> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How to simulate C style integer division? |
| Date | 2016-01-22 00:51 +0000 |
| Message-ID | <mailman.156.1453424217.15297.python-list@python.org> (permalink) |
| References | (2 earlier) <56a0d24f$0$1614$c3e8da3$5496439d@news.astraweb.com> <lf5mvrzuj5z.fsf@ling.helsinki.fi> <87mvrzc8bx.fsf@elektro.pacujo.net> <mailman.155.1453405932.15297.python-list@python.org> <877fj263aj.fsf@elektro.pacujo.net> |
On 21 January 2016 at 21:17, Marko Rauhamaa <marko@pacujo.net> wrote: > Well, then there's: > > def intdiv(a, b): > return int(a / b) That depends on how accurate you need it to be >>> def intdiv(a, b): ... return a//b if (a < 0) == (b < 0) else -(-a//b) ... >>> num = 3**171 >>> num 3870210234510307998744588107535211184800325224934979257430349324033792477926791547 >>> num2 = 4**80 >>> num2 1461501637330902918203684832716283019655932542976 >>> intdiv(num, num2) 2648105301871818722187687529062555 >>> int(num/num2) 2648105301871818477801931416797184 -- Matt Wheeler http://funkyh.at
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: How to simulate C style integer division? Ben Finney <ben+python@benfinney.id.au> - 2016-01-21 20:11 +1100
Re: How to simulate C style integer division? Paul Rubin <no.email@nospam.invalid> - 2016-01-21 01:43 -0800
Re: How to simulate C style integer division? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-21 11:58 +0200
Re: How to simulate C style integer division? Steven D'Aprano <steve@pearwood.info> - 2016-01-21 23:42 +1100
Re: How to simulate C style integer division? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-21 16:00 +0200
Re: How to simulate C style integer division? Marko Rauhamaa <marko@pacujo.net> - 2016-01-21 16:31 +0200
Re: How to simulate C style integer division? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-21 16:48 +0200
Re: How to simulate C style integer division? Random832 <random832@fastmail.com> - 2016-01-21 14:52 -0500
Re: How to simulate C style integer division? Marko Rauhamaa <marko@pacujo.net> - 2016-01-21 23:17 +0200
Re: How to simulate C style integer division? Matt Wheeler <m@funkyhat.org> - 2016-01-22 00:51 +0000
Re: How to simulate C style integer division? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2016-01-21 15:22 +0100
csiph-web