public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "d.j.allerton at sheffield dot ac.uk" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/108989] New: Two small almost identical programs give different results
Date: Thu, 02 Mar 2023 13:13:16 +0000	[thread overview]
Message-ID: <bug-108989-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108989

            Bug ID: 108989
           Summary: Two small almost identical programs give different
                    results
           Product: gcc
           Version: og10 (devel/omp/gcc-10)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: d.j.allerton at sheffield dot ac.uk
  Target Milestone: ---

Created attachment 54570
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54570&action=edit
A small program doing 2D geometry. No math calls, just addition, subtraction,
mutiplication and division of floats.

In a small program, the following lines give different reults:

    x = x0 + ((r1 * r1 - r2 * r2 + x2 * x2) / (2.0 * x2));
    y = y0 + ((r1 * r1 - r3 * r3 + x3 * x3 + y3 * y3 - 2.0 * x3 * x) / (2.0 *
y3));
    printf("x=%f y=%f\n", x, y);

and 
    x = ((r1 * r1 - r2 * r2 + x2 * x2) / (2.0 * x2));
    y = ((r1 * r1 - r3 * r3 + x3 * x3 + y3 * y3 - 2.0 * x3 * x) / (2.0 * y3));
    printf("x=%f y=%f\n", x + x0, y + y0);

the first example gives: x=-0.000000 y=33.070801 (which is wrong)
the second example gives: x=0.000000 y=7.315198  (which is correct)

The only difference is the addition of x0 and y0 in the sets of expressions.

The two programs are attached. They don't use any libraries other than stdlib.h
and stdio.h. I use gcc version 10.2.0 on msys2 on a PC and version 10.2.1 on a
Raspberry Pi 4B and get the same errors with both compilers. A colleague gets
the same errors with version 12.1.0 on a PC.

             reply	other threads:[~2023-03-02 13:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 13:13 d.j.allerton at sheffield dot ac.uk [this message]
2023-03-02 13:32 ` [Bug c/108989] " schwab@linux-m68k.org
2023-03-03  8:10 ` d.j.allerton at sheffield dot ac.uk

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=bug-108989-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).