User account creation filtered due to spam.

Bug 45272 - comment about sqrt() implementation wrong: it is not from Carmack
Summary: comment about sqrt() implementation wrong: it is not from Carmack
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on: 45273
  Show dependency treegraph
Reported: 2010-08-13 00:37 UTC by Albert Zeyer
Modified: 2010-08-13 00:44 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Albert Zeyer 2010-08-13 00:37:49 UTC
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:
Comment 1 Andrew Pinski 2010-08-13 00:44:16 UTC
Well really this code should not be using double anyways.  double can produce slight differences between targets.