Thread: Error function, erf(x)

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    3

    Error function, erf(x)

    Hello everybody,

    i'm a beginner in programming, so I hope someone can help me.
    I'm programming in Visual Studio 2008 in C++ and I'd like to use the error functionor the complementary one, erf(x) and erfc(x). I've looked for a solution in the internet and I've seen that including math.h should be enough, because this function is in this header. So I tried doing #include <math.h>,#include <math>, #include "math.h",#include <cmath.h>, #include <cmath> but during compilation an error appears, C3861: not found "erf" identifier.

    Could someone help me solving this?

    Thank you very much

  2. #2
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    How are you using it ? This works for me :

    Code:
    #include <cmath>
    #include <iostream>
    using namespace std;
    
    int main()
    {
        double x;
        x = erf(2);
        cout << x << endl;
    
        return 0;
    }

    Output :
    Code:
    0.995322

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    3
    Well, I tried your program and does not work for me. I get always the same error.

  4. #4
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Some people will massacre me for saying this, but I've never gotten along with Visual Studio. I suggest ( and people will massacre me for this too ) you try Code::Blocks. It's free and I've never had any problems with it, when coding under Windows - not for the basics, anyway :P

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    erf is a C99 function, I believe, which Visual Studio does not support, which would be why it isn't in either math.h or cmath.
    You also should be using Visual Studio 2010.
    Also, Korhedron, your inability to never figure out Visual Studio doesn't mean others cannot or will not. It is fine for basic programming as well as advanced.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Quote Originally Posted by Elysia View Post
    Also, Korhedron, your inability to never figure out Visual Studio doesn't mean others cannot or will not. It is fine for basic programming as well as advanced.
    Also, Elysia, your inability to accept other peoples preferences, doesn't mean others cannot or will not. Code::Blocks or any other alternative is just as fine for basic programming as well as advanced.

    Aside from that fact, your very own earlier statement that:
    erf is a C99 function, I believe, which Visual Studio does not support
    already indicates that the OP may be required to use another compiler/IDE for his particular needs.

    For future reference, please check your posts for logical consistency before bothering anyone with your inane pro-MSVS/C++ crusade.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    In no way did I say "don't use anything else."
    All I did say was "Visual Studio is not a bad IDE; don't dismiss it."
    It has an equal right to be used just as C::B. Point is, use whatever you like. Saying "use X" is bad, like Korhedron just did!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    *Sighs*

    I suggested a solution that would solve the OP's problems. I didn't tell him not to use Visual Studio. Actually, I used the words, "I suggest", while you, Elysia, told him he "should be using"... Which of us told him to "use X" ?

    Mwaahaaa has condensed both of our replies into an easily-understood point for Lomko : you might need another IDE. Whichever you choose is mostly irrelevant - Elysia suggests that updating your Visual Studio will solve the problem, so if you're comfortable using VS, that's probably the best solution. Personally, under Windows, I use Code::Blocks, but that's just me. People tend to stick to their preferences quite strongly, which is why my earlier post said that some people would take offense when I suggested you try Code::Blocks. Clearly, Elysia did.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I said no such thing. What I did say is that you should not be using VS2008. IF you're going to use Visual Studio, you should be using 2010.
    And nowhere did I say it would solve the problems. Clearly, it will not because Microsoft isn't supporting C99.
    I wasn't too happy at someone dismissing VS simple because someone couldn't use it properly. Being used to an IDE makes it easier to use than others. Will I find it easier to use C::B instead of VS? Most certainly not. Will I find it comfortable? Most certainly not. I have tried.
    The point is, you didn't like it. Others may. You simply suggested using C::B because you couldn't figure out how to use VS. That won't cut it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    This is the last post I'll be making in this thread, because you're not worth arguing with. Did I suggest something that would solve his problem ? Yes. Did you ? No.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Whatever you say.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Jul 2010
    Posts
    3
    Thank you guys

Popular pages Recent additions subscribe to a feed