CTFE Intrinsics (The GNU D Compiler)

#### 2.5.6 CTFE Intrinsics ¶

The following functions are only treated as intrinsics during compile-time function execution (CTFE) phase of compilation to allow more functions to be computable at compile-time, either because their generic implementations are too complex, or do some low-level bit manipulation of floating point types.

Calls to these functions that exist after CTFE has finished will get standard code-generation without any special compiler intrinsic suppport.

Function: `float` std.math.exponential.exp `(float x)` ¶
Function: `double` std.math.exponential.exp `(double x)` ¶
Function: `real` std.math.exponential.exp `(real x)` ¶

  Calculates e^x.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_exp`.

Function: `float` std.math.exponential.expm1 `(float x)` ¶
Function: `double` std.math.exponential.expm1 `(double x)` ¶
Function: `real` std.math.exponential.expm1 `(real x)` ¶

  Calculates e^x-1.0.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_expm1`.

Function: `float` std.math.exponential.exp2 `(float x)` ¶
Function: `double` std.math.exponential.exp2 `(double x)` ¶
Function: `real` std.math.exponential.exp2 `(real x)` ¶

  Calculates 2^x.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_exp2`.

Function: `float` std.math.exponential.log `(float x)` ¶
Function: `double` std.math.exponential.log `(double x)` ¶
Function: `real` std.math.exponential.log `(real x)` ¶

  Calculate the natural logarithm of x.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_log`.

Function: `float` std.math.exponential.log10 `(float x)` ¶
Function: `double` std.math.exponential.log10 `(double x)` ¶
Function: `real` std.math.exponential.log10 `(real x)` ¶

  Calculates the base-10 logarithm of x.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_log10`.

Function: `float` std.math.exponential.log2 `(float x)` ¶
Function: `double` std.math.exponential.log2 `(double x)` ¶
Function: `real` std.math.exponential.log2 `(real x)` ¶

  Calculates the base-2 logarithm of x.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_log2`.

Template: `Largest!(F, G)` std.math.exponential.pow `(F, G) (F x, G y)` ¶
Template: `real` std.math.exponential.pow `(I, F)(I x, F y)` ¶

  Calculates x^y, where y is a float.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_pow`.

Template: `F` std.math.exponential.pow `(F, G) (F x, G n)` ¶

  Calculates x^n, where n is an integer.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_powi`.

Function: `real` std.math.operations.fma `(real x, real y, real z)` ¶

  Returns `(x * y) + z`, rounding only once according to the current rounding mode.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_fma`.

Template: `F` std.math.operations.fmax `(F)(const F x, const F y)` ¶

  Returns the larger of x and y.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_fmax`.

Template: `F` std.math.operations.fmin `(F)(const F x, const F y)` ¶

  Returns the smaller of x and y.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_fmin`.

Function: `float` std.math.rounding.ceil `(float x)` ¶
Function: `double` std.math.rounding.ceil `(double x)` ¶
Function: `real` std.math.rounding.ceil `(real x)` ¶

  Returns the value of x rounded upward to the next integer (toward positive infinity).

  This function is evaluated during CTFE as the GCC built-in function `__builtin_ceil`.

Function: `float` std.math.rounding.floor `(float x)` ¶
Function: `double` std.math.rounding.floor `(double x)` ¶
Function: `real` std.math.rounding.floor `(real x)` ¶

  Returns the value of x rounded downward to the next integer (toward negative infinity).

  This function is evaluated during CTFE as the GCC built-in function `__builtin_floor`.

Function: `real` std.math.rounding.round `(real x)` ¶

  Return the value of x rounded to the nearest integer. If the fractional part of x is exactly 0.5, the return value is rounded away from zero.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_round`.

Function: `real` std.math.rounding.trunc `(real x)` ¶

  Returns the integer portion of x, dropping the fractional portion.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_trunc`.

Template: `R` std.math.traits.copysign `(R, X)(R to, X from)` ¶

  Returns a value composed of to with from’s sign bit.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_copysign`.

Template: `bool` std.math.traits.isFinite `(X)(X x)` ¶

  Returns true if x is finite.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_isfinite`.

Template: `bool` std.math.traits.isInfinity `(X)(X x)` ¶

  Returns true if x is infinite.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_isinf`.

Template: `bool` std.math.traits.isNaN `(X)(X x)` ¶

  Returns true if x is NaN.

  This function is evaluated during CTFE as the GCC built-in function `__builtin_isnan`.

Function: `float` std.math.trigoometry.tan `(float x)` ¶
Function: `double` std.math.trigoometry.tan `(double x)` ¶
Function: `real` std.math.trigonometry.tan `(real x)` ¶

  Returns tangent of x, where x is in radians.

  This intrinsic is the same as the GCC built-in function `__builtin_tan`.