public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: jcas@netcabo.pt
To: gcc-gnats@gcc.gnu.org
Subject: c/7857: Different behaviour if compiled with optimization!
Date: Sun, 08 Sep 2002 07:46:00 -0000	[thread overview]
Message-ID: <20020908143646.962.qmail@sources.redhat.com> (raw)


>Number:         7857
>Category:       c
>Synopsis:       Different behaviour if compiled with optimization!
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 08 07:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jose Santos
>Release:        3.10
>Organization:
>Environment:
Windows XP
>Description:
If code is compiled with any optimization (-O1 to -O3) it has a different behaviour than with compiled with no optimizations.
The code is related with precision errors.With optimizations there are no precision errors, without optimization there's a precision error!
>How-To-Repeat:
Just run the file with -O3 and without -O3 and see that in first case it runs fine(requires a couple of seconds, eg: 15s), in second case it enters an infinite loop(and just ends after looping all integers back to 0)
>Fix:
Don't known...perhaps don't use the sqrt function ?
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="bug.c"
Content-Disposition: inline; filename="bug.c"

#include <stdio.h>
#include <math.h>

/*
Compile with -O3 and runs fine
without there's a precision error.
SQ's value has the correct value with -O3 (+1 than without -O3 for n==46611179)

E-mail me at jcas@netcabo.pt
*/
#define NUMPAIRS 10

int main(){
  long long n=2, count = 0;
  for(n=2; count<NUMPAIRS; n++){
    long long n2 =n*n;
    //double sq = sqrt(1+8.0*n2);
    long long sq = sqrt(1+8*n2);
    long long k = -(1 - sq)/2;    
    long long k2 = k*k;  	
    if(n==46611179)
      printf("%lld, %lld\n", sq, k);      
    if(2*n2==k2+k){
      printf("%10lld %10lld\n", n, k);
      count++;
    }
  }
  return 0;
}



             reply	other threads:[~2002-09-08 14:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-08  7:46 jcas [this message]
2002-10-09 10:16 Pop Sébastian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020908143646.962.qmail@sources.redhat.com \
    --to=jcas@netcabo.pt \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).