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


Groups > comp.lang.python > #82314

Re: Coercing two numbers without coerce()

References <CALxg4FXb=_--6aCgMq0fNqY=vYZhS_0B2odEWyWJ_ZM6s=HgyA@mail.gmail.com>
Date 2014-12-11 09:32 +1100
Subject Re: Coercing two numbers without coerce()
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16830.1418251156.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Dec 11, 2014 at 9:27 AM, Luciano Ramalho <luciano@ramalho.org> wrote:
> I know I can do type(A+B)(A), or A+B-B, but both alternatives are ugly
> and perform needless arithmetic.
>
> What do you suggest, now that the coerce() built-in is not available?

I would suggest just doing the arithmetic :) That's guaranteed to
work, and a little addition isn't that costly. (As long as you're not
Numberphile and implementing four-bit binary arithmetic in racing
dominoes. Then it's costly.)

ChrisA

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


Thread

Re: Coercing two numbers without coerce() Chris Angelico <rosuav@gmail.com> - 2014-12-11 09:32 +1100

csiph-web