| View previous topic :: View next topic |
| Author |
Message |
bland
Joined: 27 Oct 2004 Posts: 3
|
Posted: Wed Oct 27, 2004 10:07 am Post subject: real*8 conversion errors |
|
|
I have the following test program on:
Linux Red Hat 8.0 kernel 2.4.18-14
GLIBC version 2.2.93-5
PGF77 version 5.1-2
program newtest
implicit none
real*8 myreal, newreal
myreal = 25.13982364598249
newreal = 17.77777777777777
write(*,*) 'myreal = ',myreal
write(*,*) 'newreal = ',newreal
end
The output of this program is:
myreal = 25.13982391357422
newreal = 17.77777862548828
The output values are obviously not the same as in the code.
Has anyone else come across this problem and if so what was done to correct it? I would imagine it to be a compiler bug. Any input would be very helpful. |
|
| Back to top |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Wed Oct 27, 2004 12:49 pm Post subject: |
|
|
Hi Bland,
Actually, its not a compiler bug. In fortran, real literal constants have an implict kind just like variables. So what's happening is at compile time your constant values are being truncated to fit the default size of a "real" which is 4 bytes.
With pgf77 and pgf90 you can add the compilation flag "-r8" to change the implicit kind for reals to be "real*8". Also with pgf90, you can append the real literal constant with a kind parameter.
Example:
myreal=25.13982364598249_8
Hope this clarifies things,
Mat
Last edited by mkcolg on Mon Feb 07, 2005 3:02 pm; edited 1 time in total |
|
| Back to top |
|
 |
cyrus
Joined: 13 Jan 2005 Posts: 2
|
Posted: Thu Jan 13, 2005 1:02 am Post subject: |
|
|
Hello,
Does this mean that only specify REAL*8 in the code is not enough?
Thanks |
|
| Back to top |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Thu Jan 13, 2005 9:23 am Post subject: |
|
|
REAL*8 only applies to the variable not the literal constant. Constants also have a "kind". If you want this kind to be anything other than the default, you must specify it. See Michael Metcalf and John Reid's Fortran 90/95 Explained discussion of types in sections 2.5 and 2.6 for further information.
- Mat |
|
| Back to top |
|
 |
|