
#include <complex>
#include <cstdio>

int main()
{
    const std::complex<long double> a = std::complex<long double>(2, 3);
    const std::complex<long double> b = std::complex<long double>(2, 0);
    std::complex<long double> x = std::complex<long double>(-5, 12);

    std::complex<long double> c = std::pow(a, b);

	printf("c = pow(a,b) = %.20Le + i*%.20Le\n", c.real(), c.imag());
	printf("x            = %.20Le + i*%.20Le\n\n", x.real(), x.imag());
	printf("err = c - x  = %.20Le + i*%.20Le\n\n", (c-x).real(), (c-x).imag());

    std::complex<long double> bw = b * std::log(a);

    std::complex<long double> d = std::exp(b*std::log(a));
    std::complex<long double> dx1 =
    	std::complex<long double>(std::exp(bw.real()) * std::cos(bw.imag()),
    		                      std::exp(bw.real()) * std::sin(bw.imag()));

	printf("d = exp(b*log(a)) = %.20Le + i*%.20Le\n", d.real(), d.imag());
	printf("dx1               = %.20Le + i*%.20Le\n", dx1.real(), dx1.imag());
	printf("err = d - x       = %.20Le + i*%.20Le\n", (d-x).real(), (d-x).imag());
	printf("err = dx1 - x     = %.20Le + i*%.20Le\n", (dx1-x).real(), (dx1-x).imag());

}
