convert fortran real to...

A

Al

I am about to start rewriting a fortran program to ansi C++.

Would it be best to convert the variables that are 'real' to float?
double? long double?
 
P

Phlip

Al said:
I am about to start rewriting a fortran program to ansi C++.

Step 1: use f2c, to translate Fortran source into complete C source that
compiles and runs. F2C is so stable that many use it as their Fortran
compiler. They never read the C intermediate.

Step 2: Read the C intermediate. It is not that bad, once you learn how
stereotypically it wraps all the Fortran nuances. But it won't be C++. Don't
ask it to be and you'l do fine. You can make minor tweaks to code in this
state.

Step 3: Write a billion unit tests that completely characterize this legacy
code. Many tests can pass sample data, collect sample results, and compare
them to golden references.

Step 4: Erase the source, and make each unit test pass by writing new
source.

Notice that at each step you can stop and have something useful to work
with.
 
I

Ioannis Vranos

Al said:
I am about to start rewriting a fortran program to ansi C++.

Would it be best to convert the variables that are 'real' to float?
double? long double?


It depends on the precision that you want. I would begin with double.
 
C

Chris Theis

Al said:
I am about to start rewriting a fortran program to ansi C++.

Would it be best to convert the variables that are 'real' to float?
double? long double?

To be on the safe side I'd go with double.

Cheers
Chris
 
B

beliavsky

Chris said:
To be on the safe side I'd go with double.

I agree, but let me note that most Fortran compilers on 32-bit
platforms use 4-byte reals, which corresponds to a C/C++ float. If the
Fortran programmer thought 8 byte variables were necessary, he would
have declared them as DOUBLE PRECISION or the nonstandard, but common,
REAL*8. Many Fortran compilers have an option to "promote" REAL
variables to double precision. If one has a make file or build script
showing that this option was used, then the corresponding C++ variables
should be double.
 
R

red floyd

Chris said:
To be on the safe side I'd go with double.

Actually, if you're lucky, then they're already declared in fortran as
either
REAL*4 or REAL*8, in which case the decision for float or double is made
for you. Otherwise, I'd agree with Chris and go with double.

It's been ages since I did FORTRAN (back in the ancient WATFOR/WATFIV
days), but didn't it also have an explicit DOUBLE PRECISION declaration?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,203
Messages
2,571,059
Members
47,668
Latest member
SamiraShac

Latest Threads

Top