From: SF/projects/mingw n. l. <min...@li...> - 2012-06-22 16:15:11
|
Bugs item #3536816, was opened at 2012-06-21 01:04 Message generated for change (Comment added) made by clemensx You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=3536816&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: MinGW Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: clemens (clemensx) Assigned to: Nobody/Anonymous (nobody) Summary: Seg fault on mingw / gcc 4.7 with csqrt function Initial Comment: Dear all, I'm running a WinXP 32 bit system on an intel dual core CPU. As a compiler, I'm using the latest gcc version installed by the "mingw-get-inst-20120426.exe". I've only installed the C and C++ cumpiler and used the option "Download the latest...". The following code produces a seg fault which I was able to track down to the csqrt function. Debugging it, it gave me no hint at all what the problem is about. I'm also running a gcc 4.6.3 build on two different Ubuntu versions, which works fine. It also _worked_ fine when I was using the prior mingw build of gcc 4.6.2. Here's the code: ********************************************** #include <stdio.h> #include <math.h> #include <complex.h> #ifndef complex #define complex _Complex #endif typedef double complex cdoub; cdoub ccangl_out(const cdoub ni, const cdoub nt, const double cangl_i, char *tir) { double t2=1.-cangl_i*cangl_i; cdoub t1=1.-ni*ni/(nt*nt)*t2; if(creal(t1)>0.) { *tir=0; return csqrt(t1); } else if(creal(t1)==0.) { *tir=1; return csqrt(t1); } else { *tir=1; return -1.*csqrt(t1); } } void testing(void) { cdoub no=1.,ni=1.39+(1.1e-7*1.i),c_out; double c_in; char tir; for(c_in=.1;c_in<1.;c_in+=.01) c_out=ccangl_out(ni,no,c_in,&tir); printf("c_out: %g + %gi\n",creal(c_out),cimag(c_out)); } int main(void) { testing(); return 1; } ********************************************** Kind regards Clemens ---------------------------------------------------------------------- >Comment By: clemens (clemensx) Date: 2012-06-22 09:15 Message: Hey, here is a simplified one: ********************************************** #include <stdio.h> #include <math.h> #include <complex.h> double complex csqrt_out(const double complex ni) { return csqrt(ni); } int main(void) { double complex ni=1.+1.1e-7*1.i,c_out; c_out=csqrt(ni); printf("c_out: %g + %gi\n",creal(c_out),cimag(c_out)); c_out=csqrt_out(ni); printf("c_out: %g + %gi\n",creal(c_out),cimag(c_out)); return 1; } ********************************************** Now, I get the output: c_out: 1.88963e+265 + 6.72985e+268i Process returned -1073741819 (0xC0000005) Which means, that only the second call produces a seg fault, but the first one a false result. It should read 1. + 5.5*10^-8 I ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=3536816&group_id=2435 |