What does DATA INF/1.D+300/ mean in Fortran?

2020-04-11 13:18发布

I'm translating some Fortran to our C# app and I'm trying to figure out what a bit of Fortran means at the top of a function.

  DOUBLE PRECISION INF, DMIN, D12

  DATA INF/1.D+300/

What would the value of INF be?

标签: fortran
4条回答
SAY GOODBYE
2楼-- · 2020-04-11 13:50

The value would be 1.0e300, but I'm sure that what is intended is that it be set to the largest double value that can be expressed on the current CPU. so in C# that would be double.PositiveInfinity rather than some hard-coded value.

查看更多
爷、活的狠高调
3楼-- · 2020-04-11 14:00

The D means "× 10???", or commonly known as the e in 1.e+300 in C#, but it's for double precision.

The DOUBLE PRECISION statement just defines 3 variables to be of type double.

The DATA statement

DATA X/Y/

translates to

X = Y;

in C#. Hence you get

double INF = 1.e+300, DMIN, D12;

Since INF is so large I believe it means "Infinity", in that case it's better to use the real IEEE infinity (double INF = double.PositiveInfinity, ...).

查看更多
▲ chillily
4楼-- · 2020-04-11 14:01

The code is in the style of FORTRAN IV or FORTRAN 77 rather than Fortran 90/95/2003.

Double Precision declares the variables to be double the precision of a regular real. I'm not sure that the FORTRAN standards of that era were extremely precise about what that meant, since there was a greater variety of numeric hardware then. Today, it will virtually always obtain an 8-byte real. The Data statement initializes the variable INF. The use of "D" in the constant "1.D+300", instead of E, is old FORTRAN to specify that the constant is double precision.

The Fortran (>=90) way of obtaining the largest positive double is:

INF = huge (1.0D+0)

查看更多
仙女界的扛把子
5楼-- · 2020-04-11 14:12

The code is declaring a constant called INF (i.e. infinity) with the value 10^300. You would want to substitute double.PositiveInfinity or double.MaxValue.

查看更多
登录 后发表回答