gpt4 book ai didi

c - 日志调用在 C 中返回 NaN

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

<分区>

我有一个 double 组:

double theoretical_distribution[] = {1/21, 2/21, 3/21, 4/21, 5/21, 6/21};

我正在尝试计算它的熵:

double entropy = 0;

for (int i = 0; i < sizeof(theoretical_distribution)/sizeof(*theoretical_distribution); i++) {
entropy -= (theoretical_distribution[i] * (log10(theoretical_distribution[i])/log10(arity)));
}

但是我得到的是 NaN,我已经检查了这部分

(theoretical_distribution[i] * (log10(theoretical_distribution[i])/log10(arity)))  

并发现它返回 NaN 本身,所以我认为它是罪魁祸首,但它应该是对日志的简单基本转换?我是否遗漏了有关它的一些数学细节?
为什么它评估为 NaN。

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