---
layout: page
title: "JavaScript expm1 function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/expm1:770
- /functions/view/expm1
- /functions/view/770
- /functions/expm1:770
- /functions/770
---
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's expm1

{% codeblock math/expm1.js lang:js https://raw.github.com/kvz/phpjs/master/functions/math/expm1.js raw on github %}
function expm1 (x) {
  // From: http://phpjs.org/functions
  // +   original by: Brett Zamir (http://brett-zamir.me)
  // %          note 1: Precision 'n' can be adjusted as desired
  // *     example 1: expm1(1e-15);
  // *     returns 1: 1.0000000000000007e-15
  var ret = 0,
    n = 50; // degree of precision
  var factorial = function factorial(n) {
    if ((n === 0) || (n === 1)) {
      return 1;
    } else {
      var result = (n * factorial(n - 1));
      return result;
    }
  };
  for (var i = 1; i < n; i++) {
    ret += Math.pow(x, i) / factorial(i);
  }
  return ret;
}
{% endcodeblock %}

 - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/math/expm1.js)

Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are 
the closest match to this hashtable-like data structure. 

Please also note that php.js offers community built functions and goes by the 
[McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online 
functions that are far from perfect, in the hopes to spark better contributions. 
Do you have one? Then please just: 

 - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/math/expm1.js)

### Example 1
This code
{% codeblock lang:js example %}
expm1(1e-15);
{% endcodeblock %}

Should return
{% codeblock lang:js returns %}
1.0000000000000007e-15
{% endcodeblock %}


### Other PHP functions in the math extension
{% render_partial _includes/custom/math.html %}
