Skip to content

fix: log as method gives symbolic output for non positive base #39986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/sage/rings/integer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2851,16 +2851,24 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
sage: ZZ(8).log(int(2))
3

Check that negative bases yield complex logarithms (:issue:`39959`)::

sage: 8.log(-2)
3*log(2)/(I*pi + log(2))

Check that zero base yield complex logarithms (:issue:`39959`)::

sage: 8.log(0)
0

TESTS::

sage: (-2).log(3) # needs sage.symbolic
(I*pi + log(2))/log(3)
"""
cdef int self_sgn
if m is not None and m <= 0:
raise ValueError("log base must be positive")
self_sgn = mpz_sgn(self.value)
if self_sgn < 0 and prec is None:
if self_sgn < 0 or (m is not None and m<=0) and prec is None:
from sage.symbolic.ring import SR
return SR(self).log(m)
if prec:
Expand Down
Loading