Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...