CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Main CFD Forum

fortran code problem

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   September 6, 2009, 21:24
Default fortran code problem
  #1
Senior Member
 
ztdep's Avatar
 
p ding
Join Date: Mar 2009
Posts: 284
Rep Power: 9
ztdep is on a distinguished road
Send a message via Yahoo to ztdep Send a message via Skype™ to ztdep
Dear firends:
I write a simple code with the fortran 95 , but i can not understantd the following.

I declare a double precdision number
Real*8 a=3.1
but when i out put it with
write(*,*) a
the Intel fortran give me the following
3.09999990463257
i can not understand this, could you please give me some hints.

Regards
ztdep is offline   Reply With Quote

Old   September 6, 2009, 22:28
Default
  #2
New Member
 
Ananda Himansu
Join Date: Apr 2009
Location: Cleveland, Ohio, USA
Posts: 17
Rep Power: 8
Ananda Himansu is on a distinguished road
Try
Real*8 a=3.1d0
Ananda Himansu is offline   Reply With Quote

Old   September 6, 2009, 23:28
Default
  #3
Senior Member
 
ztdep's Avatar
 
p ding
Join Date: Mar 2009
Posts: 284
Rep Power: 9
ztdep is on a distinguished road
Send a message via Yahoo to ztdep Send a message via Skype™ to ztdep
thank you very much , it works.

3.1d0 means 3.1 is a double float number, but i have declare the variable a as real*8. then what is the difference
If i want 3.1 to be a long double float number, which symbol should i use.

Regards
ztdep is offline   Reply With Quote

Old   September 7, 2009, 10:22
Default
  #4
New Member
 
Ananda Himansu
Join Date: Apr 2009
Location: Cleveland, Ohio, USA
Posts: 17
Rep Power: 8
Ananda Himansu is on a distinguished road
You have to use the KIND parameter in the declaration of the variable. Also use a suffix of type real-kind for a constant such as 3.1. See any Fortran 90/95/2003 book or other documentation for the details. This will give you real*16 only if such a kind is available on the cpu architecture or if the compiler supports it through a library (the latter would be slow to execute). The actual value of the kind parameter depends on the architecture and compiler. You can use the PRECISION parameter to find the closest KIND.
Ananda Himansu is offline   Reply With Quote

Old   September 7, 2009, 10:40
Default
  #5
Senior Member
 
ztdep's Avatar
 
p ding
Join Date: Mar 2009
Posts: 284
Rep Power: 9
ztdep is on a distinguished road
Send a message via Yahoo to ztdep Send a message via Skype™ to ztdep
Than you very much, Dear friends:
What is the difference between "Real*8 " and "Real(kind=8)", I think it is the same thing.
ztdep is offline   Reply With Quote

Old   September 8, 2009, 04:22
Default
  #6
Member
 
Mohammad Reza Hadian
Join Date: Mar 2009
Location: Yazd, Iran
Posts: 50
Rep Power: 8
hadian is on a distinguished road
real*8
real(8)
real(kind=8)
are the same
hadian is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
3D fortran Navier-Stokes code emrah Main CFD Forum 4 December 15, 2007 10:53
Looking for a open FEM code to solve a FSI problem Esto Main CFD Forum 3 June 15, 2006 11:02
Big loop problem of fortran Wen Long Main CFD Forum 9 April 1, 2004 12:38
a fortran problem in CFX Roy CFX 3 November 14, 2002 09:17
SIMPLE code for 3_D problem bobby Main CFD Forum 1 December 26, 2000 00:20


All times are GMT -4. The time now is 23:07.