Opened 9 years ago

Closed 9 years ago

#4803 defect closed fixed (fixed)

Conch breaks __builtin__ pow with floats

Reported by: spiv Owned by:
Priority: normal Milestone:
Component: conch Keywords:
Cc: Branch: branches/pow-floats-4803
branch-diff, diff-cov, branch-cov, buildbot
Author: spiv

Description

>>> pow(2.5, 2)
6.25
>>> import twisted.conch.ssh.common
>>> pow(2.5, 2)
mpz(4)
>>> 

I'll make a fix for this.

Change History (7)

comment:1 Changed 9 years ago by spiv

Owner: changed from z3p to spiv
Status: newassigned

comment:2 Changed 9 years ago by spiv

Keywords: review added
Owner: spiv deleted
Status: assignednew

I have a fix in bzr at lp:~spiv/twisted/pow-floats-4803. You can see the diff here: <http://bazaar.launchpad.net/~spiv/twisted/pow-floats-4803/revision/15708>.

This version is very slightly slower due to the type-checking, but still much faster than the builtin pow for sufficiently large integers. And correctness > speed anyway.

comment:3 Changed 9 years ago by Jonathan Lange

Keywords: review removed
Owner: set to spiv

Thanks for the patch. It looks good to me, on the whole.

We discussed in person whether the type checking could be replaced with a check like if x == int(x), and decided that it would be too inefficient in the cases where x is already an mpz.

There are a few places in the tests where you've neglected to add a space after a comma. Please fix those before landing.

comment:4 Changed 9 years ago by spiv

Author: spiv
Branch: branches/pow-floats-4803

(In [30447]) Branch to pow-floats-4803

comment:5 Changed 9 years ago by spiv

(In [30448]) Don't break pow(base, exp) where base is not an integer. Refs #4803.

comment:6 Changed 9 years ago by spiv

Resolution: fixed
Status: newclosed

(In [30456]) Merge pow-floats-4803: Don't break builtin pow with non-integer bases.

Author: spiv Reviewers: jml, exarkun Fixes: #4803

Fix the _fastpow hack in twisted.ssh.common so that non-integer values passed to pow aren't silently converted to integers.

comment:7 Changed 9 years ago by <automation>

Owner: spiv deleted
Note: See TracTickets for help on using tickets.