From e0aac26713517e94fbb45595719fcf5e0b64234c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 26 Dec 2020 00:08:52 +0800 Subject: [PATCH] decimal! --- libs/P_C.py | 10 ++++++---- libs/__init__.py | 2 +- libs/tools.py | 18 +++++++++++++----- test.py | 6 +++--- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/libs/P_C.py b/libs/P_C.py index f743e7d..782ba22 100644 --- a/libs/P_C.py +++ b/libs/P_C.py @@ -8,16 +8,18 @@ file name stand for : Physics calculation import libs import math +from libs.tools import F_Mi, F_Mu, F_A, F_D + def S_C_float_check(SC): # stand for Scientific notation's float check """ formats: SC list format:docs.basic_config.json:basic_number""" while SC[0] >= 10: - SC[0] /= 10 + SC[0] = F_D(SC[0], 10) SC[1] += 1 while SC[0] < 1: - SC[0] *= 10 + SC[0] = F_Mu(SC[0], 10) SC[1] -= 1 @@ -25,7 +27,7 @@ def S_N_M(A, B): # stand for Scientific notation multiple """ formats: A & B list format:docs.basic_config.json:basic_number""" - C = [A[0] * B[0], int(A[1] + B[1])] + C = [F_Mu(A[0], B[0]), F_A(A[1], B[1])] S_C_float_check(C) Unit1, Unit2 = A[2] + B[2], A[3] + B[3] if Unit1 == None: @@ -39,7 +41,7 @@ def S_N_D(A, B): # stand for Scientific notation divided """ formats: A & B list format:docs.basic_config.json:basic_number""" - C = [float(A[0] / B[0]), int(A[1] - B[1])] + C = [F_D(A[0], B[0]), F_Mi(A[1], B[1])] S_C_float_check(C) Unit1, Unit2 = A[2] + B[3], A[3] + B[2] if Unit1 == None: diff --git a/libs/__init__.py b/libs/__init__.py index b39f7fc..c976dad 100644 --- a/libs/__init__.py +++ b/libs/__init__.py @@ -6,7 +6,7 @@ mail: 3695888@qq.com import libs.Game_threads # import in this forder -import libs.S_D +import libs.P_C import libs.main import libs.tools import libs.loads diff --git a/libs/tools.py b/libs/tools.py index 5847470..b914228 100644 --- a/libs/tools.py +++ b/libs/tools.py @@ -35,16 +35,24 @@ def D_C(listA, listB): # stand for Duplicate check def F_Mu(A, B): # stand for float multiple - pass + a = decimal.Decimal(str(A)) + b = decimal.Decimal(str(B)) + return float(a * b) def F_D(A, B): # stand for float divided - pass + a = decimal.Decimal(str(A)) + b = decimal.Decimal(str(B)) + return float(a / b) -def F_P(A, B): # stand for float plus - pass +def F_A(A, B): # stand for float plus + a = decimal.Decimal(str(A)) + b = decimal.Decimal(str(B)) + return float(a + b) def F_Mi(A, B): # stand for float minus - pass + a = decimal.Decimal(str(A)) + b = decimal.Decimal(str(B)) + return float(a - b) diff --git a/test.py b/test.py index a7d5477..e860ed7 100644 --- a/test.py +++ b/test.py @@ -12,9 +12,9 @@ B = [2.45, -7, ["N", "kg"], ["m", "s"]] print("A = " , A) print("B = " , B) -C = libs.S_D.S_N_M(A, B) -D = libs.S_D.S_N_D(A, B) -E = libs.S_D.S_N_D(C, B) +C = libs.P_C.S_N_M(A, B) +D = libs.P_C.S_N_D(A, B) +E = libs.P_C.S_N_D(C, B) print("A × B = " , C) print("A ÷ B = " , D)