public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Hillel (Sabba) Markowitz" <sabbahem@bcpl.net>
To: GCC Help <gcc-help@gcc.gnu.org>
Subject: linux i-86 problem with rounding (gcc-3.1.1 & 3.2)
Date: Wed, 18 Sep 2002 07:04:00 -0000	[thread overview]
Message-ID: <3DA44C07@webmail.bcpl.net> (raw)

The following test program give incorrect results in a cast from double to int 
when compiled without an optimization option but correct results when compiled 
with an optimization option.

int main(int argc, char **argv)
{
  int i = 128000;
  double f = 0.0075;
  double g;
  unsigned int u;

  u = (unsigned int) (i*f);
  printf("unsigned int result of i*f: %u\n", u);

  g = i*f;
  u = (unsigned int)g;
  printf("double result: %lf\n", g);
  printf("unsigned int result: %u\n", u);

  return(0);
}


%gcc testfloat.c -o testfloat
%./testfloat

unsigned int result of i*f: 959
double result: 960
unsigned int result: 960

%gcc testfloat.c -o testfloat -O
%./testfloat

unsigned int result of i*f: 960
double result: 960
unsigned int result: 960


This error occurs only on the linux i-86 (redhat 7.2 or 7.3).  However, the 
results come out correctly on Solaris, DEC (4.0 and 5.1) and linux alpha 
(redhat 7.2).

Does anyone have an idea for a fix or workaround?  Is this an artifact of the 
Assembler or the floating point co-processor?  Is this something to do with 
gcc?

Please e-mail me with the answer as well as the mailing list.

Thanks,

-- 
Said the fox to the fish, "Join me ashore".
 The fish are the Jews, Torah is our water

Hillel (Sabba) Markowitz - sabbahem@bcpl.net

             reply	other threads:[~2002-09-18 14:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-18  7:04 Hillel (Sabba) Markowitz [this message]
2002-09-18  9:46 ` Martin Dickopp
2002-09-18  9:59   ` Gokhan Kisacikoglu
2002-09-18 11:37 Hillel (Sabba) Markowitz
2002-09-18 11:56 ` Martin Dickopp
2002-09-18 12:58   ` Buddy Lott
2002-09-18 13:35     ` Martin Dickopp

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=3DA44C07@webmail.bcpl.net \
    --to=sabbahem@bcpl.net \
    --cc=gcc-help@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).