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
[parent not found: <bug-6869-131@http.sourceware.org/bugzilla/>]

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