delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/28/12:01:01

Sender: nate AT cartsys DOT com
Message-ID: <374DBEE8.E73D32ED@cartsys.com>
Date: Thu, 27 May 1999 14:53:44 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.5 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
CC: jud AT tminet DOT com
Subject: Re: cos(90 * (PI / 180) = 6.12... (now has an idea of what happened
References: <7ii9di$sng$1 AT remarQ DOT com>
Reply-To: djgpp AT delorie DOT com

Shaggs wrote:
> 
> cos(90 * (PI / 180) = 6.12... could this be the result of the pentium flaw,
> as i have the sin and cos stored in arrays of double

Hasn't this come up before?

Look at the complete result, and think about what exponential notation
means.  Then compare it with the value of DBL_EPSILON, which is the
approximate precision of double.  Is your result within DBL_EPSILON of
the expected 0?

I don't think the Pentium FDIV bug is a likely suspect here.  Though it
did exist, I've never heard that it was so gross as to give answers off
by 6 in the most significant digit.  Have you even got an old enough
Pentium that could have it?

If you really want to know, this code should check for it.  It's
borrowed from the Linux source.

#include <stdio.h>

static double x = 4195835.0;
static double y = 3145727.0;

int has_fdiv_bug(void)
{
  int result;
  __asm__("fninit\n\t"
	  "fldl %1\n\t"
	  "fdivl %2\n\t"
	  "fmull %2\n\t"
	  "fldl %1\n\t"
	  "fsubp %%st,%%st(1)\n\t"
	  "fistpl %0\n\t"
	  "fwait\n\t"
	  "fninit"
	  : "=m" (result)
	  : "m" (x), "m" (y));
  return result;
}

int main(void)
{
  printf("FDIV bug %s\n", has_fdiv_bug() ? "found" : "not found");
  return 0;
}

-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019