- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear All,
I have a problem with a real number conversion. I would like to convert a single precision real number into a double precision. I wrote a simple program which uses DBLE() function.
% cat conversion.f
program conversion
real(4) sx1
real(8) dx1
sx1=1.000010
dx1=dble(sx1)
write(*,*) sx1,dx1
end
When I run the program I get the following result:
% ./conversion
1.000010 1.00001001358032
I wish that the result of conversion is 1.00001000000000 (or perhaps 1.00001000000001 or. 1.00000999999999).
With Best Regards,
Zoran
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
dx1 = 1.00001d0
The conversion you have written performs an exact binary extension. As 1.00001d0 is not exactly representable in single precision, it is different from 1.00001, as you showed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Tim,
thanks for the answer. Yes, I was serious with this question, but I was thinking decimaly and not binary :-) .
Here is the listing of the expanded test:
% cat conversion.f
program conversion
real(4) sx1
real(8) dx1
character string*15
sx1=1.00001
dx1=dble(sx1)
write(*,*) sx1,dx1
write(string,*) sx1
read(string,*) dx1
write(*,*) sx1,dx1
end
% ./conversion
1.000010 1.00001001358032
1.000010 1.00001000000000
Regards, Zoran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page