Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
536 views
in Technique[技术] by (71.8m points)

fortran - Extended double precision

Is it possible to obtain more than 16 digits with double precision without using quadruple? If it is possible, does it depend on compiler or something else? Because I know someone said he was working with double precision and had 22 digit precision.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The data type double precision stems from Fortran 77, and the only requirement for that type is that is has more precision than real. You shouldn't use that any more.

In Fortran 90/95 and beyond, at least two sizes of real numbers are supported. The precision is determined by the kind parameter, of which the value depends on the compiler.

real(kind=8) :: a, b

To have a portable way of defining precision, you can obtain a kind value that allows a certain precision by using:

integer, parameter :: long_double = SELECTED_REAL_KIND(22)

then you can declare your variables as

real(kind=long_double) :: a, b

but it is not certain your compiler will support that precision, in which case the SELECTED_REAL_KIND function will return a negative number.

see also this post


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...