gpt4 book ai didi

c - 在 C 中使用定点运算的 Horner 规则

转载 作者:太空宇宙 更新时间:2023-11-04 03:20:15 25 4
gpt4 key购买 nike

我很难根据 Horner 规则使用定点算法来追踪小数点。

int16_t horner(int16_t q)
{
const int16_t c0 = 0x0033;
const int16_t c1 = 0x0055;
const int16_t c2 = 0x001C;
const int16_t c3 = 0x0048;
const int16_t c4 = 0x0200;

horner_rule = c0 + q * (c1 - q * (c2 + q * (c3 - q * c4)));

return horner_rule;
}

其中c0c1为不同的16位有符号系数,q为值我想在(q 作为输入并转换为 16 位有符号格式)处进行评估。所有这些值都已转换为带符号的 16 位格式。我已经在浮点运算中实现了它,它运行良好。

我的问题是,我应该如何继续获得我想要的值,同时保持小数点并控制溢出?

最佳答案

首先是确定多项式和偏项的域和余域。然后,您可以调整类次以最大限度地减少截断错误,同时避免溢出。

如果您需要自动执行此过程,则必须找到所有这些多项式的最小值和最大值,这需要求解实根。

关于c - 在 C 中使用定点运算的 Horner 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47053852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com