log
虚部は[-π, π]だから、
sqrt
符号はyの正負による。
atan
powはメリットなさそうなので、パス。
import std.cstream;
import std.math;void main(char[][] args) {
dout.writefln(exp(0.1i));
dout.writefln(cos(0.1i));
dout.writefln(sin(0.1i));
dout.writefln(tan(0.1i));
dout.writefln(log(1.1i));
dout.writefln(sqrt(-1i));
dout.writefln(acos(0.1i));
dout.writefln(asin(0.1i));
dout.writefln(atan(0.1i));
}cdouble exp(idouble z) {
auto y = z.im;
return std.math.cos(y) + 1i * std.math.sin(y);
}cdouble cos(idouble z) {
auto e = std.math.exp(z.im);
return (e + 1 / e) / 2 + 0i;
}cdouble sin(idouble z) {
auto e = std.math.exp(z.im);
return 0.5i * (e - 1 / e) + 0;
}cdouble tan(idouble z) {
auto e2 = std.math.exp(z.im * 2);
return 1i * (e2 - 1) / (e2 + 1) + 0;
}cdouble log(idouble z) {
return std.math.log(z.im) + std.math.PI * 0.5i;
}cdouble sqrt(idouble z) {
auto y = z.im;
if(y >= 0)
return (1 + 1i) * std.math.sqrt(y / 2);
else
return (1 - 1i) * std.math.sqrt(-y / 2);
}cdouble acos(idouble z) {
auto y = z.im;
return std.math.PI / 2
- 1i * std.math.log(y + std.math.sqrt(y * y + 1));
}cdouble asin(idouble z) {
auto y = z.im;
return 1i * std.math.log(y
+ std.math.sqrt(y * y + 1)) + 0;
}cdouble atan(idouble z) {
auto y = z.im;
return 0.5 * log((1 + y) / (1 - y) + 0i);
}cdouble log(cdouble z) {
double x = z.re;
double y = z.im;
return std.math.log(x * x + y * y) / 2
+ 1i * atan2(y, x);
}cdouble sqrt(cdouble z) {
double x = z.re;
double y = z.im;
double theta = atan2(y, x) / 2;
return std.math.sqrt(abs(z))
* (std.math.cos(theta) + 1i * std.math.sin(theta));
}