----------------------------------------------------------------------------------
@MSGID:
<54381db2-bcf5-4714-b100-b7e0cfc86f1en@googlegroups.com> bce74982
@REPLY:
<873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com> 5e2916c7
@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>
@RFC-Message-ID:
<54381db2-bcf5-4714-b100-b7e0cfc86f1en@googlegroups.com>
@TZUTC: -0700
@PID: G2/1.0
@TID: FIDOGATE-5.12-ge4e8b94
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.
--- 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