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


Groups > comp.lang.python > #82314 > unrolled thread

Re: Coercing two numbers without coerce()

Started byChris Angelico <rosuav@gmail.com>
First post2014-12-11 09:32 +1100
Last post2014-12-11 09:32 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#82314 — Re: Coercing two numbers without coerce()

FromChris Angelico <rosuav@gmail.com>
Date2014-12-11 09:32 +1100
SubjectRe: Coercing two numbers without coerce()
Message-ID<mailman.16830.1418251156.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web