[Python-bugs-list] [ python-Bugs-823209 ] cmath.log doesn't have the same interface as math.log.

SourceForge.net noreply at sourceforge.net
Mon Oct 27 17:03:09 EST 2003


Bugs item #823209, was opened at 2003-10-14 00:23
Message generated for change (Comment added) made by jemfinch
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=823209&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Jeremy Fincher (jemfinch)
Assigned to: Martin v. Löwis (loewis)
Summary: cmath.log doesn't have the same interface as math.log.

Initial Comment:
Somewhere along the way, math.log gained an optional
"base" argument.  cmath.log is still missing it.

>>> print math.log.__doc__
log(x[, base]) -> the logarithm of x to the given base.
If the base not specified, returns the natural
logarithm (base e) of x.

>>> print cmath.log.__doc__
log(x)

Return the natural logarithm of x.

----------------------------------------------------------------------

>Comment By: Jeremy Fincher (jemfinch)
Date: 2003-10-27 17:03

Message:
Logged In: YES 
user_id=99508

In my particular usecase, I define an environment in which
people can execute mathematical statements like so:

_mathEnv = {'__builtins__': new.module('__builtins__'), 'i': 1j}
_mathEnv.update(math.__dict__)
_mathEnv.update(cmath.__dict__)

As you can see, the cmath definitions shadow the math
definitions, and thus I lose the useful ability to offer
users a log with a base (which those that know Python expect
to work).

That's at least my particular use case.  In this particular
instance, since I don't want to allow the users to cause the
application to consume arbitrary amounts of memory, I can't
allow integer arithmetic (because of the crazy int/long
unification that left people who wanted computationall
bounded arithmetic with no choice but to implement a
fixed-size integer type or use float/complex instead ;)) so
I use complex objects everywhere, and math.log can't operate
on complex objects (even those that have no imaginary
component).

----------------------------------------------------------------------

Comment By: Andrew Gaul (gaul)
Date: 2003-10-27 15:20

Message:
Logged In: YES 
user_id=139865

Base 2 logarithms are somewhat common.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-10-27 14:44

Message:
Logged In: YES 
user_id=80475

I can fix this if necessary.

My question is whether it should be done.  On the one hand,
it is nice to have the two interfaces as symmetrical as
possible.  OTOH,  I'm not aware of any use cases for log(z, b).



----------------------------------------------------------------------

Comment By: Andrew Gaul (gaul)
Date: 2003-10-18 14:42

Message:
Logged In: YES 
user_id=139865

See patch #826074 for a fix.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=823209&group_id=5470



More information about the Python-bugs-list mailing list