[PATCH] D68257: [Support] Add mathematical constants

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 15:28:59 PDT 2019


efriedma added inline comments.


================
Comment at: llvm/include/llvm/Support/MathExtras.h:66
+                 inv_sqrtpi = 0.5641895835477563, // https://oeis.org/A087197
+                 sqrt2      = 1.414213562373095, // https://oeis.org/A002193
+                 inv_sqrt2  = 0.7071067811865475,
----------------
evandro wrote:
> efriedma wrote:
> > The correct value of sqrt(2) in double-precision is 1.4142135623730951.
> > 
> > And now I don't trust any of the other values...
> `double` has a precision of 15 or 16 significant digits.  I don't understand why are you suggesting 17 significant digits when you asked to trim the precision down.
> 
> Besides, the reference I provided states that this value is 1.41421356237309505.  Whether it's rounded to 1.4142135623730950 or 1.4142135623730951 is a bit moot, IMO.
I asked for "the smallest number of digits required to produce the correct double-precision result".  This is what you get if, for example, you ask Python 2.7 or later to convert the value to a string with `repr()` (`printf "import math\nprint(repr(math.sqrt(2)))" | python`).  `1.414213562373095` produces a value that's different by one ulp.

Yes, a one ulp difference is unlikely to matter for most uses, but if we're going to take the time to define these, we should define them correctly.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:1944
+      // FIXME: The `long double` type is not fully supported by the classes
+      // `APFloat` and `Constant`.
+      Eul = ConstantFP::get(Log->getType(), numbers::e);
----------------
evandro wrote:
> efriedma wrote:
> > I'm not sure this describes the issue correctly.  You can specify a long double as a string, or raw bits.  It can't interoperate with the native long double because that might have the wrong width.
> What wording would you suggest, please?
Maybe just `FIXME: add more precise value of "e" for various long double types`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68257/new/

https://reviews.llvm.org/D68257





More information about the llvm-commits mailing list