提取工具函数

This commit is contained in:
SOR
2026-06-21 11:05:42 +08:00
parent c59105ef43
commit 1c48f91be5
13 changed files with 259 additions and 444 deletions
+1 -17
View File
@@ -33,23 +33,7 @@ Speed of Sound Calculator (Successive Difference Method)
- 声速 v 的不确定度 (忽略 f 的极小不确定度): u(v) = f * u(λ)
"""
def scientific_round(value, uncertainty):
"""
按照“四舍六入五凑偶”修约:
1. 不确定度 u 保留一位有效数字
2. 平均值末位与 u 对齐
"""
if uncertainty == 0:
return str(value), "0"
u_float = float(uncertainty)
first_digit_pos = math.floor(math.log10(u_float))
prec = Decimal('1e' + str(first_digit_pos))
u_final = uncertainty.quantize(prec, rounding=ROUND_HALF_EVEN)
val_final = value.quantize(prec, rounding=ROUND_HALF_EVEN)
return val_final, u_final
from utils import scientific_round
def calculate_method(method_name, f, k, delta_inst):
print(f"\n========================================")