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!

REAL values converted into c++ double values

Status
Not open for further replies.

consideration

Programmer
Aug 19, 2005
4
DE
Hi,

i would like to know how a value like

"REAL*8 red
red = 1.0d-10"

would be stated in c++

"double red;
red = ???"

or other FORTRAN REAL expressions
like "0.1d0, 4.0d0, 2.908228d01, 2.01327d-04" ..

THANKS in Advance
 
1.0d-10 is 1.0 divided by 10 to the power 10.

In other word the d-10 is the exponent.

So 0.1d0 is 0.1.
4.0d0 is 4.0.
2.908228d01 is 29.08228
2.01327d-04 is 0.0000201377 (I may be out by a factor of 10 here!)

Can't remember how that works for C++...
 
In C++, replace D with E

1.0D-10 = 1.0E-10
0.1d0 = 0.1E0 or 0.1
4.0d0 = 4.0E0 or 4.0
2.908228d01 = 2.908228E1
2.01327d-04 = 2.01327E-4

In Fortran, if it is REAL*4, and E format is used, add a trailing F to the number. eg
Code:
! Fortran
REAL* xxx
xxx = 1.23E-4

// C++
float xxx
xxx = 1.23E-4F
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top