在计算时结果输出1.#INF,1.#J,求解。。。

O112358 2010-09-28 04:18:45
在计算时结果输出1.#INF,1.#J,


float Speed=0.0;
// 进度条步长
UINT ProcessLength;
//进度说明
CString Notice;
UINT Perscent=0;
float statu=0.0;
ProcessLength=29760182;
DWORD Strat=0,End=0;

Strat=GetTickCount();//DWORD
//读文件
Readed=file->Read(ByteReceive,sizeof(ByteReceive));//ByteReceive设置为8888
End=GetTickCount();//DWORD
Speed=(float)Readed*1000/(End-Strat);//1000毫秒;
Perscent=Perscent+Readed;//UINT
float LeftTime=0;
LeftTime=(ProcessLength-Perscent)/Speed;//在这里Speed的值有时出现,1.#INF,不像溢出,除数为零
Notice.Format(_T("剩余时间:%6.2f s"),LeftTime);
DownNoticeInfo.LeftTime->SetWindowTextW(Notice);
if(Speed>=1024&&Speed<1024*1024)
Notice.Format(_T("即时速度:%6.2fKB/s"),Speed/1024);
else
if(Speed>=1024*1024)
Notice.Format(_T("即时速度:%6.2fMB/s"),Speed/1024/1024);//这里输出怎么会出现1.#JMB?
else
Notice.Format(_T("即时速度:%6.2fB/s"),Speed);
DownNoticeInfo.DownSpeed->SetWindowTextW(Notice);

下面为截图:
...全文
538 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
O112358 2010-09-30
  • 打赏
  • 举报
回复
回楼上的几位,版本是vs2010的。。
问题已搞定,起初认为那个值不会为零的,但还是为零了。
O112358 2010-09-30
  • 打赏
  • 举报
回复
问题自己解决了。。。
应该是(End-Strat)<1导致的。
一般读取网络文件是不会出现那么快的速度(限速<60Kb/s的Ftp下载文件),还是出错了。
加一句保险的,其实也应该考虑到的:
if((End-Strat)<1)
End-Strat=1;
就行了。
可以结贴了。
谁知道更精确的计时函数,毫秒以下的?
cattycat 2010-09-30
  • 打赏
  • 举报
回复
看来除数是0了,楼主的好像是vs08吧,要么就是Dev了。
iambic 2010-09-30
  • 打赏
  • 举报
回复
请教下你这截图是啥开发环境?
logiciel 2010-09-30
  • 打赏
  • 举报
回复
Speed=(float)Readed*1000/(End-Strat);
当End-Strat为0时,speed为1.#INF000。

请参考以下解释(http://www.codeguru.com/forum/archive/index.php/t-220306.html):

The IEEE floating point defines a couple "special case" situations.
1) Infinity
double d0 = 0.0;
double d1 = 1.0;
double inf = d1/d0; // results in 'infinity'. Contrary to popular belief this will NOT cause a divide by zero unless you explicitely tell the compiler to generate an exception instead of infinity result.
CString str;
str.Format("%0.2f", inf); // "1.#J"
str.Format("%0.5f", inf); // "1.#INF00000"

2) Indefinite
double d0 = 0.0;
double ind = d0 / d0;
CString str;
str.Format("%0.2f", inf); // "1.#J"
str.Format("%0.5f", inf); // "1.#IND00000"

3) (Signaling/Quiet) NAN (Not A Number)
These can't occur as result of a calculation on valid numeric values, but can occur by illegal asignent of 'random' bits to a floating point value. easiest way to 'cause' this to happen is using a QNAN assign on the FPU stack.

example...
typedef struct
{
UINT64 u64Mantissa : 63;
UINT64 u64Integer : 1;
WORD wExponent : 15;
WORD wSign : 1;
} FP80;
FP80 qnan = { 0, 0x7FFF, 1, 0x7FFFFFFFFFFFFFFF };
double qnan2;
_asm
{
FLD TBYTE PTR qnan // look at registers in debugmode, ST0 on FPU stack will contain "1#QNAN "
FSTP qnan2
FWAIT
}
str.Format("%0.2f", inf); // "1.#R"
str.Format("%0.5f", inf); // "1.#QNAN0000"

O112358 2010-09-30
  • 打赏
  • 举报
回复
没人?。。
O112358 2010-09-28
  • 打赏
  • 举报
回复
up,up myself...
dingshaofengbinbin 2010-09-28
  • 打赏
  • 举报
回复
没遇到过!待高手。。

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