Skip to content

Commit 7635805

Browse files
committed
fix: log as method gives symbolic output for non positive base
1 parent 871ba9d commit 7635805

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/sage/rings/integer.pyx

+11-3
Original file line numberDiff line numberDiff line change
@@ -2851,16 +2851,24 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
28512851
sage: ZZ(8).log(int(2))
28522852
3
28532853
2854+
Check that negative bases yield complex logarithms (:issue:`39959`)::
2855+
2856+
sage: 8.log(-2)
2857+
3*log(2)/(I*pi + log(2))
2858+
2859+
Check that zero base yield complex logarithms (:issue:`39959`)::
2860+
2861+
sage: 8.log(0)
2862+
0
2863+
28542864
TESTS::
28552865
28562866
sage: (-2).log(3) # needs sage.symbolic
28572867
(I*pi + log(2))/log(3)
28582868
"""
28592869
cdef int self_sgn
2860-
if m is not None and m <= 0:
2861-
raise ValueError("log base must be positive")
28622870
self_sgn = mpz_sgn(self.value)
2863-
if self_sgn < 0 and prec is None:
2871+
if (self_sgn < 0 or m<=0) and prec is None:
28642872
from sage.symbolic.ring import SR
28652873
return SR(self).log(m)
28662874
if prec:

0 commit comments

Comments
 (0)