# test the functions imported from cmathtry:from cmath import *except ImportError:print("SKIP")raise SystemExit# make sure these constants exist in cmathprint("%.5g" % e)print("%.5g" % pi)test_values_non_zero = []base_values = (0.0, 0.5, 1.2345, 10.)for r in base_values:for i in base_values:if r != 0. or i != 0.:test_values_non_zero.append(complex(r, i))if r != 0.:test_values_non_zero.append(complex(-r, i))if i != 0.:test_values_non_zero.append(complex(r, -i))if r != 0. and i != 0.:test_values_non_zero.append(complex(-r, -i))test_values = [complex(0., 0.),] + test_values_non_zeroprint(test_values)functions = [('phase', phase, test_values),('polar', polar, test_values),('rect', rect, ((0, 0), (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, 1), (1, -1), (123., -456.))),('exp', exp, test_values),('log', log, test_values_non_zero),('sqrt', sqrt, test_values),('cos', cos, test_values),('sin', sin, test_values),]for f_name, f, test_vals in functions:print(f_name)for val in test_vals:if type(val) == tuple:ret = f(*val)else:ret = f(val)if type(ret) == float:print("%.5g" % ret)elif type(ret) == tuple:print("%.5g %.5g" % ret)else:# some test (eg cmath.sqrt(-0.5)) disagree with CPython with tiny real partreal = ret.realif abs(real) < 1e15:real = 0.print("complex(%.5g, %.5g)" % (real, ret.imag))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。