This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/28473] with -O, casting result of round(x) to uint64_t produces wrong values for x > INT_MAX
- From: "pinskia at physics dot uc dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Jul 2006 22:01:00 -0000
- Subject: [Bug c/28473] with -O, casting result of round(x) to uint64_t produces wrong values for x > INT_MAX
- References: <bug-28473-13001@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from pinskia at physics dot uc dot edu 2006-07-24 22:01 -------
Subject: Re: New: with -O, casting result of round(x) to uint64_t produces
wrong values for x > INT_MAX
>
> When compiling with -O or greater optimization, and if x > INT_MAX, then code
> like this:
> uint64_t y = (uint64_t)round(x);
> assigns the wrong value to y (the top 32 bits are all 1s). But this code
> assigns the right value to z:
> double dz = round(x);
> uint64_t z = dz;
>
> It almost seems as if gcc -O in some cases compiles using a built-in
> declaration of round() that returns a 32-bit int.
Yes this is wrong code, GCC is generating for some reason lround instead of
llround.
Thanks,
Andrew Pinski
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28473