[pypy-commit] pypy default: Special-case "x ** 2" here instead.

arigo noreply at buildbot.pypy.org
Sun Jan 22 12:22:35 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r51642:f1fb181c13a3
Date: 2012-01-22 12:22 +0100
http://bitbucket.org/pypy/pypy/changeset/f1fb181c13a3/

Log:	Special-case "x ** 2" here instead.

diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -443,6 +443,8 @@
     y = w_float2.floatval
 
     # Sort out special cases here instead of relying on pow()
+    if y == 2.0:                      # special case for performance:
+        return W_FloatObject(x * x)   # x * x is always correct
     if y == 0.0:
         # x**0 is 1, even 0**0
         return W_FloatObject(1.0)


More information about the pypy-commit mailing list