Nп/п : 23 из 100
 От   : robin vowels                        2:5075/128        30 авг 23 19:49:59
 К    : jfh                                                   30 авг 23 05:51:02
 Тема : Re: Real number precision in fortran
----------------------------------------------------------------------------------
                                                                                 
@MSGID:
<9fc18888-bab4-44a5-8152-3c20ca33b566n@googlegroups.com> b00e9d4d
@REPLY:
<058f2111-ca5a-4e6d-92b7-af3e3337277dn@googlegroups.com> 58132da8
@REPLYADDR robin vowels <robin51@dodo.com.au>
@REPLYTO 2:5075/128 robin vowels
@CHRS: CP866 2
@RFC: 1 0
@RFC-References:
<873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com> <54381db2-bcf5-4714-b100-b7e0cfc86f1en@googlegroups.com>
<058f2111-ca5a-4e6d-92b7-af3e3337277dn@googlegroups.com>
@RFC-Message-ID:
<9fc18888-bab4-44a5-8152-3c20ca33b566n@googlegroups.com>
@TZUTC: -0700
@PID: G2/1.0
@TID: FIDOGATE-5.12-ge4e8b94
On Thursday, 31 August 2023 at 07:43:20 UTC+10, jfh wrote:
> On Wednesday, August 30, 2023 at 6:02:37 PM UTC+12, robin vowels wrote: 
> > On Sunday, 27 August 2023 at 23:52:41 UTC+10, Kim Hanjoon wrote: 
 > > > Hi, I`m new at Fortran. I`m studying numerical analysis and
I got question about real number precision 
> > > 
> > > program test 
> > > real*8 x 
> > . 
> > You need: 
> > double precision x 
> > to be standard conforming. 
> > > 
> > > x = 1.0/3.0 
> > . 
> > You have used single-precision constants. You need to write 
> > x = 1d0 / 3d0 
> > . 
> > > write(*,*) x 
> > > stop 
> > > end 
> > > 
 > > > Above code gives result 0.33333334326744080. I know why this
happens because computer can not represent real number exactly but only
gives approximation. 
> > > 
 > > > However, similar code in Python or C++ gives
0.3333333333333333 which is more closer to 1/3 than 0.33333334326744080. Somebody said
their difference is small so I can ignore, but I want to represent as
possible as I can. I wonder how I can fix that rough approximation. 
> > > 
> > > I used gfortran in windows10. 
> > > 
> > > Thank you.
 > Double precision x was the only way to be standard-conforming in
Fortran 77. Many of us would now use something like 

> integer, parameter :: dp = kind(1d0) 
> real(dp) x
.
The OP is beginning in Fortran.
It makes sense to tell him something straightforward and simple..
I have been using what you suggest from F90 days.
--- G2/1.0
 * Origin: usenet.network (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх