private static function powi($z, $n) {
        if ($n < 0) return static::div(1,static::powi($z, -$n));

        if ($n == 0) return new Complex(1,0);

        $y = new Complex(1,0);
        while ($n > 1) {
            if ($n % 2 == 0) {
                $n = $n / 2;
            } else {
                $y = static::mul($z, $y);
                $n = ($n-1)/2;
            }
            $z = static::mul($z, $z);
        }

        return static::mul($z, $y);
    }