N
Nomak
Hello,
i've lost about hours (at least) to find a problem. I use the
following utility function:
13 template <typename T>
14 inline
15 T
16 diffabs(T a, T b)
17 {
18 T ret;
19
20 if (a > b)
21 ret = a - b;
22 else
23 ret = b - a;
24
25 if (ret < 0)
26 cerr << "ERROR: diffabs(" << a << ", "
27 << b << ") = " << ret << endl;
28
29 assert(ret >= 0);
30 return ret;
31 }
The verification part have been added after founding the bug.
At runtime, i have the assertion wich fails, but no error message, so
i run gdb:
#7 0x08050747 in diffabs<double> (a=-nan(0x8000000000000), b=-1)
29 assert(ret >= 0);
(gdb) print ret
$1 = -nan(0x8000000000000)
I don't even know wich path is taken. But the error message test fails
(<0) while the assert test is ok (>=0).
Please tell me it's not the way it should be and it's a compiler bug.
If it's the standard way, do you know why? And how can i detect if a
double if negativ or -nan ?
TIA
i've lost about hours (at least) to find a problem. I use the
following utility function:
13 template <typename T>
14 inline
15 T
16 diffabs(T a, T b)
17 {
18 T ret;
19
20 if (a > b)
21 ret = a - b;
22 else
23 ret = b - a;
24
25 if (ret < 0)
26 cerr << "ERROR: diffabs(" << a << ", "
27 << b << ") = " << ret << endl;
28
29 assert(ret >= 0);
30 return ret;
31 }
The verification part have been added after founding the bug.
At runtime, i have the assertion wich fails, but no error message, so
i run gdb:
#7 0x08050747 in diffabs<double> (a=-nan(0x8000000000000), b=-1)
29 assert(ret >= 0);
(gdb) print ret
$1 = -nan(0x8000000000000)
I don't even know wich path is taken. But the error message test fails
(<0) while the assert test is ok (>=0).
Please tell me it's not the way it should be and it's a compiler bug.
If it's the standard way, do you know why? And how can i detect if a
double if negativ or -nan ?
TIA