The iv.mpf type represents a closed interval [a,b][a,b]; that is, the set {x:a≤x≤b}{x:a≤x≤b}, where aa and bb are arbitrary-precision floating-point values, possibly ±∞±∞. The iv.mpc type represents a rectangular complex interval [a,b]+[c,d]i[a,b]+[c,d]i; that is, the set {z=x+iy:a≤x≤b∧c≤y≤d}{z=x+iy:a≤x≤b∧c≤y≤d}.
# The number of digits with which numbers are printed by default is determined by the working precision. To specify the number of digits to show without changing the working precision, use mpmath.nstr() and mpmath.nprint(): >>> a = mpf(1) / 6 >>> a mpf('0.16666666666666666') >>> nstr(a, 8) '0.16666667' >>> nprint(a, 8) 0.16666667 >>> nstr(a, 50) '0.16666666666666665741480812812369549646973609924316'
>>> fadd(2, 1e-20, rounding='u') # 当然还有fsub mpf('2.0000000000000004') # Valid options are 'n' for nearest (default), # 'f' for floor, 'c' for ceiling, 'd' for down, 'u' for up.
>>> x, y = mpf(2), mpf('1e1000') >>> print(x - y + y) #把prec跳到5k也可以 0.0 >>> print(fsub(x, y, prec=inf) + y) 2.0 >>> print(fsub(x, y, exact=True) + y) 2.0
fneg,fmul,fdiv,fmod,fabs sign
re, im # real\image part arg polar # polar phase >>> arg(-3j) -1.5707963267949 >>> polar(-2) (2.0, 3.14159265358979) #旋转 >>> chop(rect(2, pi)) -2.0
# 点乘 >>> A = [2, 1.5, 3] >>> B = [1, -1, 2] >>> fdot(A, B) mpf('6.5') >>> list(zip(A, B)) [(2, 1), (1.5, -1), (3, 2)] >>> fdot(_) mpf('6.5')