PDA

View Full Version : erf / erfc (error function / complementary error function)



guiismiti
3rd February 2015, 06:28
Hi,

I'm trying to use erfc in my app.
I used it successfully in CodeBlocks using math.h, but it looks like neither math.h or cmath or QtCore/qmath.h have got erfc in Qt.

Is there a way to use this function on Qt or a way to use the math.h I have for CodeBlocks in Qt?


Thanks in advance.

Radek
3rd February 2015, 06:46
Both erf() and erfc() are C-standard (not Qt-standard) functions. Include math.h, math.h should be on the standard INCLUDE path. If it is not, search math.h by your file manager, you should be successful. As to Linux, glibc knows both erf() and erfc().

guiismiti
3rd February 2015, 14:00
math.h should be on the standard INCLUDE path. If it is not, search math.h by your file manager, you should be successful.

It is on the standard path, and so is cmath.h.
I found math.h inside the mingw folder, which is inside the Tools folder.
I tried including the path all the way to math.h, like this

<../../Tools/mingw491_32/i686-w64-mingw32/include/c++/tr1/math.h>
<../../Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/tr1/math.h>
<C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/tr1/math.h>

but had no success.
I'm gonna try to set mingw as the compiler.


Edited: I have also tried to add

INCLUDEPATH += <C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/tr1/math.h>

to my .pro, but no success.

anda_skoa
3rd February 2015, 14:18
What actually is the error you are getting?

Cheers,
_

guiismiti
3rd February 2015, 14:20
What actually is the error you are getting?

'erfc': identifier not found

anda_skoa
3rd February 2015, 16:17
And you are including math.h in that source file?

What about other functions from math.h? Say sin()?

Cheers,
_

guiismiti
3rd February 2015, 16:41
I'm currently including QtCore/qmath.h, which has sin and exp (I'm also using exp in my app).

I tried replacing it with math.h, and it recognizes sin and exp, but not erfc.

Radek
3rd February 2015, 16:54
#include <math.h> should suffice. If you suspect your standard C libraries (or the math.h header file) being somehow strange, remove #include <math.h> and add in the files containing erf() or erfc():


extern "C"
{
double erf( double x);
double erfc( double x);
}

If the code does not link (undefined externals) then your C libraries do not know erf() and erfc(). Change the compiler (and the libraries) because the libraries are too obsolete. erf() and erfc() are C-standard since C99.

guiismiti
3rd February 2015, 17:05
I'm gonna have to change the compiler, the other things did not work.
I'm currently using the MSVC2012 compiler, which came with Qt for windows.

I found mingw in my Qt/Tools folder, which has math.h with erf and erfc, that's why I tried to include it. The only math.h files in my Qt folder are inside mingw.


Thanks

d_stranz
3rd February 2015, 17:35
You are headed for big trouble if you are trying to use headers from mingw in programs you are compiling with MSVC. Like mixing fire and gasoline.


MSVC2012 compiler, which came with Qt for windows.

Really? I'd like to know when Microsoft jumped onto the Qt wagon. And I'd like to know where you downloaded that Qt version. I'd sure like to save the thousands of dollars I give M$ every year for my MSVC updates.

In Visual Studio 9 (VS 2008), math.h and cmath do not contain declarations for erf() / erfc(). In Visual Studio 12 (VS 2013), math.h and cmath do contain these functions, so the runtime libraries must also. I don't know about VS 2012 - I do not have that installed.

But Google is your friend (http://www.johndcook.com/blog/cpp_erf/).

ChrisW67
3rd February 2015, 20:24
Not declared in the 2012 compiler headers:
https://msdn.microsoft.com/en-us/library/7wsh95e5(v=vs.110).aspx

The Boost Math tool kit contains implementations of those functions but may be overkill