Cannot find erf()

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Cannot find erf()

Postby smd » Mon Jul 04, 2016 12:30 pm

I am trying to compile the NIST statistical test suite which is available as a set of standard C source files. The statistical test call the erf() (Gaussian error function). the library routine is supposed to be available by including <math.h>. It is not referenced at all in the header file.

Does RAD Studio have the erf() function? I cannot find it and it is a standard math function that is commonly used.
-----------------------------
Scott
smd
BCBJ Guru
BCBJ Guru
 
Posts: 130
Joined: Sat Nov 29, 2014 8:02 pm
Location: Las Vegas

Re: Cannot find erf()

Postby rlebeau » Mon Jul 04, 2016 2:30 pm

smd wrote:Does RAD Studio have the erf() function?


There is a std::erf() function in the <cmath> header for C++11, and a boost::math::erf() function in the <boost/math/special_functions/erf.hpp> header for pre-C++11.

I don't see an erf() function available for C, however erf() is fairly simple to implement manually:

Code: Select all
double erf(double x)
{
    // constants
    double a1 =  0.254829592;
    double a2 = -0.284496736;
    double a3 =  1.421413741;
    double a4 = -1.453152027;
    double a5 =  1.061405429;
    double p  =  0.3275911;

    // Save the sign of x
    int sign = 1;
    if (x < 0)
        sign = -1;
    x = fabs(x);

    // A&S formula 7.1.26
    double t = 1.0/(1.0 + p*x);
    double y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);

    return sign*y;
}
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1399
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA


Return to Technical

Who is online

Users browsing this forum: No registered users and 7 guests