avatar
有个问题drive me crazy# Computation - 科学计算
w*n
1
有谁能在Pentium 的CPU上得到这样的计算结果:
1.0/3.0=0.33333333333333333333 (3的个数多于16位)?
要是谁能写这么一个程序,我就佩服他了。当然是用最简单的办法。 不论什么complior
和platform(Suse, redhat, or XP ...). 但是一定要使Pentium 的CPU.
avatar
t*e
2

这是Pentium 4上得结果,正好16个3:
program main
real(8) :: a,b,c
c = 1.d0/3.d0
print'(F20.18)',c
end
0.333333333333333303

【在 w****n 的大作中提到】
: 有谁能在Pentium 的CPU上得到这样的计算结果:
: 1.0/3.0=0.33333333333333333333 (3的个数多于16位)?
: 要是谁能写这么一个程序,我就佩服他了。当然是用最简单的办法。 不论什么complior
: 和platform(Suse, redhat, or XP ...). 但是一定要使Pentium 的CPU.

avatar
w*n
3
忘记说了,一定要用C++/C

不论什么complior

【在 t*****e 的大作中提到】
:
: 这是Pentium 4上得结果,正好16个3:
: program main
: real(8) :: a,b,c
: c = 1.d0/3.d0
: print'(F20.18)',c
: end
: 0.333333333333333303

avatar
i*w
4
换UNIX系统。 换REAL8. 好像能更多位吧

【在 w****n 的大作中提到】
: 忘记说了,一定要用C++/C
:
: 不论什么complior

avatar
h*o
5
Wed May 12 19:52:05 PDT 2004=====>[~/temp]
[email protected]: pts/0: 25 files 37Mb-> cat onethird.c
#include
main()
{
double a, b;
a = 1.e0;
b = 3.e0;
printf("%18.16lf\n", a/b);
}
Wed May 12 19:52:10 PDT 2004=====>[~/temp]
[email protected]: pts/0: 25 files 37Mb-> gcc -o onethird.exe onethird.c
Wed May 12 19:52:13 PDT 2004=====>[~/temp]
[email protected]: pts/0: 25 files 37Mb-> ./onethird.exe
0.3333333333333333
123456789ABCDEF0
十六个三了吧。
Wed May 12 19:52:17 PDT 2004=====>

【在 w****n 的大作中提到】
: 忘记说了,一定要用C++/C
:
: 不论什么complior

avatar
a*s
6
meaningless work

【在 w****n 的大作中提到】
: 忘记说了,一定要用C++/C
:
: 不论什么complior

avatar
w*n
7
what did u mean?

【在 a******s 的大作中提到】
: meaningless work
avatar
h*o
8
[email protected]: pts/0: 25 files 37Mb-> cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 9
model name : Intel(R) Pentium(R) M processor 1400MHz
stepping : 5
cpu MHz : 1395.881
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr mce cx8 sep m

【在 h***o 的大作中提到】
: Wed May 12 19:52:05 PDT 2004=====>[~/temp]
: [email protected]: pts/0: 25 files 37Mb-> cat onethird.c
: #include
: main()
: {
: double a, b;
: a = 1.e0;
: b = 3.e0;
: printf("%18.16lf\n", a/b);
: }

avatar
w*n
9
我是需要多于16个3。如果是double, 最多16个3。

【在 h***o 的大作中提到】
: Wed May 12 19:52:05 PDT 2004=====>[~/temp]
: [email protected]: pts/0: 25 files 37Mb-> cat onethird.c
: #include
: main()
: {
: double a, b;
: a = 1.e0;
: b = 3.e0;
: printf("%18.16lf\n", a/b);
: }

avatar
w*n
10
what are you doing? u can only obtain 16 "3". :)

clflush dts acpi mmx fxsr sse sse2 tm pbe tm2 est

【在 h***o 的大作中提到】
: [email protected]: pts/0: 25 files 37Mb-> cat /proc/cpuinfo
: processor : 0
: vendor_id : GenuineIntel
: cpu family : 6
: model : 9
: model name : Intel(R) Pentium(R) M processor 1400MHz
: stepping : 5
: cpu MHz : 1395.881
: cache size : 1024 KB
: fdiv_bug : no

avatar
h*o
11
那没戏,让(1.0+t == 1.0)为真的最大t值,在pentium机里差不多就是3e-17左右
所以没戏吧。

