[Issue 1475] New: allow to use intrinsic math functions (e.g. trigonometry) in CTFEs

Ingo Oeser ioe-news at rameria.de
Thu Sep 6 13:10:11 PDT 2007


d-bugmail at puremagic.com wrote:

> The compiler already supports some math functions, like the trigonometric
> ones, as intrinsics, since it inlines them even when -inline is not
> specified. It would greatly add to CTFEs if it were possible to call such
> functions in compile-time functions. For example, Pi could be calculated
> at compile-time using:
> 
> const double PI = atan(1)*4;
> 
> Sine tables could also be pre-calculated at compile time, etcetera.

Quoting http://gcc.gnu.org/gcc-4.3/changes.html
"The GCC middle-end has been integrated with the MPFR library. This allows
GCC to evaluate and replace at compile-time calls to built-in math
functions having constant arguments with their mathematically equivalent
results. In making use of MPFR, GCC can generate correct results regardless
of the math library implementation or floating point precision of the host
platform. This also allows GCC to generate identical results regardless of
whether one compiles in native or cross-compile configurations to a
particular target. The following built-in functions take advantage of this
new capability: acos, acosh, asin, asinh, atan2, atan, atanh, cbrt, cos,
cosh, drem, erf, erfc, exp10, exp2, exp, expm1, fdim, fma, fmax, fmin,
gamma_r, hypot, j0, j1, jn, lgamma_r, log10, log1p, log2, log, pow10, pow,
remainder, remquo, sin, sincos, sinh, tan, tanh, tgamma, y0, y1 and yn. The
float and long double variants of these functions (e.g. sinf and sinl) are
also handled. The sqrt and cabs functions with constant arguments were
already optimized in prior GCC releases. Now they also use MPFR."

So GDC might be able to do this, if ported to GCC 4.3 backend and it
patches some frontend parts :-)

Maybe there is a similar solution with a different license to be
able to use that in DMD.


Best Regards

Ingo Oeser


More information about the Digitalmars-d-bugs mailing list