pow

Calculates xy.

Special Values
xypow(x, y)div 0invalid?
anything±0.01.0nono
|x| > 1+∞+∞nono
|x| < 1+∞+0.0nono
|x| > 1-∞+0.0nono
|x| < 1-∞+∞nono
+∞> 0.0+∞nono
+∞< 0.0+0.0nono
-∞odd integer > 0.0-∞nono
-∞> 0.0, not odd integer+∞nono
-∞odd integer < 0.0-0.0nono
-∞< 0.0, not odd integer+0.0nono
±1.0±∞-NaNnoyes
< 0.0finite, nonintegralNaNnoyes
±0.0odd integer < 0.0$(PLUSMNINF)yesno
±0.0< 0.0, not odd integer+∞yesno
±0.0odd integer > 0.0±0.0nono
±0.0> 0.0, not odd integer+0.0nono
  1. Unqual!F pow(F x, G n)
  2. typeof(Unqual!(F).init * Unqual!(G).init) pow(F x, G n)
  3. real pow(I x, F y)
  4. Unqual!(Largest!(F, G)) pow(F x, G y)
    @nogc @trusted pure nothrow
    Unqual!(Largest!(F, G))
    pow
    (
    F
    G
    )
    (
    F x
    ,
    G y
    )

Examples

import std.math.operations : isClose;

assert(isClose(pow(2.0, 3.0), 8.0));
assert(isClose(pow(1.5, 10.0), 57.6650390625));

// square root of 9
assert(isClose(pow(9.0, 0.5), 3.0));
// 10th root of 1024
assert(isClose(pow(1024.0, 0.1), 2.0));

assert(isClose(pow(-4.0, 3.0), -64.0));

// reciprocal of 4 ^^ 2
assert(isClose(pow(4.0, -2.0), 0.0625));
// reciprocal of (-2) ^^ 3
assert(isClose(pow(-2.0, -3.0), -0.125));

assert(isClose(pow(-2.5, 3.0), -15.625));
// reciprocal of 2.5 ^^ 3
assert(isClose(pow(2.5, -3.0), 0.064));
// reciprocal of (-2.5) ^^ 3
assert(isClose(pow(-2.5, -3.0), -0.064));

// reciprocal of square root of 4
assert(isClose(pow(4.0, -0.5), 0.5));

// per definition
assert(isClose(pow(0.0, 0.0), 1.0));
import std.math.operations : isClose;

// the result is a complex number
// which cannot be represented as floating point number
import std.math.traits : isNaN;
assert(isNaN(pow(-2.5, -1.5)));

// use the ^^-operator of std.complex instead
import std.complex : complex;
auto c1 = complex(-2.5, 0.0);
auto c2 = complex(-1.5, 0.0);
auto result = c1 ^^ c2;
// exact result apparently depends on `real` precision => increased tolerance
assert(isClose(result.re, -4.64705438e-17, 2e-4));
assert(isClose(result.im, 2.52982e-1, 2e-4));

Meta