【在 w****n 的大作中提到】
: 我是需要多于16个3。如果是double, 最多16个3。
avatar
h*o
12
look at this one
[email protected]: pts/0: 25 files 37Mb-> gcc -o onethird.exe onethird.c
Wed May 12 20:00:26 PDT 2004=====>[~/temp]
[email protected]: pts/0: 25 files 37Mb-> ./onethird.exe
0.333333333333333314829616256247390992939472198486328125
I am pretty sure there are more than sixteen '3's....hoho

【在 w****n 的大作中提到】
: what are you doing? u can only obtain 16 "3". :)
:
: clflush dts acpi mmx fxsr sse sse2 tm pbe tm2 est

avatar
t*e
13
Why C?
I got more than 20 using fortran
program main
real :: c
c = 1./3.
print'(F22.20)',c
end
using ifc7.1
ifc -r16 -pc80 test.f90
./a.out
0.33333333333333333333(20 '3's)

【在 w****n 的大作中提到】
: 忘记说了,一定要用C++/C
:
: 不论什么complior

avatar
w*n
14
it depends on ur data type. GSL has extended precision IEEE ... but it's not
working in my PC/Suse.所以我想来这里问问有什么高人知道怎么干。

【在 h***o 的大作中提到】
: 那没戏,让(1.0+t == 1.0)为真的最大t值,在pentium机里差不多就是3e-17左右
: 所以没戏吧。

avatar
w*n
15
这是我最想不通的事情。居然c/c++没有办法得到这样的double precision(extended
precision)?????

【在 t*****e 的大作中提到】
: Why C?
: I got more than 20 using fortran
: program main
: real :: c
: c = 1./3.
: print'(F22.20)',c
: end
: using ifc7.1
: ifc -r16 -pc80 test.f90
: ./a.out

avatar
a*s
16

-pc80好像没用吧?

【在 t*****e 的大作中提到】
: Why C?
: I got more than 20 using fortran
: program main
: real :: c
: c = 1./3.
: print'(F22.20)',c
: end
: using ifc7.1
: ifc -r16 -pc80 test.f90
: ./a.out

avatar
h*o
17
16字节的real算起来巨慢,这个我有经验
我要不把那部分改了,再给我5年我也不可能毕业

【在 t*****e 的大作中提到】
: Why C?
: I got more than 20 using fortran
: program main
: real :: c
: c = 1./3.
: print'(F22.20)',c
: end
: using ifc7.1
: ifc -r16 -pc80 test.f90
: ./a.out

avatar
a*s
18
你看看thinkme是怎么编译的,再看看hanzo那程序写法和编译法,就知道为什么了.:)

【在 w****n 的大作中提到】
: 这是我最想不通的事情。居然c/c++没有办法得到这样的double precision(extended
: precision)?????

avatar
w*n
19
no. thinkme 用的是fortran. 和hanzo不是一回事情。

【在 a******s 的大作中提到】
: 你看看thinkme是怎么编译的,再看看hanzo那程序写法和编译法,就知道为什么了.:)
avatar
a*s
20
我c和fortran还是能看出来的:),语言是区别,但是不是本质。

【在 w****n 的大作中提到】
: no. thinkme 用的是fortran. 和hanzo不是一回事情。
avatar
w*n
21
我就是找不到用gcc 编译的时候,如果我的data type在程序里是long double, 我是否要
在编译的时候加一些flag.

【在 t*****e 的大作中提到】
: Why C?
: I got more than 20 using fortran
: program main
: real :: c
: c = 1./3.
: print'(F22.20)',c
: end
: using ifc7.1
: ifc -r16 -pc80 test.f90
: ./a.out

avatar
w*n
22
so, please tell me how to get it work in C, or it's just not going to work in
C. I will really appreicate. :)

.:)

【在 a******s 的大作中提到】
: 我c和fortran还是能看出来的:),语言是区别,但是不是本质。
avatar
a*s
23
hanzo用的是gcc,是没有-r8 or -r16这样的选项的,他程序里面是double,这样就
相当于thinkme用-r8做出来的,而thinkme实际上用的是-r16,当然就比hanzo的高了,
但是-r16也是有限度的,
$ ./a.out
0.3333333333333333333333333333333333173000
解决的办法就是改gcc为icc,这样我估计就可以做到了,程序都是一样的,但是
declare的不同,当然结果就不同了。

