public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/6869] New: sin() and cos() return grossly wrong results when rounding is set to upward
@ 2008-09-05 19:35 bagnara at cs dot unipr dot it
  2008-09-05 19:37 ` [Bug math/6869] " bagnara at cs dot unipr dot it
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: bagnara at cs dot unipr dot it @ 2008-09-05 19:35 UTC (permalink / raw)
  To: glibc-bugs

$ cat bug2.cc
#include <fenv.h>
#include <iostream>
#include <cmath>

int main() {
  double theta = 5.27905511969922880410877041867934167385101318359375;

  std::cout << "theta = " << theta << "\n";
  std::cout << "sin(theta) = " << sin(theta) << "\n";
  std::cout << "cos(theta) = " << cos(theta) << "\n";

  std::cout << "Repeating after setting the rounding direction to UPWARD:"
            << std::endl;

  fesetround(FE_UPWARD);
  std::cout << "theta = " << theta << "\n";
  std::cout << "sin(theta) = " << sin(theta) << "\n";
  std::cout << "cos(theta) = " << cos(theta) << "\n";
}
$ g++ -W -Wall bug2.cc
$ a.out
theta = 5.27906
sin(theta) = -0.843695
cos(theta) = 0.536822
Repeating after setting the rounding direction to UPWARD:
theta = 5.27906
sin(theta) = -0.119458
cos(theta) = 12.1636
$

This happens on a Fedora 7, x86_64  system, with glibc-2.6-4
and GCC 4.3.2.

As you see, after setting the rounding direction to UPWARD,
the results are grossly wrong, to the point of cos() returning
12.1636.  The value computed by second invocation of sin() is
also wrong.

-- 
           Summary: sin() and cos() return grossly wrong results when
                    rounding is set to upward
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
        AssignedTo: aj at suse dot de
        ReportedBy: bagnara at cs dot unipr dot it
                CC: glibc-bugs at sources dot redhat dot com
  GCC host triplet: athlon64-unknown-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=6869

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/6869] sin() and cos() return grossly wrong results when rounding is set to upward
  2008-09-05 19:35 [Bug math/6869] New: sin() and cos() return grossly wrong results when rounding is set to upward bagnara at cs dot unipr dot it
@ 2008-09-05 19:37 ` bagnara at cs dot unipr dot it
  2008-09-05 21:20 ` eberlein at us dot ibm dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: bagnara at cs dot unipr dot it @ 2008-09-05 19:37 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From bagnara at cs dot unipr dot it  2008-09-05 19:36 -------
Created an attachment (id=2941)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=2941&action=view)
Testcase allowing to reproduce the problem.


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=6869

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/6869] sin() and cos() return grossly wrong results when rounding is set to upward
  2008-09-05 19:35 [Bug math/6869] New: sin() and cos() return grossly wrong results when rounding is set to upward bagnara at cs dot unipr dot it
  2008-09-05 19:37 ` [Bug math/6869] " bagnara at cs dot unipr dot it
@ 2008-09-05 21:20 ` eberlein at us dot ibm dot com
  2008-09-24 10:45 ` anders dot lennartsson at foi dot se
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: eberlein at us dot ibm dot com @ 2008-09-05 21:20 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From eberlein at us dot ibm dot com  2008-09-05 21:19 -------
Here are the results for SLES10 SP1, Power6, using Advance
Toolchain GLIBC 2.8, GCC 4.3.1, again very wrong:

theta = 5.27906
sin(theta) = -0.843695
cos(theta) = 0.536822
Repeating after setting the rounding direction to UPWARD:
theta = 5.27906
sin(theta) = -0.0702948
cos(theta) = 9.55255

I also checked the calculation of sin and cos by moving it before setting the
rounding mode and printing it after setting the rounding mode: the correct
results were printed.  This indicates the problem is in sin and cos, and not
with io.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eberlein at us dot ibm dot
                   |                            |com


http://sourceware.org/bugzilla/show_bug.cgi?id=6869

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/6869] sin() and cos() return grossly wrong results when rounding is set to upward
  2008-09-05 19:35 [Bug math/6869] New: sin() and cos() return grossly wrong results when rounding is set to upward bagnara at cs dot unipr dot it
  2008-09-05 19:37 ` [Bug math/6869] " bagnara at cs dot unipr dot it
  2008-09-05 21:20 ` eberlein at us dot ibm dot com
