gpt4 book ai didi

c - Double 不在 C 中存储数字(数字太小)

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

<分区>

这是我的问题,我需要计算 1 ms 中有多少个时钟周期,而我们的 pll 在 TM4C123 上等待。但是,我的 double 值显示为零,使我的其他值不正确。任何帮助将不胜感激。

#include <stdio.h>

int main()
{
float ms_cycled;
float us_cycled;
int ms_cycle;
int us_cycle;
unsigned long MHz = 50;
double TPC = 1/(MHz*10000000); //calculate time per clock cycle

//calculate cycles for ms
ms_cycled = 0.001/TPC;
ms_cycle = ms_cycled;
//calculate cycles for us
us_cycled = 0.000001/TPC;
us_cycle = us_cycled;
printf("TPC = %.16f \n", TPC);
printf("ms_cycled = %f \n", ms_cycled);
printf("us_cycled = %f \n", us_cycled);
printf("ms_cycle = %i \n", ms_cycle);
printf("us_cycle = %i \n", us_cycle);
return 0;
}

我得到的输出是:

TPC = 0.0000000000000000                                                                                                                             
ms_cycled = inf
us_cycled = inf
ms_cycle = -2147483648
us_cycle = -2147483648

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