【在 w****n 的大作中提到】
: so, please tell me how to get it work in C, or it's just not going to work in
: C. I will really appreicate. :)
:
: .:)

avatar
t*e
24
I cant make long double work properly using g++
here is the code
#include
int main()
{
long double a;
a = 1.0/3.0;
printf("%22.20lf\n",a);
return 0;
}
here is the output:
-0.00000000000000000000
which is obviously wrong.
If I use double, the output is:
0.33333333333333331483
still 16 '3's but not more than that

【在 w****n 的大作中提到】
: so, please tell me how to get it work in C, or it's just not going to work in
: C. I will really appreicate. :)
:
: .:)

avatar
h*o
25
gcc用long double能搞到19位3
[email protected]: pts/0: 26 files 37Mb-> ./onethird.exe
0.3333333333333333333423683514
加了-m128bit-long-double好象还是这么多

【在 a******s 的大作中提到】
: hanzo用的是gcc,是没有-r8 or -r16这样的选项的,他程序里面是double,这样就
: 相当于thinkme用-r8做出来的,而thinkme实际上用的是-r16,当然就比hanzo的高了,
: 但是-r16也是有限度的,
: $ ./a.out
: 0.3333333333333333333333333333333333173000
: 解决的办法就是改gcc为icc,这样我估计就可以做到了,程序都是一样的,但是
: declare的不同,当然结果就不同了。

avatar
h*o
26

%22.20Lf

【在 t*****e 的大作中提到】
: I cant make long double work properly using g++
: here is the code
: #include
: int main()
: {
: long double a;
: a = 1.0/3.0;
: printf("%22.20lf\n",a);
: return 0;
: }

avatar
w*n
27
hi, achillis, and thinkme and all:
thank you very much for helping out. it does sound like that i should try
icc. make sense. but what's the flag i shall use?
or any icc manual?

in

【在 a******s 的大作中提到】
: hanzo用的是gcc,是没有-r8 or -r16这样的选项的,他程序里面是double,这样就
: 相当于thinkme用-r8做出来的,而thinkme实际上用的是-r16,当然就比hanzo的高了,
: 但是-r16也是有限度的,
: $ ./a.out
: 0.3333333333333333333333333333333333173000
: 解决的办法就是改gcc为icc,这样我估计就可以做到了,程序都是一样的,但是
: declare的不同,当然结果就不同了。

avatar
w*n
28
hi, hanzo,你是怎么搞到19位的????with what flag??


work in

【在 h***o 的大作中提到】
: gcc用long double能搞到19位3
: [email protected]: pts/0: 26 files 37Mb-> ./onethird.exe
: 0.3333333333333333333423683514
: 加了-m128bit-long-double好象还是这么多

avatar
a*s
29
install icc if you want to use c, ifc for fortran. You will find the document
in the doc directory. It should come with icc.

【在 w****n 的大作中提到】
: hi, achillis, and thinkme and all:
: thank you very much for helping out. it does sound like that i should try
: icc. make sense. but what's the flag i shall use?
: or any icc manual?
:
: in

avatar
h*o
30

man了一下gcc就明白了
-m128bit-long-double
These switches control the size of "long double" type. The i386
application binary interface specifies the size to be 96 bits, so
-m96bit-long-double is the default in 32 bit mode.
Modern architectures (Pentium and newer) would prefer "long double"
to be aligned to an 8 or 16 byte boundary. In arrays or structures
conforming to the ABI, this would not be possible. So specifying a
-m

【在 h***o 的大作中提到】
: gcc用long double能搞到19位3
: [email protected]: pts/0: 26 files 37Mb-> ./onethird.exe
: 0.3333333333333333333423683514
: 加了-m128bit-long-double好象还是这么多

avatar
a*s
31
还是没我的多:)

【在 h***o 的大作中提到】
: gcc用long double能搞到19位3
: [email protected]: pts/0: 26 files 37Mb-> ./onethird.exe
: 0.3333333333333333333423683514
: 加了-m128bit-long-double好象还是这么多

avatar
h*o
32
no flag needed....just use long double
printf use %Lf instead of %lf

【在 w****n 的大作中提到】
: hi, hanzo,你是怎么搞到19位的????with what flag??
:
: ,
: work in

