public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: std::isfinite broken?
       [not found] <20080728222713.GB16937@fsf.org>
@ 2008-07-30 15:29 ` Eus
  2008-07-30 15:58   ` Paolo Carlini
  0 siblings, 1 reply; 12+ messages in thread
From: Eus @ 2008-07-30 15:29 UTC (permalink / raw)
  To: Neal Becker; +Cc: gcc

Hi Ho!

--- On Tue, 7/29/08, "Neal Becker" <ndbecker2@gmail.com> 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:

eus@experimental:~/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;
}
eus@experimental:~/shared/del/PHP$ g++ -o a -O3 -ffast-math x.c
eus@experimental:~/shared/del/PHP$ ./a
Inside if
Outside if

eus@experimental:~/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


      

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: std::isfinite broken?
  2008-07-30 15:29 ` std::isfinite broken? Eus
@ 2008-07-30 15:58   ` Paolo Carlini
  2008-07-31 11:56     ` Neal Becker
  0 siblings, 1 reply; 12+ messages in thread
From: Paolo Carlini @ 2008-07-30 15:58 UTC (permalink / raw)
  To: eus; +Cc: gcc

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: std::isfinite broken?
  2008-07-30 15:58   ` Paolo Carlini
@ 2008-07-31 11:56     ` Neal Becker
  2008-07-31 12:54       ` Dave Korn
  0 siblings, 1 reply; 12+ messages in thread
From: Neal Becker @ 2008-07-31 11:56 UTC (permalink / raw)
  To: gcc

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: std::isfinite broken?
  2008-07-31 11:56     ` Neal Becker
@ 2008-07-31 12:54       ` Dave Korn
  2008-07-31 13:05         ` Dave Korn
  0 siblings, 1 reply; 12+ messages in thread
From: Dave Korn @ 2008-07-31 12:54 UTC (permalink / raw)
  To: 'Neal Becker', gcc

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....

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: std::isfinite broken?
  2008-07-31 12:54       ` Dave Korn
@ 2008-07-31 13:05         ` Dave Korn
  0 siblings, 0 replies; 12+ messages in thread
From: Dave Korn @ 2008-07-31 13:05 UTC (permalink / raw)
  To: 'Dave Korn', 'Neal Becker', gcc

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....

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: std::isfinite broken?
  2008-07-28 12:03   ` Paolo Carlini
@ 2008-07-28 13:20     ` Neal Becker
  0 siblings, 0 replies; 12+ messages in thread
From: Neal Becker @ 2008-07-28 13:20 UTC (permalink / raw)
  To: gcc

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: std::isfinite broken?
  2008-07-28 11:54   ` Neal Becker
  2008-07-28 12:00     ` Richard Guenther
@ 2008-07-28 12:10     ` Paolo Carlini
  1 sibling, 0 replies; 12+ messages in thread
From: Paolo Carlini @ 2008-07-28 12:10 UTC (permalink / raw)
  To: Neal Becker; +Cc: gcc

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: std::isfinite broken?
  2008-07-28 11:53 ` Paolo Carlini
  2008-07-28 11:54   ` Neal Becker
@ 2008-07-28 12:03   ` Paolo Carlini
  2008-07-28 13:20     ` Neal Becker
  1 sibling, 1 reply; 12+ messages in thread
From: Paolo Carlini @ 2008-07-28 12:03 UTC (permalink / raw)
  To: Neal Becker; +Cc: gcc

... 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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: std::isfinite broken?
  2008-07-28 11:54   ` Neal Becker
@ 2008-07-28 12:00     ` Richard Guenther
  2008-07-28 12:10     ` Paolo Carlini
  1 sibling, 0 replies; 12+ messages in thread
From: Richard Guenther @ 2008-07-28 12:00 UTC (permalink / raw)
  To: Neal Becker; +Cc: gcc

On Mon, Jul 28, 2008 at 1:52 PM, Neal Becker <ndbecker2@gmail.com> 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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: std::isfinite broken?
  2008-07-28 11:53 ` Paolo Carlini
@ 2008-07-28 11:54   ` Neal Becker
  2008-07-28 12:00     ` Richard Guenther
  2008-07-28 12:10     ` Paolo Carlini
  2008-07-28 12:03   ` Paolo Carlini
  1 sibling, 2 replies; 12+ messages in thread
From: Neal Becker @ 2008-07-28 11:54 UTC (permalink / raw)
  To: gcc

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")

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: std::isfinite broken?
  2008-07-28 11:51 Neal Becker
@ 2008-07-28 11:53 ` Paolo Carlini
  2008-07-28 11:54   ` Neal Becker
  2008-07-28 12:03   ` Paolo Carlini
  0 siblings, 2 replies; 12+ messages in thread
From: Paolo Carlini @ 2008-07-28 11:53 UTC (permalink / raw)
  To: Neal Becker; +Cc: gcc

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* std::isfinite broken?
@ 2008-07-28 11:51 Neal Becker
  2008-07-28 11:53 ` Paolo Carlini
  0 siblings, 1 reply; 12+ messages in thread
From: Neal Becker @ 2008-07-28 11:51 UTC (permalink / raw)
  To: gcc

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?

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-07-31 11:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20080728222713.GB16937@fsf.org>
2008-07-30 15:29 ` std::isfinite broken? Eus
2008-07-30 15:58   ` Paolo Carlini
2008-07-31 11:56     ` Neal Becker
2008-07-31 12:54       ` Dave Korn
2008-07-31 13:05         ` Dave Korn
2008-07-28 11:51 Neal Becker
2008-07-28 11:53 ` Paolo Carlini
2008-07-28 11:54   ` Neal Becker
2008-07-28 12:00     ` Richard Guenther
2008-07-28 12:10     ` Paolo Carlini
2008-07-28 12:03   ` Paolo Carlini
2008-07-28 13:20     ` Neal Becker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).