编程介的小学生 2017-04-13 10:41 采纳率: 20.5%
浏览 816
已采纳

Complex Calculator

Dr. Jimbo, an applied mathematician, needs to calculate complex numbers all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating complex numbers expressions, however, he cannot use it outside his laboratory because the software consumes much of resources. He wants to manipulate complex numbers outside, so he needs a small program similar to the excellent application for his handheld computer.

Your job is to provide him a program that computes expressions of complex numbers.

Expressions of complex numbers just has almost the same grammer as the C programming language's. The only difference is that all constants are complex numbers and there is a special constant "i", which is the imaginary unit (i*i=-1). Besides the elementary arithmetic operations, namely addition, subtraction, multiplication and division, all following function should be implemented:
function:

x+y return new complex value x plus y.
x-y return new complex value x minus y.
x*y return new complex value x times y.
x/y return new complex value x divided by y.
abs(x) return magnitude of x. abs(x) = sqrt(x * conj(x)).
acos(x) return complex arc cosine of x, with real part in [0,pi]. acos(x) = -i log(x + sqrt(x * x - 1))
acosh(x) return complex arc hyperbolic cosine of x, with imaginary part in [-pi,pi] and real part non-negative. acosh(x) = (0.5) * log((1 + x) / (1 - x)).
arg(x) return phase angle of x. arg(x) = atan2(imag(x), real(x))
asin(x) return complex arc sine of x, with real part in [-pi/2,pi/2]. asin(x) = -i log(iz + sqrt(1 - x * x)).
asinh(x) return complex arc hyperbolic sine of x, with imaginary part in [-pi/2,pi/2]. asinh(x) = log(x + sqrt(x * x + 1)).
atan(x) return complex arc tangent of x, with real part in [-pi/2,pi/2]. atan(x) = 1 / 2i log((1 + iz) / (1 - iz)).
atanh(x) return complex arc hyperbolic tangent of x, with imaginary part in [-pi/2,pi/2]. atanh(x) = 0.5 * log((1 + x) / (1 - x)).
conj(x) return complex conjugate of x.
cos(x) return complex cosine of x. cos(x) = (exp(i * x) + exp(-i * x)) / 2.
cosh(x) return complex hyperbolic cosine of x. cosh(x) = (exp(x) + exp(-x)) / 2.
exp(x) return complex base e exponential of x. exp(i * x) = cos(x) + i * sin(x)
imag(x) return imaginary part of complex number x.
log(x) return complex natural logarithm of x. log(x) = log(abs(x)) + i * arg(x).
pow(x,y) return x raised to the power y, with a branch cut for x along the negative real axis.
real(x) return real part of complex number x.
sin(x) return complex sine of x. sin(x) = (exp(i * x) - exp(-i * x)) / (2 * i).
sinh(x) return complex hyperbolic sine of x. sinh(x) = (exp(x) - exp(-x)) / 2.
sqrt(x) return complex square root of x, with non-negative real part, and with a branch cut along the negative real axis.
tan(x) return complex tangent of x. tan(x) = sin(x) / cos(x).
tanh(x) return complex hyperbolic tangent of x. tanh(x) = sinh(x) / cosh(x).

All other operations and functions are invalid. Overflow and division by zero are also invalid.
Input

Lines of expressions. There are no blanks in the expression and it's guaranteed that the expression is always valid.

Output

For each expression, output the result with six digits after the decimal point, always output the sign ('+' or '-'). See sample for more details. Never output "-0.000000"!

Sample Input

i*i
pow(-1*i,2)
sqrt(-1.0)
8+6*i/8-6*i
(8+6*i)/(8-6*i)
(8+6*i)*conj(8-6*i)
2*exp(i*acos(-1)/6)
pow(i,i)
cos(i)
cos(-1*i)
acos(cos(i))
acos(cos(i*-1))
pow(exp(1),acos(-1)*i)
Sample Output

-1.000000+0.000000*i
-1.000000+0.000000*i
+0.000000+1.000000*i
+8.000000-5.250000*i
+0.280000+0.960000*i
+28.000000+96.000000*i
+1.732051+1.000000*i
+0.207880+0.000000*i
+1.543081+0.000000*i
+1.543081+0.000000*i
+0.000000+1.000000*i
+0.000000+1.000000*i
-1.000000+0.000000*i

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记