avatar
w*n
33
no, it's working here:
[email protected]:~/program/PRECISION> more long.c
#include
int main()
{
long double a;
a = 1.0/3.0;
printf("%22.20Lf\n",a);
return 0;
}
[email protected]cp57:~/program/PRECISION> gcc long.c
[email protected]:~/program/PRECISION> ./a.out
0.33333333333333331483

【在 h***o 的大作中提到】
: no flag needed....just use long double
: printf use %Lf instead of %lf

avatar
h*o
34
你这个gcc太土了吧。hoho
[email protected]: pts/0: 26 files 37Mb-> gcc -v
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/specs
Configured with: /var/tmp/portage/gcc-3.3.3-r3/work/gcc-3.3.3/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.3 --includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3
avatar
w*n
35
here it is:
[email protected]:~/program/PRECISION> gcc -v
Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.1/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr
avatar
h*o
36
要么是版本太低,要么是有些开关编译的时候没打开,比如
avatar
a*s
37

这个是有可能的,编译器编译的时候有很多options的。
gentoo宰牛也没有icc牛,呵呵
我试了fedora的gcc
$ gcc a.c
$ ./a.out
0.33333333333333331483
#include
int main()
{
long double a;
a = 1.0/3.0;
printf("%22.20Lf\n",a);
return 0;
}

【在 h***o 的大作中提到】
: 要么是版本太低,要么是有些开关编译的时候没打开,比如
avatar
a*s
38
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)

【在 a******s 的大作中提到】
:
: 这个是有可能的,编译器编译的时候有很多options的。
: gentoo宰牛也没有icc牛,呵呵
: 我试了fedora的gcc
: $ gcc a.c
: $ ./a.out
: 0.33333333333333331483
: #include
: int main()
: {

avatar
w*n
39
i just tried redhat gcc, it's not working. :(( hehe

【在 a******s 的大作中提到】
: $ gcc -v
: Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.2/specs
: Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
: Thread model: posix
: gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)

avatar
a*s
40
icc比gcc快多了,功能也多不少,尤其是-r选项,这么方便的东西为啥不用呢?
我都说了解决办法了,即使你重装机器,装gentoo的话,gentoo上的gcc也不比
icc快,何苦呢?:)

【在 w****n 的大作中提到】
: i just tried redhat gcc, it's not working. :(( hehe
avatar
w*n
41
hehe. achillis,这个问题我搞了很久乐, 现在特别好奇.就想try try. i actually
like ur solution best.
我现在就是有点好奇,怎么hanzo的gcc 能work呢? 其实20个3对我刚刚好。呵呵。

【在 a******s 的大作中提到】
: icc比gcc快多了,功能也多不少,尤其是-r选项,这么方便的东西为啥不用呢?
: 我都说了解决办法了,即使你重装机器,装gentoo的话,gentoo上的gcc也不比
: icc快,何苦呢?:)

avatar
a*s
42

没什么好奇的,gentoo编译gcc的时候可能打开了那个option,kaka,如果你够坚定,
可以自己编个gcc和hanzo抗衡,kaka

【在 w****n 的大作中提到】
: hehe. achillis,这个问题我搞了很久乐, 现在特别好奇.就想try try. i actually
: like ur solution best.
: 我现在就是有点好奇,怎么hanzo的gcc 能work呢? 其实20个3对我刚刚好。呵呵。

avatar
h*o
43
你难道不知道现在amd的cpu比intel的卖得多?

【在 a******s 的大作中提到】
: icc比gcc快多了,功能也多不少,尤其是-r选项,这么方便的东西为啥不用呢?
: 我都说了解决办法了,即使你重装机器,装gentoo的话,gentoo上的gcc也不比
: icc快,何苦呢?:)

avatar
a*s
44
做数值计算,我只用intel,kaka,管什么amd? amd现在和intel差多少钱了?

【在 h***o 的大作中提到】
: 你难道不知道现在amd的cpu比intel的卖得多?
avatar
a*s
45
其实,你需不需要那么多位这才是我第一个回帖的意思。这个比icc还重要,kaka

【在 w****n 的大作中提到】
: hehe. achillis,这个问题我搞了很久乐, 现在特别好奇.就想try try. i actually
: like ur solution best.
: 我现在就是有点好奇,怎么hanzo的gcc 能work呢? 其实20个3对我刚刚好。呵呵。

avatar
f*r
46
AMD is simply faster :)

【在 a******s 的大作中提到】
: 做数值计算,我只用intel,kaka,管什么amd? amd现在和intel差多少钱了?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。