- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
When I make some calculation in double precision using an integer, I don't receive a good result.
For example, I made a simple program to write 0.10000000, 0.20000000, ...2.000000000 :
program do
implicit none
real(8) step, allo
integer i
step=0.1
do i=1,nint(2/step)
allo=real(i,8)*step
write(*,*) allo
end do
end program
But I receive
0.100000001490116
0.200000002980232
0.300000004470348
0.400000005960464
0.500000007450581
0.600000008940697
0.700000010430813
0.800000011920929
0.900000013411045
1.00000001490116
1.10000001639128
1.20000001788139
1.30000001937151
1.40000002086163
1.50000002235174
1.60000002384186
1.70000002533197
1.80000002682209
1.90000002831221
2.00000002980232
What should I do to correct the problem?
Nath
When I make some calculation in double precision using an integer, I don't receive a good result.
For example, I made a simple program to write 0.10000000, 0.20000000, ...2.000000000 :
program do
implicit none
real(8) step, allo
integer i
step=0.1
do i=1,nint(2/step)
allo=real(i,8)*step
write(*,*) allo
end do
end program
But I receive
0.100000001490116
0.200000002980232
0.300000004470348
0.400000005960464
0.500000007450581
0.600000008940697
0.700000010430813
0.800000011920929
0.900000013411045
1.00000001490116
1.10000001639128
1.20000001788139
1.30000001937151
1.40000002086163
1.50000002235174
1.60000002384186
1.70000002533197
1.80000002682209
1.90000002831221
2.00000002980232
What should I do to correct the problem?
Nath
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Replace "step=0.1" by "step=0.1d0".
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page