@ 2008-09-24 10:45 ` anders dot lennartsson at foi dot se
  2008-09-29 16:44 ` anders dot lennartsson at foi dot se
  2010-03-21 22:24 ` vincent+libc at vinc17 dot org
  4 siblings, 0 replies; 7+ messages in thread
From: anders dot lennartsson at foi dot se @ 2008-09-24 10:45 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From anders dot lennartsson at foi dot se  2008-09-24 10:43 -------
The problem may occur on 64-bits only. I compiled and ran the test program on
three computers, all Intel machines running Debian. Two of these use Debian 4.0
Etch, one 32 and one 64-bits, and the problem was present only on 64 bits. It is
still there on a 64-bits machine with Debian unstable.

Etch 32-bits:

theta = 5.27906
sin(theta) = -0.843695
cos(theta) = 0.536822
Repeating after setting the rounding direction to UPWARD:
theta = 5.27906
sin(theta) = -0.843695
cos(theta) = 0.536822

user@computer1:~/gcc$  g++ --v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)


Etch 64-bits:

theta = 5.27906
sin(theta) = -0.843695
cos(theta) = 0.536822
Repeating after setting the rounding direction to UPWARD:
theta = 5.27906
sin(theta) = -0.212522
cos(theta) = 8.2185

user@computer2:~/gcc$  g++ --v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --enable-checking=release x86_64-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Sid 64-bits:

theta = 5.27906
sin(theta) = -0.843695
cos(theta) = 0.536822
Repeating after setting the rounding direction to UPWARD:
theta = 5.27906
sin(theta) = -0.247529
cos(theta) = 7.26962
user@computer3:/home_2/abel/gcc$ g++ --v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3
--program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --enable-cld --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1) 



-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=6869

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/6869] sin() and cos() return grossly wrong results when rounding is set to upward
  2008-09-05 19:35 [Bug math/6869] New: sin() and cos() return grossly wrong results when rounding is set to upward bagnara at cs dot unipr dot it
                   ` (2 preceding siblings ...)
  2008-09-24 10:45 ` anders dot lennartsson at foi dot se
@ 2008-09-29 16:44 ` anders dot lennartsson at foi dot se
  2010-03-21 22:24 ` vincent+libc at vinc17 dot org
  4 siblings, 0 replies; 7+ messages in thread
From: anders dot lennartsson at foi dot se @ 2008-09-29 16:44 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From anders dot lennartsson at foi dot se  2008-09-29 16:43 -------
Created an attachment (id=2967)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=2967&action=view)
modified version of test program and plot of results

There are several intervals for which sine and cosine return wrong results,
when rounding is adjusted according to the original bug report. I modified the
original program to compute values for several angles, and plotted the results.
The program and one plot are attached. As it turns out, not even for all
arguments where |angle|<pi are the results completely correct.


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=6869

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/6869] sin() and cos() return grossly wrong results when rounding is set to upward
  2008-09-05 19:35 [Bug math/6869] New: sin() and cos() return grossly wrong results when rounding is set to upward bagnara at cs dot unipr dot it
                   ` (3 preceding siblings ...)
  2008-09-29 16:44 ` anders dot lennartsson at foi dot se
@ 2010-03-21 22:24 ` vincent+libc at vinc17 dot org
  4 siblings, 0 replies; 7+ messages in thread
From: vincent+libc at vinc17 dot org @ 2010-03-21 22:24 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From vincent+libc at vinc17 dot org  2010-03-21 22:24 -------


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

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


http://sourceware.org/bugzilla/show_bug.cgi?id=6869

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug math/6869] sin() and cos() return grossly wrong results when rounding is set to upward
       [not found] <bug-6869-131@http.sourceware.org/bugzilla/>
@ 2014-07-02  7:44 ` fweimer at redhat dot com
  0 siblings, 0 replies; 7+ messages in thread
From: fweimer at redhat dot com @ 2014-07-02  7:44 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=6869

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

end of thread, other threads:[~2014-07-02  7:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-05 19:35 [Bug math/6869] New: sin() and cos() return grossly wrong results when rounding is set to upward bagnara at cs dot unipr dot it
2008-09-05 19:37 ` [Bug math/6869] " bagnara at cs dot unipr dot it
2008-09-05 21:20 ` eberlein at us dot ibm dot com
2008-09-24 10:45 ` anders dot lennartsson at foi dot se
2008-09-29 16:44 ` anders dot lennartsson at foi dot se
2010-03-21 22:24 ` vincent+libc at vinc17 dot org
     [not found] <bug-6869-131@http.sourceware.org/bugzilla/>
2014-07-02  7:44 ` fweimer at redhat 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).