From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5277 invoked by alias); 26 May 2005 21:08:53 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 5266 invoked by uid 22791); 26 May 2005 21:08:47 -0000 Received: from sadr.equallogic.com (HELO sadr.equallogic.com) (66.155.203.134) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Thu, 26 May 2005 21:08:47 +0000 Received: from sadr.equallogic.com (localhost.localdomain [127.0.0.1]) by sadr.equallogic.com (8.12.8/8.12.8) with ESMTP id j4QL8jZZ000980 for ; Thu, 26 May 2005 17:08:46 -0400 Received: from M31.equallogic.com (M31.equallogic.com [172.16.1.31]) by sadr.equallogic.com (8.12.8/8.12.8) with SMTP id j4QL8jNd000975; Thu, 26 May 2005 17:08:45 -0400 Received: from pkoning.equallogic.com ([172.16.1.163]) by M31.equallogic.com with Microsoft SMTPSVC(6.0.3790.211); Thu, 26 May 2005 17:08:45 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17046.15068.446652.763680@gargle.gargle.HOWL> Date: Thu, 26 May 2005 23:52:00 -0000 From: Paul Koning To: uros@kss-loka.si Cc: gcc@gcc.gnu.org Subject: Re: Sine and Cosine Accuracy References: <429638A1.3080102@kss-loka.si> X-SW-Source: 2005-05/txt/msg01458.txt.bz2 >>>>> "Uros" == Uros Bizjak writes: Uros> Hello! >> Fair enough, so with 64 bit floats you have no right to expect an >> accurate answer for sin(2^90). However, you DO have a right to >> expect an answer in the range [-1,+1] rather than the 1.2e+27 that >> Richard quoted. I see no words in the description of >> -funsafe-math-optimizations to lead me to expect such a result. >> Uros> The source operand to fsin, fcos and fsincos x87 insns must be Uros> within the range of +-2^63, otherwise a C2 flag is set in FP Uros> status word that marks insufficient operand reduction. Limited Uros> operand range is the reason, why fsin & friends are enabled Uros> only with -funsafe-math-optimizations. Uros> However, the argument to fsin can be reduced to an acceptable Uros> range by using fmod builtin. Internally, this builtin is Uros> implemented as a very tight loop that check for insufficient Uros> reduction, and could reduce whatever finite value one wishes. Uros> Out of curiosity, where could sin(2^90) be needed? It looks Uros> rather big angle to me. It looks that way to me too, but it's a perfectly valid argument to the function as has been explained by several people. Unless -funsafe-math-optimizations is *explicitly* documented to say "trig function arguments must be in the range x..y for meaningful results" I believe it is a bug to translate sin(x) to a call to the x87 fsin primitive. It needs to be wrapped with fmod (perhaps after a range check for efficiency), otherwise you've drastically changed the semantics of the function. Personally I don't expect sin(2^90) to yield 1.2e27. Yes, you can argue that, pedantically, clause (b) in the doc for -funsafe-math-optimizations permits this. Then again, I could argue that it also permits sin(x) to return 0 for all x. paul