public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bagnara at cs dot unipr dot it" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug math/6869] New: sin() and cos() return grossly wrong results when rounding is set to upward
Date: Fri, 05 Sep 2008 19:35:00 -0000	[thread overview]
Message-ID: <20080905193441.6869.bagnara@cs.unipr.it> (raw)

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


             reply	other threads:[~2008-09-05 19:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-05 19:35 bagnara at cs dot unipr dot it [this message]
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

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=20080905193441.6869.bagnara@cs.unipr.it \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /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).