4
$\begingroup$

I need something like this

a = 101010/0;
If[a == ComplexInfinity, True, False]

But if I use ToString, I get what I want.

a = 101010/0;
If[ToString[a] == "ComplexInfinity", True, False]

Does someone know a better way to do this?, I can't belive that transforming to a string is the only way.

$\endgroup$
3
  • $\begingroup$ This question might be interesting for you Max of a table/list with indeterminate values. $\endgroup$
    – Artes
    Commented Sep 13, 2014 at 22:29
  • 7
    $\begingroup$ I think you want SameQ (===) i.e. If[a === ComplexInfinity, True, False] $\endgroup$
    – RunnyKine
    Commented Sep 13, 2014 at 22:30
  • 1
    $\begingroup$ The title says Indeterminate but the question shows only ComplexInfinity -- do you mean both symbols, or just one, or something else? $\endgroup$
    – Michael E2
    Commented Sep 13, 2014 at 23:19

3 Answers 3

10
$\begingroup$

For the record, as RunnyKine wrote in a comment

a = 101010/0;
If[a === ComplexInfinity, True, False]
True

is what you are looking for.

$\endgroup$
0
2
$\begingroup$

you can also try:

a = 101010/0;
If[1/a == 0, True, False]
$\endgroup$
1
$\begingroup$

A generalization could look like this:

{1, 101010/0, 2, 0/0, Infinity, -Infinity} /.
   ComplexInfinity | DirectedInfinity | Indeterminate :> True /. True[1 | -1] -> True

{1, True, 2, True, True, True}

$\endgroup$
1
  • 2
    $\begingroup$ Or ... /. ComplexInfinity | DirectedInfinity[1] | DirectedInfinity[-1] | Indeterminate :> True $\endgroup$
    – Bob Hanlon
    Commented Sep 14, 2014 at 0:02

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.