Arkaitz Bitorika <arkaitz.bitorika <at> gmail.com> writes:
I've verified that the function causes the exception when embedded in the program but not when used from a simple C program with just a main () function. The successful version iterates 31 times over the for loop while the crashing one fails the 30th time that it does "pinf *= mul".
Now we know exactly where the crash is, but no idea how to fix it ;).
Hi, I just found this old thread, and it looks like I've got the very same problem: Turns out that Borland C++ Builder (which I'm using, and you are most probably as well) can't get to infinity by multiplying a number with 1E10 over and over, but throws an exception instead when ecceeding number space: On 22 Apr 2006, at 20:12, Andrew Straw wrote:
static double pinf_init(void) { double mul = 1e10; double tmp = 0.0; double pinf;
pinf = mul; for (;;) { pinf *= mul; if (pinf == tmp) break; tmp = pinf; } return pinf; }
My proposal is to ask the numpy people to patch numpy as follows: Don't multiply, but instead create pinf according to IEEE 754 specifications: char inf_string[9] = "\x00\x00\x00\x00\x00\x00\xF0\x7F"; double pinf = ((double*)inf_string)[0]; This will get rid of the overflow for little endian machines. For big endian architectures, just reverse the byte order in inf_string. I already submitted a bug report to their bugtracker. Cheers, Thomas