编程介的小学生 2017-04-13 10:41 采纳率: 0.2%
浏览 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 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?