This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Cong Hou <congh at google dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>, David Li <davidxl at google dot com>
- Date: Sat, 31 Aug 2013 16:24:05 +0000
- Subject: Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.
- Authentication-results: sourceware.org; auth=none
- References: <CAK=A3=1b=qhx8u8Wz7je=KYUbvOQHyKaWP353ud7D7f8gF56Bw at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1308232046240 dot 12585 at digraph dot polyomino dot org dot uk> <CAK=A3=3=gLhTso3+AF-BmiONPsEpP3dGTFtOAZPbh+oteYPTNA at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1308302148230 dot 22363 at digraph dot polyomino dot org dot uk> <CAK=A3=0bQkcvprFZTtuJ0ZNbknSJixhMP559tiF3FFUL0zkmfw at mail dot gmail dot com>
On Sat, 31 Aug 2013, Cong Hou wrote:
> > I don't see why it would be unsafe for logb - can you give an example
> > (exact float input value as hex float, and the values you believe logb
> > should return for float and double).
> >
>
> Please try the following code (you will get different results whether to
> use optimization mode):
>
> #include <math.h>
> #include <stdio.h>
>
> int main()
> {
> int i = 0x3edc67d5;
> float f = *((float*)&i);
> float r1 = logb(f);
> float r2 = logbf(f);
> printf("%x %x\n", *((int*)&r1), *((int*)&r2));
> }
(a) Please stop sending HTML email, so your messages reach the mailing
list, and resend your messages so far to the list. The mailing list needs
to see the whole of both sides of the discussion of any patch being
proposed for GCC.
(b) I referred to the values *you believe logb should return*.
Optimization is not meant to preserve library bugs; the comparison should
be on the basis of correctly rounded results from both float and double
functions. The correct return from logb appears to be -2 here, and I get
that from both logb and logbf with current git glibc. The existence of a
bug in some old library is not relevant here.
(c) I always advise writing such tests as *valid C code* using hex floats
(or if really necessary, unions), not *invalid C code* with aliasing
violations.
--
Joseph S. Myers
joseph@codesourcery.com