title: Chi-Squared Probability Function in C++
body: <p>The following code of mine computes the confidence interval using Chi-square's 'quantile' and probability function from Boost.</p>
  
  <p>I am trying to implement this function as to avoid dependency to Boost. Is there any resource where can I find such implementation?</p>
  
  <pre><code>#include &lt;boost/math/distributions/chi_squared.hpp&gt;
  #include &lt;boost/cstdint.hpp&gt;
  
  using namespace std;     
  using boost::math::chi_squared; 
  using boost::math::quantile;
  
  vector &lt;double&gt; ConfidenceInterval(double x) {
      vector &lt;double&gt; ConfInts; 
  
      // x is an estimated value in which
      // we want to derive the confidence interval.
  
      chi_squared distl(2);     
      chi_squared distu((x+1)*2);
  
      double alpha = 0.90;      
  
      double lower_limit = 0;   
  
      if (x != 0) {
          chi_squared distl(x*2);   
          lower_limit = (quantile(distl,((1-alpha)/2)))/2;
      }
  
      double upper_limit = (quantile(distu,1-((1-alpha)/2)))/2;
  
      ConfInts.push_back(lower_limit);
      ConfInts.push_back(upper_limit);
  
      return ConfInts;         
  }
  </code></pre>