4

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.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257

3 Answers3

10

For the record, as RunnyKine wrote in a comment

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

is what you are looking for.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
2

you can also try:

a = 101010/0;
If[1/a == 0, True, False]
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78
1

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}

eldo
  • 67,911
  • 5
  • 60
  • 168