由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - sscanf problem in MSVC 7
相关主题
c++ 中如何把str转换为float?面试题还是不太清楚怎么回答。尤其是8,我用MSVC试了一下,没有问题啊。
一个c语言的问题lifeaswater, please answer question in post 5700
关于gdb的问题, 谢谢Qt/Windows 开源版本将支持 VS Express
compare double to floatC array
问sscanf一道c++的考古题
问个C/C++题目[合集] 面试题还是不太清楚怎么回答。尤其是8,我用MSVC试了一下,没有
how to sscanf this case.Help: Another C++ compilation error on GCC
求助,这样从c++输入窗口读入一连串的单词或数字呢?C++ help: 一个multiple definition problem.
相关话题的讨论汇总
话题: intsec话题: lf话题: sscanf话题: msvc话题: dis
进入Programming版参与讨论
1 (共1页)
i*****f
发帖数: 578
1
Hi, I'm having trouble with the following codes;
=======================================
sscanf(s, "%d %s %s %lf %lf %lf %d",
&(intsec[i].ref),
intsec[i].name,
intsec[i].state,
&(intsec[i].dis),
&(intsec[i].logi),
&(intsec[i].latt),
&(intsec[i].pop) );
======================================
When the string s is like "342 omak WA 0.8 119.5141 ...."
The 4th value intsec[i].dis will scan in 0.799999999...
k****e
发帖数: 100
2
It seems right.
0.7999999..... == 0.8

【在 i*****f 的大作中提到】
: Hi, I'm having trouble with the following codes;
: =======================================
: sscanf(s, "%d %s %s %lf %lf %lf %d",
: &(intsec[i].ref),
: intsec[i].name,
: intsec[i].state,
: &(intsec[i].dis),
: &(intsec[i].logi),
: &(intsec[i].latt),
: &(intsec[i].pop) );

i*****f
发帖数: 578
3
But why is that when I try that using gcc, I got exactly 0.8 ???

【在 k****e 的大作中提到】
: It seems right.
: 0.7999999..... == 0.8

m****e
发帖数: 7
4
How do you know it's exactly 0.8 on gcc?? There is never an "exact 0.8" for
floating point value. 0.8 = 4/5, and 5 is not a power of 2.
i*****f
发帖数: 578
5
All right, you guys are right. I found it's printed like 0.8000...4 in gdb
the same phenomena as in MSVC. But when I compare it with 0.8, it returns
true.

【在 m****e 的大作中提到】
: How do you know it's exactly 0.8 on gcc?? There is never an "exact 0.8" for
: floating point value. 0.8 = 4/5, and 5 is not a power of 2.

t****t
发帖数: 6806
6
没听说过直接比较两个浮点数相等的

【在 i*****f 的大作中提到】
: All right, you guys are right. I found it's printed like 0.8000...4 in gdb
: the same phenomena as in MSVC. But when I compare it with 0.8, it returns
: true.

d*******d
发帖数: 2050
7
normal,负点精度。

【在 i*****f 的大作中提到】
: Hi, I'm having trouble with the following codes;
: =======================================
: sscanf(s, "%d %s %s %lf %lf %lf %d",
: &(intsec[i].ref),
: intsec[i].name,
: intsec[i].state,
: &(intsec[i].dis),
: &(intsec[i].logi),
: &(intsec[i].latt),
: &(intsec[i].pop) );

1 (共1页)
进入Programming版参与讨论
相关主题
C++ help: 一个multiple definition problem.问sscanf
有谁知道怎么把matlab和VC联接着一起用? (转载)问个C/C++题目
C++ questionhow to sscanf this case.
听说pointer to member function只支持最多128个virtual functi求助,这样从c++输入窗口读入一连串的单词或数字呢?
c++ 中如何把str转换为float?面试题还是不太清楚怎么回答。尤其是8,我用MSVC试了一下,没有问题啊。
一个c语言的问题lifeaswater, please answer question in post 5700
关于gdb的问题, 谢谢Qt/Windows 开源版本将支持 VS Express
compare double to floatC array
相关话题的讨论汇总
话题: intsec话题: lf话题: sscanf话题: msvc话题: dis