This seems ridiculously basic, but I cannot find anywhere explaining how to do it.

If you evaluate certain undefined functions like 1/0 or Tan[\[Pi]/2], Mathematica evaluates to ComplexInfinity. For some reason, however, the following expression does not act as expected:

1/0 == ComplexInfinity

This results in

ComplexInfinity == ComplexInfinity

rather than the expected


So the question is, how do you test whether a function evaluates to ComplexInfinity, or better yet, how do you test if a function is (mathematically, not programmatically) undefined?

  • 2
    $\begingroup$ If you need to test if something returns ComplexInfinity, you can use something === ComplexInfinity. This is a structural test that'll only return True if the two symbols are identical. It's not a mathematical test like == is. $\endgroup$
    – Szabolcs
    Commented Feb 6, 2013 at 17:05
  • 2
    $\begingroup$ I think the reason why ComplexInfinity == ComplexInfinity doesn't evaluate is that the direction in the complex plane is considered unknown. Check this. $\endgroup$
    – Szabolcs
    Commented Feb 6, 2013 at 17:07
  • 2
    $\begingroup$ Something I didn't know before: it seems all of Infinity, -Infinity, ComplexInfinity are just special printed forms of DirectedInfinity. Check their FullForm or their Head: they have structure. $\endgroup$
    – Szabolcs
    Commented Feb 6, 2013 at 17:09
  • $\begingroup$ @Szabolcs Probably enough info in your three comments to combine them in an answer. $\endgroup$ Commented Feb 6, 2013 at 21:19

2 Answers 2


To understand why ComplexInfinity == ComplexInfinity, let's look at how Mathematica handles infinities. All of Infinity, -Infinity, ComplexInfinity are just displayed forms of DirectedInfinity:

In[1]:= FullForm /@ {Infinity, -Infinity, ComplexInfinity}
Out[1]= {DirectedInfinity[1], DirectedInfinity[-1], DirectedInfinity[]}

DirectedInfinity[z] represents an infinite quantity in the direction of z on the complex plane. ComplexInfinity is DirectedInfinity[]; i.e., an infinite quantity with an unknown direction. The reason it cannot be compared is that the direction is unknown.

If you need to test for ComplexInfinity in particular, you can use

something === ComplexInfinity

=== is a structural test that, unlike ==, does not take any mathematical meaning into account.

Finally, for your purpose, I think NumericalQ (your answer) is a very good solution.

  • $\begingroup$ Posted answer per request. $\endgroup$
    – Szabolcs
    Commented Feb 6, 2013 at 23:38
  • $\begingroup$ If all you want is to test if an input is infinite: MatchQ[(* stuff *), _DirectedInfinity]. +1 of course. $\endgroup$ Commented Feb 7, 2013 at 3:37

I found an easy way to do this, simply test the value of the function with NumericQ to determine if it evaluates to a number or not. I would still be interested to know what sort of object or entity ComplexInfinity is that I can't test whether it is equal to itself with ==.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.