Skip to content
Standard libraryZig 0.17.1Official documentation
Sourcestd/math/complex/pow.zig

Source line 1

std.math.complex.pow.cmath

alias

Source line 4

Alias of std.math.complex

std.math.complex.pow.Complex

alias

Source line 5

Alias of std.math.complex.Complex

std.math.complex.pow.math

alias

Source line 3

Alias of std.math

std.math.complex.pow.pow

function

Source line 8

Returns z raised to the complex power of c.

pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im))

Example usage

test pow {
    const epsilon = math.floatEps(f32);
    const a = Complex(f32).init(5, 3);
    const b = Complex(f32).init(2.3, -1.3);
    const c = pow(a, b);

    try testing.expectApproxEqAbs(58.049110, c.re, epsilon);
    try testing.expectApproxEqAbs(-101.003433, c.im, epsilon);
}

std.math.complex.pow.std

alias

Source line 1

Alias of std

std.math.complex.pow.testing

alias

Source line 2

Alias of std.testing

Source code

std/math/complex/pow.zig

const std = @import("../../std.zig");
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;

/// Returns z raised to the complex power of c.
pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im)) {
    return cmath.exp(cmath.log(z).mul(s));
}

test pow {
    const epsilon = math.floatEps(f32);
    const a = Complex(f32).init(5, 3);
    const b = Complex(f32).init(2.3, -1.3);
    const c = pow(a, b);

    try testing.expectApproxEqAbs(58.049110, c.re, epsilon);
    try testing.expectApproxEqAbs(-101.003433, c.im, epsilon);
}