public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108989] New: Two small almost identical programs give different results
@ 2023-03-02 13:13 d.j.allerton at sheffield dot ac.uk
  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
  0 siblings, 2 replies; 3+ messages in thread
From: d.j.allerton at sheffield dot ac.uk @ 2023-03-02 13:13 UTC (permalink / raw)
  To: gcc-bugs

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.

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

* [Bug c/108989] Two small almost identical programs give different results
  2023-03-02 13:13 [Bug c/108989] New: Two small almost identical programs give different results d.j.allerton at sheffield dot ac.uk
@ 2023-03-02 13:32 ` schwab@linux-m68k.org
  2023-03-03  8:10 ` d.j.allerton at sheffield dot ac.uk
  1 sibling, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2023-03-02 13:32 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
x is used to compute y.

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

* [Bug c/108989] Two small almost identical programs give different results
  2023-03-02 13:13 [Bug c/108989] New: Two small almost identical programs give different results d.j.allerton at sheffield dot ac.uk
  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
  1 sibling, 0 replies; 3+ messages in thread
From: d.j.allerton at sheffield dot ac.uk @ 2023-03-03  8:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Dave Allerton <d.j.allerton at sheffield dot ac.uk> ---
Apologies - should have spotted it but thanks for sorting it out.

Best regards
Dave Allerton
------------------------------------------------------------------------
On 02/03/2023 13:32, schwab@linux-m68k.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108989
>
> Andreas Schwab<schwab@linux-m68k.org>  changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>           Resolution|---                         |INVALID
>               Status|UNCONFIRMED                 |RESOLVED
>
> --- Comment #1 from Andreas Schwab<schwab@linux-m68k.org>  ---
> x is used to compute y.
>

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

end of thread, other threads:[~2023-03-03  8:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 13:13 [Bug c/108989] New: Two small almost identical programs give different results d.j.allerton at sheffield dot ac.uk
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

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