Math Intrinsics (The GNU D Compiler)

#### 2.5.3 Math Intrinsics ¶

The following functions are a collection of mathematical intrinsics, available by importing the `core.math` module.

Function: `float` core.math.cos `(float x)` ¶
Function: `double` core.math.cos `(double x)` ¶
Function: `real` core.math.cos `(real x)` ¶

  Returns cosine of x, where x is in radians. The return value is undefined if x is greater than 2^{64}.

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

Function: `float` core.math.fabs `(float x)` ¶
Function: `double` core.math.fabs `(double x)` ¶
Function: `real` core.math.fabs `(real x)` ¶

  Compute the absolute value of x.

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

Function: `float` core.math.ldexp `(float n, int exp)` ¶
Function: `double` core.math.ldexp `(double n, int exp)` ¶
Function: `real` core.math.ldexp `(real n, int exp)` ¶

  Compute n * 2^{exp}.

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

Function: `float` core.math.rint `(float x)` ¶
Function: `double` core.math.rint `(double x)` ¶
Function: `real` core.math.rint `(real x)` ¶

  Rounds x to the nearest integer value, using the current rounding mode. If the return value is not equal to x, the `FE_INEXACT` exception is raised. `nearbyint` performs the same operation, but does not set the `FE_INEXACT` exception.

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

Function: `float` core.math.rndtol `(float x)` ¶
Function: `double` core.math.rndtol `(double x)` ¶
Function: `real` core.math.rndtol `(real x)` ¶

  Returns x rounded to a long value using the current rounding mode. If the integer value of x is greater than `long.max`, the result is indeterminate.

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

Function: `float` core.math.sin `(float x)` ¶
Function: `double` core.math.sin `(double x)` ¶
Function: `real` core.math.sin `(real x)` ¶

  Returns sine of x, where x is in radians. The return value is undefined if x is greater than 2^{64}.

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

Function: `float` core.math.sqrt `(float x)` ¶
Function: `double` core.math.sqrt `(double x)` ¶
Function: `real` core.math.sqrt `(real x)` ¶

  Compute the sqrt of x.

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

Template: `T` core.math.toPrec `(T)(float f)` ¶
Template: `T` core.math.toPrec `(T)(double f)` ¶
Template: `T` core.math.toPrec `(T)(real f)` ¶

  Round f to a specific precision.

  In floating-point operations, D language types specify only a minimum precision, not a maximum. The `toPrec` function forces rounding of the argument f to the precision of the specified floating point type `T`. The rounding mode used is inevitably target-dependent, but will be done in a way to maximize accuracy. In most cases, the default is round-to-nearest.