Re: std::isfinite broken?
Paolo Carlini wrote: Hi ho, ho!! ;) It worked with me. Try a recent gcc (eg, 4.3.x) and you will get the same, actually expected, result of the original poster. Paolo. I believe this is a bug. I agree that -ffast-math will not always comply 100% with IEEE, as advertised. But, if I explicity ask isfinite(), I expect it to work. If it is really intended not to work, then at least documentation should state that.
RE: std::isfinite broken?
Neal Becker wrote on 31 July 2008 12:42: Paolo Carlini wrote: Hi ho, ho!! ;) It worked with me. Try a recent gcc (eg, 4.3.x) and you will get the same, actually expected, result of the original poster. Paolo. I believe this is a bug. I agree that -ffast-math will not always comply 100% with IEEE, as advertised. But, if I explicity ask isfinite(), I expect it to work. If it is really intended not to work, then at least documentation should state that. It does, as was already explained to you; re-read the thread. cheers, DaveK -- Can't think of a witty .sigline today
RE: std::isfinite broken?
Dave Korn wrote on 31 July 2008 12:45: Neal Becker wrote on 31 July 2008 12:42: If it is really intended not to work, then at least documentation should state that. It does, as was already explained to you; re-read the thread. Actually I can be more use than that, I'll show you the relevant bits of the manual: -ffast-math' Sets `-fno-math-errno', `-funsafe-math-optimizations', `-fno-trapping-math', `-ffinite-math-only' and ^^^ `-fno-signaling-nans'. `-ffinite-math-only' Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs. So, to address your point: But, if I explicity ask isfinite(), I expect it to work. Fine. But what do you expect to happen if you explicitly tell it that no number in your program will ever be infinite, and then call isinfinite? You told GCC that it could assume isinfinite will always return zero, so it took your word for that and replaced all the calls by a constant zero. What do you want to happen in those circumstances? cheers, DaveK -- Can't think of a witty .sigline today
Re: std::isfinite broken?
Hi Ho! --- On Tue, 7/29/08, Neal Becker [EMAIL PROTECTED] wrote: Paolo Carlini wrote: ... ah, ok, now I see what you meant, you meant that x is *not* finite, still, std::isfinite(x) != 0. Still, testcase badly needed... Paolo. #include cmath #include stdexcept int main () { double x = log (0); if (not std::isfinite (x)) { throw std::runtime_error (not finite); } } Compiled with -O3 -ffast-math will not throw. It worked with me. Here is the record: [EMAIL PROTECTED]:~/shared/del/PHP$ cat x.c #include iostream #include cmath #include stdexcept int main () { double x = log (0); if (not std::isfinite (x)) { std::cout Inside if std::endl; } std::cout Outside if std::endl; return 0; } [EMAIL PROTECTED]:~/shared/del/PHP$ g++ -o a -O3 -ffast-math x.c [EMAIL PROTECTED]:~/shared/del/PHP$ ./a Inside if Outside if [EMAIL PROTECTED]:~/shared/del/PHP$ g++ -v Reading specs from /usr/lib/gcc-lib/i486-slackware-linux/3.3.6/specs Configured with: ../gcc-3.3.6/configure --prefix=/usr --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --target=i486-slackware-linux --host=i486-slackware-linux Thread model: posix gcc version 3.3.6 Best regards, Eus
Re: std::isfinite broken?
Hi ho, ho!! ;) It worked with me. Try a recent gcc (eg, 4.3.x) and you will get the same, actually expected, result of the original poster. Paolo.
Re: std::isfinite broken?
Neal Becker wrote: gcc-4.3.0-8.x86_64 I have test code that does passes std::isfinite (x), yet if I print the values to std::cout the value printed is 'inf'. Is std::isfinite (x) broken? Whatever bug it may have - it can, of course - std::isfinite returns an *int*, therefore your statement seems at the very least rather weird. A self-contained testcase is badly needed. Paolo.
Re: std::isfinite broken?
Paolo Carlini wrote: Neal Becker wrote: gcc-4.3.0-8.x86_64 I have test code that does passes std::isfinite (x), yet if I print the values to std::cout the value printed is 'inf'. Is std::isfinite (x) broken? Whatever bug it may have - it can, of course - std::isfinite returns an *int*, therefore your statement seems at the very least rather weird. A self-contained testcase is badly needed. Paolo. I found that compiling without -ffast-math would allow std::isfinite to work. Sorry if the statement was confusing. The code looks something like: [calculate x] if (not isfinite (x)) throw std::runtime_error (blah)
Re: std::isfinite broken?
On Mon, Jul 28, 2008 at 1:52 PM, Neal Becker [EMAIL PROTECTED] wrote: Paolo Carlini wrote: Neal Becker wrote: gcc-4.3.0-8.x86_64 I have test code that does passes std::isfinite (x), yet if I print the values to std::cout the value printed is 'inf'. Is std::isfinite (x) broken? Whatever bug it may have - it can, of course - std::isfinite returns an *int*, therefore your statement seems at the very least rather weird. A self-contained testcase is badly needed. Paolo. I found that compiling without -ffast-math would allow std::isfinite to work. That's by desing. With -ffast-math you are assessing that Infs and NaNs do not occur, so the compiler optimizes the call to isfinite. Richard.
Re: std::isfinite broken?
... ah, ok, now I see what you meant, you meant that x is *not* finite, still, std::isfinite(x) != 0. Still, testcase badly needed... Paolo.
Re: std::isfinite broken?
Neal Becker wrote: I found that compiling without -ffast-math would allow std::isfinite to work. Sorry if the statement was confusing. The code looks something like: [calculate x] if (not isfinite (x)) throw std::runtime_error (blah) Well, -ffast-math implies -ffinite-math-only, I think you have to pass -fno-finite-math-only if you want to deal correctly with infinities. Paolo.
Re: std::isfinite broken?
Paolo Carlini wrote: ... ah, ok, now I see what you meant, you meant that x is *not* finite, still, std::isfinite(x) != 0. Still, testcase badly needed... Paolo. #include cmath #include stdexcept int main () { double x = log (0); if (not std::isfinite (x)) { throw std::runtime_error (not finite); } } Compiled with -O3 -ffast-math will not throw.