public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103030] New: floating point to int inconsistency
@ 2021-11-01 18:51 c25devbiz at aol dot com
  2021-11-01 20:02 ` [Bug middle-end/103030] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: c25devbiz at aol dot com @ 2021-11-01 18:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103030
           Summary: floating point to int inconsistency
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: c25devbiz at aol dot com
  Target Milestone: ---

#include <math.h>
typedef long long llong;
int main(int argc,char **argv){;
int ex=0;
llong num_z=0xf70694892bddbb3f,num_x=0x0000000000f88640;double *z_p=(void
*)&num_z,*x_p=(void *)&num_x;
static int le_v=1;char *le=(void *)&le_v;if(le[0])
{       llong num_z2=0,num_x2=0;int n=0;while(n<sizeof(llong))
{               num_z2<<=8;num_z2|=num_z&0xFF;num_z>>=8;
                num_x2<<=8;num_x2|=num_x&0xFF;num_x>>=8;n+=1;
}       num_z=num_z2;num_x=num_x2;
}double c_f=z_p[0]*x_p[0];int
a=floor(z_p[0]*x_p[0]),b=z_p[0]*x_p[0],c=c_f;if(a!=b)dprintf(2,"%d %d
%d\n",a,b,c);
if(1)dprintf(2,"%.15lf %.15lf %.15lf\n",z_p[0],x_p[0],c_f);
return ex;};
/*fn=;gcc $fn.c -o $fn -lm -include stdio.h&&$fn*/

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

* [Bug middle-end/103030] floating point to int inconsistency
  2021-11-01 18:51 [Bug c/103030] New: floating point to int inconsistency c25devbiz at aol dot com
@ 2021-11-01 20:02 ` pinskia at gcc dot gnu.org
  2021-11-02  6:11 ` c25devbiz at aol dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-01 20:02 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
   Last reconfirmed|                            |2021-11-01
          Component|c                           |middle-end
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I get the result of 80 for a, b and c on x86_64-linux-gnu (even with -m32) and
across compilers, GCC, clang and ICC.

What target are you using?

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

* [Bug middle-end/103030] floating point to int inconsistency
  2021-11-01 18:51 [Bug c/103030] New: floating point to int inconsistency c25devbiz at aol dot com
  2021-11-01 20:02 ` [Bug middle-end/103030] " pinskia at gcc dot gnu.org
@ 2021-11-02  6:11 ` c25devbiz at aol dot com
  2021-11-02  7:17 ` pinskia at gcc dot gnu.org
  2021-11-02 18:55 ` c25devbiz at aol dot com
  3 siblings, 0 replies; 5+ messages in thread
From: c25devbiz at aol dot com @ 2021-11-02  6:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from c25devbiz at aol dot com ---
i686-linux-gnu
if change c_f to long double and use llf, brings c_f down and brings c down to
b

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

* [Bug middle-end/103030] floating point to int inconsistency
  2021-11-01 18:51 [Bug c/103030] New: floating point to int inconsistency c25devbiz at aol dot com
  2021-11-01 20:02 ` [Bug middle-end/103030] " pinskia at gcc dot gnu.org
  2021-11-02  6:11 ` c25devbiz at aol dot com
@ 2021-11-02  7:17 ` pinskia at gcc dot gnu.org
  2021-11-02 18:55 ` c25devbiz at aol dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-02  7:17 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|WAITING                     |RESOLVED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is just an artifact of x87 and how everything is done in 80bit fp and
sometimes you get different answers than you are expected.  If SSE2 is turned
on, then the integer to fp conversion happens in the SSE2 unit and is converted
to 64bit fp before the conversion.

Again this is not really a bug, but a partial misunderstanding of floating
point and how x87 floating point works.

*** This bug has been marked as a duplicate of bug 323 ***

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

* [Bug middle-end/103030] floating point to int inconsistency
  2021-11-01 18:51 [Bug c/103030] New: floating point to int inconsistency c25devbiz at aol dot com
                   ` (2 preceding siblings ...)
  2021-11-02  7:17 ` pinskia at gcc dot gnu.org
@ 2021-11-02 18:55 ` c25devbiz at aol dot com
  3 siblings, 0 replies; 5+ messages in thread
From: c25devbiz at aol dot com @ 2021-11-02 18:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from c25devbiz at aol dot com ---
it works with -mpc64
so the default was set to the highest, but I guess should have been limited by
the target

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

end of thread, other threads:[~2021-11-02 18:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 18:51 [Bug c/103030] New: floating point to int inconsistency c25devbiz at aol dot com
2021-11-01 20:02 ` [Bug middle-end/103030] " pinskia at gcc dot gnu.org
2021-11-02  6:11 ` c25devbiz at aol dot com
2021-11-02  7:17 ` pinskia at gcc dot gnu.org
2021-11-02 18:55 ` c25devbiz at aol dot com

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