title: Using Math.exp() in Javascript with BigDecimal for large floating point numbers
body: <p>I'm attempting to perform the following calculation in Javascript:</p>
  
  <pre><code>e^x / (1 + e^x)
  </code></pre>
  
  <p>where <code>x</code> is a long floating point number.</p>
  
  <p>In this instance, I require accuracy to at least the 10th decimal place.</p>
  
  <p>I've been using <a href="http://stz-ida.de/index.php?option=com_content&amp;id=18" rel="nofollow">BigDecimal</a> to accurately handle the floating point numbers, as suggested at <a href="http://floating-point-gui.de/languages/javascript" rel="nofollow">The Floating Point Guide</a>.</p>
  
  <p>My first attempt of:</p>
  
  <pre><code>var foo = new BigDecimal(myVeryLongFloatingPoint)
  var bar = Math.exp(foo);
  var spam = bar.divide(bar.add(new BigDecimal("1")));
  </code></pre>
  
  <p>led to the error (where xxxxx is the floating point number):</p>
  
  <pre><code>TypeError: Object xxxxx has no method 'add'
  </code></pre>
  
  <p>So I attempted to tried convert <code>bar</code> into a BigDecimal object:</p>
  
  <pre><code>var foo = new BigDecimal(myVeryLongFloatingPoint)
  var bar = new BigDecimal(Math.exp(foo));
  var spam = bar.divide(bar.add(new BigDecimal("1")));
  </code></pre>
  
  <p>which in turn leads to the error (where xxxxx is the floating point number):</p>
  
  <pre><code>BigDecimal(): Not a number: xxxxx
  </code></pre>
  
  <p>Where am I going wrong?</p>
  
  <p>Is this a sensible approach to handling this kind of calculation with floating points where a high degree of precision is required?</p>