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) );
|
|