gpt4 book ai didi

c - 在 C 中使用 long double 减法后会产生奇怪的结果

转载 作者:行者123 更新时间:2023-11-30 19:32:41 24 4
gpt4 key购买 nike

我刚刚开始学习 C,我有一个非常有趣的问题。我会让代码自己说话。在 scanf 上,我给出值 25.15:

long double input;
scanf("%Lf", &input);
printf("%Lf\n", input); //its correctly 25.150000
input = input - 0.75;
printf("%Lf\n", input); //Instead of something resembling 24.4 I get -2

25.15 - 0.75 怎么可能给我 -2?

最佳答案

我在CodeBlocks中也遇到了和你一样的问题。与 double.. 完美配合。完成一些 googling 。这似乎是已知问题。也可以尝试谷歌搜索“long double给出错误的结果c”,我希望你能在那里找到答案。

关于c - 在 C 中使用 long double 减法后会产生奇怪的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46797477/

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