编程介的小学生 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 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的