Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOUBLE PRECISION

Status
Not open for further replies.

GerritGroot

Technical User
Nov 3, 2006
291
ES
Hi,

I would like to run a certain subroutine with variables in DOUBLE PRECISION, while the main program is in REAL.

However, as soon as the REAL data from the main program passes as input to the subroutine to the DOUBLE PRECISION type, the numbers don't match anymore.

Is there a way to get around this without converting the whole program in DOUBLE PRECISION?

Thanks in advance,

Gerrit
 
REALs (as usually 32 bit values) and DOUBLE PRECISIONs (as usually 64 bit values) have totally different internal bit representations (REAL data image is not short version of DOUBLE PRECISION data image). Let's compile the subroutine with DOUBLE PRECISION input parameters. It uses 64-bit floating point commands to process data, right? These commands can't process 32-bit floating point values.

So prepare input data for this routine (convert to DOUBLE PRECISION in temp storage) then convert results back - or rewrite the subroutine (or caller;) totally. For example, write some kind of wrappers for DOUBLE PRECISION subroutines (allocate DOUBLE PRECISION storage, move REAL data then pass to the subroutine then convert back and free temp storage etc).

In actual fact short floats have insufficient precision for any serious calculations. Use REALs if you have tons of low precision external data (from sensors, for example) but process data with DOUBLE PRECISION (convert results back and save if you wish;)...

As far as I know some compilers have a switch to treat all REAL data as DOUBLE PRECISION. May be it helps (but it is a question;).
 
Well, I don't know, I think that with a proper normalisation DOUBLE PRECISION shouldn't be necessary. The problem is that many codes are not made by one and the same person or that people don't normalise properly.

Anyway, what do you mean by temporal storage? To a file?
Any temporal storage to memory is associated with either REAL (32bit) or DOUBLE PRECISION(64bit)

Is there a fortran command that converts it, similar like INT(1.0) converts to 1 or FLOAT(2) converts to 2. or isn't there some command like DOUBLE(2.8)=2.8000000...00000(64bit)?

Thanks in advance,

Gerrit
 
You may simply assign REAL value to DOUBLE PRECISION variable, or use DBLE intrinsic function.
Of course, temp storage = new DOUBLE PRECISION array(s).

You may use ALLOCATE/DEALLOCATE statements for these temporaries. Allocate temp array then copy REAL array to this tenp array - that's all.

REAL and DOUBLE PRECISION numbers have different bit fields for mantissa and exponent, it's not a question of normalization.

The key point: it's impossible to process short floating point REAL data with DOUBLE PRECISION code w/o explicit (or implicit, as in expression) conversion. It's impossible to cheat DOUBLE PRECISION code with memory mapping tricks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top