title: Do numerical programming languages distinguish between a "largest finite number" and "infinity"?
body: <p><strong>Question motivation:</strong></p>
  
  <p>In standard numerical languages of which I am aware (e.g. Matlab, Python numpy, etc.), if, for example, you take the exponential of a modestly large number, the output is infinity as the result of numerical overflow.  If this is multiplied by 0, you get NaN.  Separately, these steps are reasonable enough, but they reveal a logical mistake in the implementation of the math.  The first number resulting from overflow is known to be finite and we clearly want the result of a multiplication by 0 with this large finite number to be 0.  </p>
  
  <p>Explicitly:</p>
  
  <pre><code>&gt;&gt;&gt; import numpy as np
  &gt;&gt;&gt; np.exp(709)*0
  0.0
  &gt;&gt;&gt; np.exp(710)*0
  nan
  </code></pre>
  
  <p>I imagine we could here introduce a notion of the "largest finite value" (LFV) which would have the following properties:</p>
  
  <ul>
  <li>LFV would be the default for numerical overflow that would otherwise
  round up to infinity </li>
  <li>LFV &lt; infinity </li>
  <li>any explicit number &lt; LFV  (for example if LEV stands for "largest explicit value", then LEV
  <li>(MATLAB detail: realmax &lt; LFV) </li>
  <li>LFV*0 = 0</li>
  </ul>
  
  <p>On the other hand, infinity should not simply be redefined in the way described for LFV.  It does not make sense for 0 *infinity = 0...appropriately, the current standard implementation of infinity yields NaN in this setting.  Also, sometimes there arises a need to initialize numbers to infinity and you'd want the result of any numerical operation, even one that yielded LFV to be strictly less than the initialized value (this is convenient for some logical statements).  I'm sure other situations exist where a proper infinity is necessary -- my point is simply that infinity should <strong>not</strong> simply be redefined to have some of the LFV properties above. </p>
  
  <p><strong>The Question:</strong></p>
  
  <p>I want to know if there is any language which uses a scheme like this and if there are any problems with such a scheme.  This problem does not arise in proper math since there aren't these numerical limits on the size of numbers, but I think it is a real problem when implementing a consistent mathematics in programming languages.  Essentially, by LFV, I think I want a shorthand for the open interval between the largest explicit value and infinity LFV = (LEV,infinity), but maybe this intuition is wrong.</p>
  
  <p><em>Update: In the comments, people seem to be objecting a little to the utility of issue I'm bringing up.  My question arises not because many related issues occur, but rather because the same issue frequently arises in many different settings.  From talking to people who do data analysis, this is something that often enough contributes to runtime errors when training/fitting models.  The question is basically why this isn't handled by numerical languages.  From the comments, I'm essentially gathering that the people who write the languages don't see the utility of handling things this way.  In my opinion, when certain specific issues occur frequently enough for people using a language, it might make sense to handle those exceptions in a principled way so each user doesn't have to.</em>  </p>