public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/45272]  New: comment about sqrt() implementation wrong: it is not from Carmack
@ 2010-08-13  0:38 ich at az2000 dot de
  2010-08-13  0:44 ` [Bug middle-end/45272] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: ich at az2000 dot de @ 2010-08-13  0:38 UTC (permalink / raw)
  To: gcc-bugs

The code:

/* sqrt() implementation: based on open source QUAKE3 code (magic sqrt
   implementation) by John Carmack.  Returns sqrt of X.  */

static double
mcf_sqrt (double x)
{
#define MAGIC_CONST1    0x1fbcf800
#define MAGIC_CONST2    0x5f3759df
  union {
    int intPart;
    float floatPart;
  } convertor, convertor2;

  gcc_assert (x >= 0);

  convertor.floatPart = x;
  convertor2.floatPart = x;
  convertor.intPart = MAGIC_CONST1 + (convertor.intPart >> 1);
  convertor2.intPart = MAGIC_CONST2 - (convertor2.intPart >> 1);

  return 0.5f * (convertor.floatPart + (x * convertor2.floatPart));
}


Read here:

http://en.wikipedia.org/wiki/Fast_inverse_square_root
http://www.beyond3d.com/content/articles/8/


-- 
           Summary: comment about sqrt() implementation wrong: it is not
                    from Carmack
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ich at az2000 dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45272


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

* [Bug middle-end/45272] comment about sqrt() implementation wrong: it is not from Carmack
  2010-08-13  0:38 [Bug middle-end/45272] New: comment about sqrt() implementation wrong: it is not from Carmack ich at az2000 dot de
@ 2010-08-13  0:44 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-08-13  0:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-08-13 00:44 -------
Well really this code should not be using double anyways.  double can produce
slight differences between targets.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45272


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

end of thread, other threads:[~2010-08-13  0:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-13  0:38 [Bug middle-end/45272] New: comment about sqrt() implementation wrong: it is not from Carmack ich at az2000 dot de
2010-08-13  0:44 ` [Bug middle-end/45272] " pinskia at gcc dot gnu dot org

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