提问人:Lucien Pruvot 提问时间:10/10/2023 更新时间:10/10/2023 访问量:23
FXPMATH :将两个无符号减去到一个有符号的结果中
fxpmath : substract two unsigned into a signed result
问:
import numpy as np
from fxpmath import Fxp as fxp
t1 = fxp(4, False, 9, 3)
t2 = fxp(5, False, 9, 3)
inter1 = fxp(0, True, 9, 3, raw=True)
inter2 = fxp(0, True, 9, 3, raw=True)
inter1(t1 - t2)
inter2(t1.get_val() - t2.get_val())
inter1 等于 0.00,因为计算中使用的两个数字是无符号的。我发现获得正确结果的唯一方法是使用 numpy 值(来自 get_val())。有没有最好的方法可以做到这一点?我不想把 t1 或 t2 放在签名中。
答: 暂无答案
评论
inter1(t1.like(inter1) - t2.like(inter1))