Repository: sympy/sympy

Issue:
limit(sign(sin(x)), x, 0, '+')) = 0 (which is wrong)
Putting a sine inside a sign operation results in wrong solution.

Here is a code example:

```python
from sympy import *

x = symbols("x")
print("limit(sign(x), x, 0, '+') =", limit(sign(x), x, 0, "+")) # correct
print("limit(sign(sin(x)), x, 0, '+')) =", limit(sign(sin(x)), x, 0, "+")) # wrong
```

Also Wolfram Alpha has a different solution:

https://www.wolframalpha.com/input/?i=limit+sign%28sin%28x%29%29+for+x-%3E0%2B

Im using sympy 1.5 and mpmath 1.1.0.

Discussion:

Patch:
diff --git a/sympy/functions/elementary/complexes.py b/sympy/functions/elementary/complexes.py
index 6d7ea7c989..2f316a332f 100644
--- a/sympy/functions/elementary/complexes.py
+++ b/sympy/functions/elementary/complexes.py
@@ -422,6 +422,15 @@ def _eval_power(self, other):
         ):
             return S.One
 
+    def _eval_nseries(self, x, n, logx, cdir=0):
+        arg0 = self.args[0]
+        x0 = arg0.subs(x, 0)
+        if x0 != 0:
+            return self.func(x0)
+        if cdir != 0:
+            cdir = arg0.dir(x, cdir)
+        return -S.One if re(cdir) < 0 else S.One
+
     def _sage_(self):
         import sage.all as sage
         return sage.sgn(self.args[0]._sage_())


Test patch:
diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py
index 56774a4cfe..5492772918 100644
--- a/sympy/series/tests/test_limits.py
+++ b/sympy/series/tests/test_limits.py
@@ -796,6 +796,11 @@ def test_issue_17792():
     assert limit(factorial(n)/sqrt(n)*(exp(1)/n)**n, n, oo) == sqrt(2)*sqrt(pi)
 
 
+def test_issue_18118():
+    assert limit(sign(sin(x)), x, 0, "-") == -1
+    assert limit(sign(sin(x)), x, 0, "+") == 1
+
+
 def test_issue_18306():
     assert limit(sin(sqrt(x))/sqrt(sin(x)), x, 0, '+') == 1