Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6009265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:56:45+00:00 2026-05-23T01:56:45+00:00

It seems that cmath for visual studio 2005 does not have erf(x). I am

  • 0

It seems that cmath for visual studio 2005 does not have erf(x). I am using NIST Statistical Test Suite for Random and Pseudorandom Number Generators. In cephes.c’s method, double cephes_normal(double x), it uses a C99 math function erf(x) which I don’t believe is supported by visual studio 2005.

How can I overcome this problem? I saw a C++ solution here:
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/9f5f4bf4-c0ae-4620-8039-4dc36e98d718/

Someone used the boost C++ math library. But I don’t think I can include a c++ header into a C source file.

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:56:45+00:00Added an answer on May 23, 2026 at 1:56 am

    Some Googling found this C++ implementation (reposted here):

    erf code:

    #include <cmath>
    
    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;
    }
    

    Test function

    void testErf()
    {
        // Select a few input values
        double x[] = 
        {
            -3, 
            -1, 
            0.0, 
            0.5, 
            2.1 
        };
    
        // Output computed by Mathematica
        // y = Erf[x]
        double y[] = 
        { 
            -0.999977909503, 
            -0.842700792950, 
            0.0, 
            0.520499877813, 
            0.997020533344 
        };
    
        int numTests = sizeof(x)/sizeof(double);
    
        double maxError = 0.0;
        for (int i = 0; i < numTests; ++i)
        {
            double error = fabs(y[i] - erf(x[i]));
            if (error > maxError)
                maxError = error;
        }
    
        std::cout << "Maximum error: " << maxError << "\n";
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that this handy Quick Access window does not show the items available
Seems that a site I made for fun does not like to work in
It seems that altough I have been using NHibernate for a while now, I
When I try to read my cookie that I have set something does not
It seems that jQuery :contains selector does not work on IE8. Please see following
Seems that requirements on safety do not seem to like systems that use AI
Seems that when i create an object, the time is not correct. You can
Seems that it may not be possible, but hey I might as well ask,
It seems that i have this weird behavior in my Web Client My application
Seems that there are not much work done on Haskell for web. People uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.