1。整数常量默认是Int 型
浮点常量默认是单精度double型
25 b=sizeof(1.1);
26 printf("%d\n",b); 8
27 b=sizeof(1.1l);
28 printf("%d\n",b); 16
29 b=sizeof(1.1f);
30 printf("%d\n",b); 4
加 l,L 说明是 long double 型,double 的扩展型
加 f,F 说明是single float 型 , 4byte
L A following a, A, e, E, f, F, g, or G conversion corresponds to a long double argument. (C99
allows %LF, but SUSv2 does not.)
l (ell) A following integer conversion corresponds to a long int or unsigned long int argument, or a
following n conversion corresponds to a pointer to a long int argument, or a following c conver-
sion corresponds to a wint_t argument, or a following s conversion corresponds to a pointer to
wchar_t argument.
L和l 的使用与操作系统有关系。
2.
读浮点类型的数据时,为了保持精度,避免使用%f,
应使用 fscanf(fp,%s,array);
atof
这样能保持原始数据的精度。
- 16 int main()
-
17 {
-
18 double *list;
-
19 double sum;
-
20 int i;
-
21 int n=30*1024;
-
22 unsigned int sax,sdx,fax,fdx;
-
23 long long int cycles;
-
24 list=(double *)malloc(sizeof(double)*n);
-
25 for(i=0;i<n;i++)
-
26 list[i]=drand48();
-
27 __asm__ __volatile__(
-
28 "rdtsc\n\t"
-
29 :"=a"(sax),"=d"(sdx));
-
30 for(i=0;i<10000;i++)
-
31 sum=pure_load(list,n);
-
32 __asm__ __volatile__(
-
33 "rdtsc\n\t"
-
34 :"=a"(fax),"=d"(fdx));
-
35 cycles=(long long int)(fdx-sdx)*0x0100000000l;
-
36 printf("%lld\n",cycles);
-
37 cycles=(long long int )(fdx-sdx)*0x0100000000l + fax-sax;
-
38 printf("sax sdx %u %u \n",sax,sdx);
-
39 printf("fax fdx %u %u \n",fax,fdx);
-
40 printf("%lld\n",cycles);
-
41 return 0;
-
42 }
阅读(624) | 评论(0) | 转发(0) |