# 下面就是对两个乘法化为一个乘法的过程 # 先判断一下0.5n 是否大于0.5m # 如果大于的话 if branch_x2 > branch_y2: # 获取两者之差 pow_num = branch_x2-branch_y2 # 依次获取公式中第 1 2 3 4部分 A = x1*math.pow(10, pow_num)-x2 B = y2 - y1 C = temp_x1_y1*math.pow(10, pow_num) D = x2_y2
# 排除乘法中的负数,如果有负数的话,在上面计算的时候会麻烦很多 if A >= 0and B >= 0: mid = (multi(A, B) + C + D)*math.pow(10, branch_y2) elif A >= 0and B < 0: B = -B mid = (-multi(A, B) + C + D)*math.pow(10, branch_y2) elif A < 0and B >= 0: A = -A mid = (-multi(A, B) + C + D)*math.pow(10, branch_y2) else: A = -A B = -B mid = (multi(A, B) + C + D)*math.pow(10, branch_y2) else: pow_num = branch_y2-branch_x2 A = x1-x2 B = y2 - y1*math.pow(10, pow_num) C = temp_x1_y1*math.pow(10, pow_num) D = x2_y2 if A >= 0and B >= 0: mid = (multi(A, B) + C + D)*math.pow(10, branch_x2) elif A >= 0and B < 0: B = -B mid = (-multi(A, B) + C + D)*math.pow(10,branch_x2) elif A < 0and B >= 0: A = -A mid = (-multi(A, B) + C + D)*math.pow(10, branch_x2) else: A = -A B = -B mid = (multi(A, B) + C + D)*math.pow(10, branch_x2) return x1_y1 + mid + x2_y2
defgetNumLen(num): x = 0 while(num/10 != 0): x += 1 num = int(num/10) return x