[pypy-svn] r42182 - in pypy/branch/pypy-string-formatting: interpreter module/math objspace/cpy objspace/fake objspace/std rlib
arigo at codespeak.net
arigo at codespeak.net
Thu Apr 19 19:01:47 CEST 2007
Author: arigo
Date: Thu Apr 19 19:01:47 2007
New Revision: 42182
Modified:
pypy/branch/pypy-string-formatting/interpreter/baseobjspace.py
pypy/branch/pypy-string-formatting/module/math/interp_math.py
pypy/branch/pypy-string-formatting/objspace/cpy/objspace.py
pypy/branch/pypy-string-formatting/objspace/fake/objspace.py
pypy/branch/pypy-string-formatting/objspace/std/floatobject.py
pypy/branch/pypy-string-formatting/objspace/std/longobject.py
pypy/branch/pypy-string-formatting/rlib/rbigint.py
Log:
(cfbolz, arigo)
Kill space.log(), which was used in exactly one place.
Use space.bigint_w() instead, now that we have it.
Modified: pypy/branch/pypy-string-formatting/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/pypy-string-formatting/interpreter/baseobjspace.py (original)
+++ pypy/branch/pypy-string-formatting/interpreter/baseobjspace.py Thu Apr 19 19:01:47 2007
@@ -1015,6 +1015,5 @@
'newslice',
'call_args',
'marshal_w',
- 'log',
]
Modified: pypy/branch/pypy-string-formatting/module/math/interp_math.py
==============================================================================
--- pypy/branch/pypy-string-formatting/module/math/interp_math.py (original)
+++ pypy/branch/pypy-string-formatting/module/math/interp_math.py Thu Apr 19 19:01:47 2007
@@ -137,14 +137,28 @@
degrees.unwrap_spec = [ObjSpace, float]
def _log_any(space, w_x, base):
+ # base is supposed to be positive or 0.0, which means we use e
try:
- return space.log(w_x, base)
+ if space.is_true(space.isinstance(w_x, space.w_long)):
+ # special case to support log(extremely-large-long)
+ num = space.bigint_w(w_x)
+ result = num.log(base)
+ else:
+ x = space.float_w(w_x)
+ if base == 10.0:
+ result = math.log10(x)
+ else:
+ result = math.log(x)
+ if base != 0.0:
+ den = math.log(base)
+ result /= den
except OverflowError:
raise OperationError(space.w_OverflowError,
space.wrap('math range error'))
except ValueError:
raise OperationError(space.w_ValueError,
space.wrap('math domain error'))
+ return space.wrap(result)
def log(space, w_x, w_base=NoneNotWrapped):
"""log(x[, base]) -> the logarithm of x to the given base.
Modified: pypy/branch/pypy-string-formatting/objspace/cpy/objspace.py
==============================================================================
--- pypy/branch/pypy-string-formatting/objspace/cpy/objspace.py (original)
+++ pypy/branch/pypy-string-formatting/objspace/cpy/objspace.py Thu Apr 19 19:01:47 2007
@@ -366,7 +366,6 @@
def delete(self, *args): raise NotImplementedError("space.delete()")
def userdel(self, *args): raise NotImplementedError("space.userdel()")
def marshal_w(self, *args):raise NotImplementedError("space.marshal_w()")
- def log(self, *args): raise NotImplementedError("space.log()")
def exec_(self, statement, w_globals, w_locals, hidden_applevel=False):
"NOT_RPYTHON"
Modified: pypy/branch/pypy-string-formatting/objspace/fake/objspace.py
==============================================================================
--- pypy/branch/pypy-string-formatting/objspace/fake/objspace.py (original)
+++ pypy/branch/pypy-string-formatting/objspace/fake/objspace.py Thu Apr 19 19:01:47 2007
@@ -126,7 +126,6 @@
def delete(self, *args): raise NotImplementedError("space.delete()")
def userdel(self, *args): raise NotImplementedError("space.userdel()")
def marshal_w(self, *args):raise NotImplementedError("space.marshal_w()")
- def log(self, *args): raise NotImplementedError("space.log()")
gettypefor = make_dummy()
gettypeobject = make_dummy()
Modified: pypy/branch/pypy-string-formatting/objspace/std/floatobject.py
==============================================================================
--- pypy/branch/pypy-string-formatting/objspace/std/floatobject.py (original)
+++ pypy/branch/pypy-string-formatting/objspace/std/floatobject.py Thu Apr 19 19:01:47 2007
@@ -389,19 +389,6 @@
def getnewargs__Float(space, w_float):
return space.newtuple([W_FloatObject(w_float.floatval)])
-def log__Float(space, w_float, base):
- # base is supposed to be positive or 0.0, which means we use e
- x = space.float_w(w_float)
- if base == 10.0:
- return space.wrap(math.log10(x))
- num = math.log(x)
- if base == 0.0:
- return space.wrap(num)
- else:
- den = math.log(base)
- return space.wrap(num / den)
-
-
register_all(vars())
# pow delegation for negative 2nd arg
Modified: pypy/branch/pypy-string-formatting/objspace/std/longobject.py
==============================================================================
--- pypy/branch/pypy-string-formatting/objspace/std/longobject.py (original)
+++ pypy/branch/pypy-string-formatting/objspace/std/longobject.py Thu Apr 19 19:01:47 2007
@@ -254,9 +254,6 @@
def getnewargs__Long(space, w_long1):
return space.newtuple([W_LongObject(w_long1.num)])
-def log__Long(space, w_long, base):
- return space.wrap(w_long.num.log(base))
-
register_all(vars())
# register implementations of ops that recover int op overflows
Modified: pypy/branch/pypy-string-formatting/rlib/rbigint.py
==============================================================================
--- pypy/branch/pypy-string-formatting/rlib/rbigint.py (original)
+++ pypy/branch/pypy-string-formatting/rlib/rbigint.py Thu Apr 19 19:01:47 2007
@@ -1288,13 +1288,13 @@
def _loghelper(func, arg):
"""
A decent logarithm is easy to compute even for huge bigints, but libm can't
- do that by itself -- loghelper can. func is log or log10, and name is
- "log" or "log10". Note that overflow isn't possible: a bigint can contain
+ do that by itself -- loghelper can. func is log or log10.
+ Note that overflow isn't possible: a bigint can contain
no more than INT_MAX * SHIFT bits, so has value certainly less than
2**(2**64 * 2**16) == 2**2**80, and log2 of that is 2**80, which is
small enough to fit in an IEEE single. log and log10 are even smaller.
"""
- x, e = _AsScaledDouble(arg);
+ x, e = _AsScaledDouble(arg)
if x <= 0.0:
raise ValueError
# Value is ~= x * 2**(e*SHIFT), so the log ~=
More information about the Pypy-commit
mailing list