title: What is the best way to check for infinity in a Perl module?
body: <p>In one of my modules, I have to deal with the concept of infinity.  To date, I have been using <code>9**9**9</code> as positive infinity, and this seems to work well, is fast, and seems to be what perl's internals use as infinity.  </p>
  
  <p>However, things get a bit dicey if a user of my module decides to use one of the big number modules (like <code>use bigint;</code>), and then they use <code>inf</code> or <code>Math::BigInt-&gt;binf()</code> to represent infinity.</p>
  
  <p>In some places it seems to work fine, but in others, comparisons that should be true or should be false end up the wrong way round leading to difficult to track down bugs.</p>
  
  <p>I would like to support the various other notions of infinity with something that will work with both normal perl numbers, and arbitrary precision numbers. </p>
  
  <p>But I also have concerns about performance since some of my comparisons to infinity occur in tight inner loops.  Obviously <code>inf</code> from <code>Math::BigInt</code> is going to be slower than <code>9**9**9</code> (due to either calling tied or overloaded methods on each access).  Has anyone dealt with this problem in the past?  If so, what was your solution?</p>
  
  <p>I've thought about using my own constant for infinity, defined something like this:</p>
  
  <pre><code>use constant INF =&gt; if_any_bignum_modules_loaded() 
                      ? Math::BigInt-&gt;binf 
                      : 9**9**9;
  </code></pre>
  
  <p>And then adding the caveat to my module that any bignum modules should be loaded first.  Does this sound sensible?  Is there a reliable implementation of <code>if_any_bignum...</code> out there, or should I roll my own?</p>