Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The moon is a planet just like the Earth, only it is even deader.


devel / comp.lang.fortran / Re: Real number precision in fortran

SubjectAuthor
* Real number precision in fortranKim Hanjoon
+* Real number precision in fortrangah4
|+- Real number precision in fortranGary Scott
|`* Real number precision in fortranKim Hanjoon
| +* Real number precision in fortranGary Scott
| |+- Real number precision in fortranGiorgio Pastore
| |`- Real number precision in fortrangah4
| +* Real number precision in fortrangah4
| |+- Real number precision in fortranSpiros Bousbouras
| |`* Real number precision in fortranRon Shepard
| | `- Real number precision in fortranGary Scott
| `* Real number precision in fortranpehache
|  `- Real number precision in fortrangah4
+- Real number precision in fortranLynn McGuire
`* Real number precision in fortranrobin vowels
 `* Real number precision in fortranjfh
  `- Real number precision in fortranrobin vowels

1
Real number precision in fortran

<873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10071&group=comp.lang.fortran#10071

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:318a:b0:76c:d5e2:23b4 with SMTP id bi10-20020a05620a318a00b0076cd5e223b4mr876352qkb.11.1693144359858;
Sun, 27 Aug 2023 06:52:39 -0700 (PDT)
X-Received: by 2002:a17:90a:8505:b0:26c:f05d:1f2 with SMTP id
l5-20020a17090a850500b0026cf05d01f2mr5447161pjn.7.1693144359338; Sun, 27 Aug
2023 06:52:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sun, 27 Aug 2023 06:52:38 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=110.76.108.168; posting-account=-umF9goAAAD1sr2xCtmVfTkv0Nc-lly2
NNTP-Posting-Host: 110.76.108.168
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
Subject: Real number precision in fortran
From: khongs...@gmail.com (Kim Hanjoon)
Injection-Date: Sun, 27 Aug 2023 13:52:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1705
 by: Kim Hanjoon - Sun, 27 Aug 2023 13:52 UTC

Hi, I'm new at Fortran. I'm studying numerical analysis and I got question about real number precision

program test
real*8 x

x = 1.0/3.0

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.

Re: Real number precision in fortran

<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10072&group=comp.lang.fortran#10072

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:a85:b0:64a:742c:dcbd with SMTP id ev5-20020a0562140a8500b0064a742cdcbdmr715776qvb.1.1693145383035;
Sun, 27 Aug 2023 07:09:43 -0700 (PDT)
X-Received: by 2002:a17:902:c40c:b0:1c0:ac09:4032 with SMTP id
k12-20020a170902c40c00b001c0ac094032mr3758570plk.9.1693145382610; Sun, 27 Aug
2023 07:09:42 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sun, 27 Aug 2023 07:09:41 -0700 (PDT)
In-Reply-To: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:e4d2:d2f9:551c:893;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:e4d2:d2f9:551c:893
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
Subject: Re: Real number precision in fortran
From: gah...@u.washington.edu (gah4)
Injection-Date: Sun, 27 Aug 2023 14:09:43 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2855
 by: gah4 - Sun, 27 Aug 2023 14:09 UTC

On Sunday, August 27, 2023 at 6:52:41 AM UTC-7, 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
>
> x = 1.0/3.0
>
> 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.

The first answer to your question is x = 1.d0/3.d0

(Since you have REAL*8, you don't need the modern version yet.)

> However, similar code in Python or C++ gives 0.3333333333333333 which is
> more closer to 1/3 than 0.33333334326744080.

I believe that Python only does double precision, but someone can say if
that is wrong.

In C, I believe inherited by C++, floating point constants default to double.

C, as defined by K&R, evaluated all expressions in double precision,
though still allowing for float (single precision) variables.

That works well with processors that automatically evaluate
to full precision, like x87.

But Fortran constants default to single precision, and so 1.0/3.0
is evaluated in single precision, even though you assign to a REAL*8
variable.

It is one thing that Fortran programmers learn fast.

In actual fact, though, a large number of programs need double
precision intermediates to get single precision results.
(That is, to avoid precision loss in subtraction.)

Invert a 10x10 matrix in double precision, you will likely get
single precision results. Close enough, though.

Re: Real number precision in fortran

<ucg0kc$18o5d$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10073&group=comp.lang.fortran#10073

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: garylsc...@sbcglobal.net (Gary Scott)
Newsgroups: comp.lang.fortran
Subject: Re: Real number precision in fortran
Date: Sun, 27 Aug 2023 12:20:11 -0500
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <ucg0kc$18o5d$1@dont-email.me>
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 27 Aug 2023 17:20:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d5660a758afe420621f51ba7339ede43";
logging-data="1335469"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uHVlsO1tcd2rWAigB13sdHgd0+g0ph3I="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dtjGz0sjTIRTCHbu3I2K6UA7HWg=
Content-Language: en-US
In-Reply-To: <d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
 by: Gary Scott - Sun, 27 Aug 2023 17:20 UTC

On 8/27/2023 9:09 AM, gah4 wrote:
> On Sunday, August 27, 2023 at 6:52:41 AM UTC-7, 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
>>
>> x = 1.0/3.0
>>
>> 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.
>
> The first answer to your question is x = 1.d0/3.d0
>
> (Since you have REAL*8, you don't need the modern version yet.)
>
>> However, similar code in Python or C++ gives 0.3333333333333333 which is
>> more closer to 1/3 than 0.33333334326744080.
>
> I believe that Python only does double precision, but someone can say if
> that is wrong.
>
> In C, I believe inherited by C++, floating point constants default to double.
>
> C, as defined by K&R, evaluated all expressions in double precision,
> though still allowing for float (single precision) variables.
>
> That works well with processors that automatically evaluate
> to full precision, like x87.
>
> But Fortran constants default to single precision, and so 1.0/3.0
> is evaluated in single precision, even though you assign to a REAL*8
> variable.
>
> It is one thing that Fortran programmers learn fast.
>
> In actual fact, though, a large number of programs need double
> precision intermediates to get single precision results.
> (That is, to avoid precision loss in subtraction.)
>
> Invert a 10x10 matrix in double precision, you will likely get
> single precision results. Close enough, though.
>
>
Sorry, newly installed news reader went to email.

REXX is user selectable precision.

Re: Real number precision in fortran

<ucgg3l$1bcgk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10075&group=comp.lang.fortran#10075

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lynnmcgu...@gmail.com (Lynn McGuire)
Newsgroups: comp.lang.fortran
Subject: Re: Real number precision in fortran
Date: Sun, 27 Aug 2023 16:44:17 -0500
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <ucgg3l$1bcgk$1@dont-email.me>
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 27 Aug 2023 21:44:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3752f80e03679bf060fb6f09479f20ca";
logging-data="1421844"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JyjETEYIkffExEUWh6bL1Yn/ElN7HRvs="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:7nrujbaK/kFRxEhbkPLQhxuElu8=
Content-Language: en-US
In-Reply-To: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
 by: Lynn McGuire - Sun, 27 Aug 2023 21:44 UTC

On 8/27/2023 8:52 AM, 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
>
> x = 1.0/3.0
>
> 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.

Use "x = 1.0d0 / 3.0d0".

The d0 forces the compiler to use double precision for floating point
constant values, I advise using this for all floating point constants.
The default in Fortran is to use single precision. Most Fortran
compilers allow you to change them to default double precision by a
command line switch. BTW, modern C defaults to double precision.

Lynn

Re: Real number precision in fortran

<3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10076&group=comp.lang.fortran#10076

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:8e:b0:410:9af1:f9db with SMTP id o14-20020a05622a008e00b004109af1f9dbmr740352qtw.8.1693183523361;
Sun, 27 Aug 2023 17:45:23 -0700 (PDT)
X-Received: by 2002:a17:902:f684:b0:1bc:6e30:d3c3 with SMTP id
l4-20020a170902f68400b001bc6e30d3c3mr9859510plg.12.1693183523103; Sun, 27 Aug
2023 17:45:23 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sun, 27 Aug 2023 17:45:22 -0700 (PDT)
In-Reply-To: <d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=143.248.11.249; posting-account=-umF9goAAAD1sr2xCtmVfTkv0Nc-lly2
NNTP-Posting-Host: 143.248.11.249
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com> <d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
Subject: Re: Real number precision in fortran
From: khongs...@gmail.com (Kim Hanjoon)
Injection-Date: Mon, 28 Aug 2023 00:45:23 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Kim Hanjoon - Mon, 28 Aug 2023 00:45 UTC

Thank you! I have never expected fortran's default precision is float not double.

Re: Real number precision in fortran

<ucgr2m$1cs20$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10077&group=comp.lang.fortran#10077

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: garylsc...@sbcglobal.net (Gary Scott)
Newsgroups: comp.lang.fortran
Subject: Re: Real number precision in fortran
Date: Sun, 27 Aug 2023 19:51:35 -0500
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <ucgr2m$1cs20$1@dont-email.me>
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
<3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 28 Aug 2023 00:51:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c1479826fc90389685ee2360328fd00f";
logging-data="1470528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nAAcO0ARemtZ0svDXvWnq6eJ+AnnX3Og="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:7K9qW6Q01Fr7Pni3TC5S9+Dk82M=
In-Reply-To: <3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
Content-Language: en-US
 by: Gary Scott - Mon, 28 Aug 2023 00:51 UTC

On 8/27/2023 7:45 PM, Kim Hanjoon wrote:
> Thank you! I have never expected fortran's default precision is float not double.

I was surprised some other languages don't do the same. In the past,
many systems only supported double precision with software which was
painfully slow. I find single precision perfectly fine for the majority
of common programming uses. But then I've always been aware of the
availability of double precision and on some system beyond double precision.

Re: Real number precision in fortran

<kl360pF1a4aU1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10078&group=comp.lang.fortran#10078

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: past...@units.it (Giorgio Pastore)
Newsgroups: comp.lang.fortran
Subject: Re: Real number precision in fortran
Date: Mon, 28 Aug 2023 11:00:05 +0200
Lines: 17
Message-ID: <kl360pF1a4aU1@mid.individual.net>
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
<3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
<ucgr2m$1cs20$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net SWYVSWMS3N/rELUdcTsMLQ6G5q05Gq1giDzVZvRtFnU+7fzCjX
Cancel-Lock: sha1:xp0XHQkI3fs8YMqi5S0s9IXX5Kg= sha256:KceDCskdOq5OF/7OwOIHRvdrmfOeZY7waBYMh8RLs7A=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.14.0
Content-Language: it
In-Reply-To: <ucgr2m$1cs20$1@dont-email.me>
 by: Giorgio Pastore - Mon, 28 Aug 2023 09:00 UTC

Il 28/08/23 02:51, Gary Scott ha scritto:
> On 8/27/2023 7:45 PM, Kim Hanjoon wrote:
>> Thank you! I have never expected fortran's default precision is float
>> not double.
>
> I was surprised some other languages don't do the same.  In the past,
> many systems only supported double precision with software which was
> painfully slow.  I find single precision perfectly fine for the majority
> of common programming uses.  But then I've always been aware of the
> availability of double precision and on some system beyond double
> precision.

One should also take into account that a standard for floating number
started to be used and incorporated into programming languages
relatively late. At the beginning of the eighties it was possible to
find real (float) at 32 bits represented with different ratios between
matissa/exponent, or using 48 or 60 bits.

Re: Real number precision in fortran

<3883c7bc-48d1-4910-bd1a-c55cb92c92bdn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10081&group=comp.lang.fortran#10081

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a37:ad06:0:b0:76f:454:8e6a with SMTP id f6-20020a37ad06000000b0076f04548e6amr295247qkm.4.1693228753390;
Mon, 28 Aug 2023 06:19:13 -0700 (PDT)
X-Received: by 2002:a05:6214:3905:b0:63c:edce:c71e with SMTP id
nh5-20020a056214390500b0063cedcec71emr929719qvb.3.1693228753199; Mon, 28 Aug
2023 06:19:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 28 Aug 2023 06:19:12 -0700 (PDT)
In-Reply-To: <3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:a954:9255:836b:f29a;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:a954:9255:836b:f29a
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com> <3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3883c7bc-48d1-4910-bd1a-c55cb92c92bdn@googlegroups.com>
Subject: Re: Real number precision in fortran
From: gah...@u.washington.edu (gah4)
Injection-Date: Mon, 28 Aug 2023 13:19:13 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4716
 by: gah4 - Mon, 28 Aug 2023 13:19 UTC

On Sunday, August 27, 2023 at 5:45:25 PM UTC-7, Kim Hanjoon wrote:
> Thank you! I have never expected fortran's default precision is float not double.

DOUBLE PRECISION didn't come until Fortran II, in 1958, on the
vacuum tube powered IBM 704 with up to (and often less than)
32K words of 36 bits each. The first machine with hardware floating
point, and only the 36 bit single precision.

C originated as a systems programming language, for writing things
like OS and compilers. Most often those didn't need much floating
point, but C did supply them. All expressions were evaluated in double
precision, and library routines only existed in double precision.

The C types were, and still are, float and double, which I note in your comment.

With the ANSI C standard in 1989, expressions could be evaluated in single
precision, but constants continued to default to double. A trailing f is used
for single precision constants, and leading f for single precision functions.
That was, then, about 31 years after Fortran originated double precision,
in software on a the first machine with floating point hardware.

The first Fortran standard in 1966 included most, but not all, the features
from IBM's Fortran IV, an upgrade from the Fortran II on the 704.

IBM had upgraded from the 704 to the still vacuum tube powered 709,
and then the transistorized version, the 7090, still with only single
precision hardware.

Double precision in hardware seems to go to the IBM 7094, an upgrade
of the 7090, in 1962.

IBM S/360 in the mid 1960's decreased the word size to 32 bits, with a
single precision 32 bit format, and double precision 64 bit format.
The change from 36 bits to 32 bits mean that much floating point that
was done in 36 bits, instead went to the 64 bit double precision type.

C was internal to Bell labs in 1976, with the book defining it released in 1978.

Note also that Fortran defines a double precision type as twice as big as
the single precision type, but mostly not the size of either one.

In the 1960's, CDC introduced its 60 bit machines, with hardware 60 bit
and software 120 bit double precision floating point. Fortran programmers
commonly used single precision on such machines, but double on the popular,
at about that time, IBM S/360 machines.

The second version of the Fortran standard in 1977 didn't change much of
the way floating point was done, but did introduce a CHARACTER data type
for the first time.

With the Fortran 90 and 95 standards, it was desired to keep as much as
possible compatible with the previous versions, so old programs would still
work the same way they always did.

By this time, programmers (except in CDC installations) were used to
using double precision constants with the D0 suffix. (Or other D
values, as needed.)

So, the default double precision constants originated in the system
programming language C, originally not popular for scientific programming.
It became more popular for scientific programming in the late 1980's,
about the time that the IBM PC with optional 8087 floating point processor,
and not so much later PC/AT with 80286 and optional 80287 floating point
processor were becoming more popular. The 8087 does all arithmetic in 80
bit registers, usually with the full 64 bit significand.

Re: Real number precision in fortran

<ce6b1092-5bf5-4bf3-9e8a-b5e6e753a8f0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10082&group=comp.lang.fortran#10082

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:a4b:b0:641:8c45:9fa6 with SMTP id ee11-20020a0562140a4b00b006418c459fa6mr805133qvb.12.1693228994347;
Mon, 28 Aug 2023 06:23:14 -0700 (PDT)
X-Received: by 2002:a63:3606:0:b0:564:17ba:47cd with SMTP id
d6-20020a633606000000b0056417ba47cdmr4900944pga.10.1693228993934; Mon, 28 Aug
2023 06:23:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 28 Aug 2023 06:23:13 -0700 (PDT)
In-Reply-To: <ucgr2m$1cs20$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:a954:9255:836b:f29a;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:a954:9255:836b:f29a
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com> <3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
<ucgr2m$1cs20$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ce6b1092-5bf5-4bf3-9e8a-b5e6e753a8f0n@googlegroups.com>
Subject: Re: Real number precision in fortran
From: gah...@u.washington.edu (gah4)
Injection-Date: Mon, 28 Aug 2023 13:23:14 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: gah4 - Mon, 28 Aug 2023 13:23 UTC

On Sunday, August 27, 2023 at 5:51:39 PM UTC-7, Gary Scott wrote:
> On 8/27/2023 7:45 PM, Kim Hanjoon wrote:
> > Thank you! I have never expected fortran's default precision is float not double.

> I was surprised some other languages don't do the same. In the past,
> many systems only supported double precision with software which was
> painfully slow. I find single precision perfectly fine for the majority
> of common programming uses. But then I've always been aware of the
> availability of double precision and on some system beyond double precision.

For the majority of common use, single precision results are fine, but often
that requires double precision intermediates. Many matrix operations easily
lose precision, when subtracting numbers that are close in value.

But yes, double precision hardware was slow in coming. First in the larger
mainframes, and then later also in the minicomputers that allowed for more
personal computing.

Re: Real number precision in fortran

<+BRAmlYTn4cAnKjm=@bongo-ra.co>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10084&group=comp.lang.fortran#10084

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.fortran
Subject: Re: Real number precision in fortran
Date: Mon, 28 Aug 2023 13:45:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <+BRAmlYTn4cAnKjm=@bongo-ra.co>
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com> <d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com> <3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
<3883c7bc-48d1-4910-bd1a-c55cb92c92bdn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 28 Aug 2023 13:45:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="27731cadeb3699a05d4be7fe786ee280";
logging-data="1818971"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RXmh6UKMFoBY6n7hN07A+"
Cancel-Lock: sha1:cYLwbIqAmULPlNTi9PrGhTwv3LU=
In-Reply-To: <3883c7bc-48d1-4910-bd1a-c55cb92c92bdn@googlegroups.com>
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
 by: Spiros Bousbouras - Mon, 28 Aug 2023 13:45 UTC

On Mon, 28 Aug 2023 06:19:12 -0700 (PDT)
gah4 <gah4@u.washington.edu> wrote:
> The C types were, and still are, float and double, which I note in your comment.

And long double .

Re: Real number precision in fortran

<uwAr_9YrL-hz5wl9KITOu2l5X1o@jntp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10085&group=comp.lang.fortran#10085

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!from-devjntp
Message-ID: <uwAr_9YrL-hz5wl9KITOu2l5X1o@jntp>
JNTP-Route: news2.nemoweb.net
JNTP-DataType: Article
Subject: Re: Real number precision in fortran
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com> <d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
<3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
Newsgroups: comp.lang.fortran
JNTP-HashClient: tnsWkqFJiOokZWImjtdsnXP6RTE
JNTP-ThreadID: 873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com
JNTP-Uri: http://news2.nemoweb.net/?DataID=uwAr_9YrL-hz5wl9KITOu2l5X1o@jntp
User-Agent: Nemo/0.999a
JNTP-OriginServer: news2.nemoweb.net
Date: Mon, 28 Aug 23 16:22:12 +0000
Organization: Nemoweb
JNTP-Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0
Injection-Info: news2.nemoweb.net; posting-host="fd5675444fb2abe5cff243786215e1a6f7fd1bea"; logging-data="2023-08-28T16:22:12Z/8172662"; posting-account="44@news2.nemoweb.net"; mail-complaints-to="newsmaster@news2.nemoweb.net"
JNTP-ProtocolVersion: 0.21.1
JNTP-Server: PhpNemoServer/0.94.5
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-JNTP-JsonNewsGateway: 0.96
From: pehach...@gmail.com (pehache)
 by: pehache - Mon, 28 Aug 2023 16:22 UTC

Le 28/08/2023 à 02:45, Kim Hanjoon a écrit :
> Thank you! I have never expected fortran's default precision is float not
> double.

The default precision is the one of the REAL type, nothing more. The
standard does not specify the actual size and precision of this type.
Although it is nowadays mapped to the IEEE754 single precision 32 bits
floating point by most (if not all) compilers, it was not the case in the
past. Notably, on the CRAY machines it was mapped to the hardware native
64 bits floating point.

But mapping the REAL type to 64 bits had an important drawback back then :
it was impossible to propose a 32 bits type in a portable way, as the
standard was only requiring the REAL type, and the DOUBLE PRECISION type,
which had to be twice the size of the REAL type.

Re: Real number precision in fortran

<cH4HM.836316$TPw2.99944@fx17.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10087&group=comp.lang.fortran#10087

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:102.0)
Gecko/20100101 Thunderbird/102.14.0
Subject: Re: Real number precision in fortran
Content-Language: en-US
Newsgroups: comp.lang.fortran
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
<3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
<3883c7bc-48d1-4910-bd1a-c55cb92c92bdn@googlegroups.com>
From: nos...@nowhere.org (Ron Shepard)
In-Reply-To: <3883c7bc-48d1-4910-bd1a-c55cb92c92bdn@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 65
Message-ID: <cH4HM.836316$TPw2.99944@fx17.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Mon, 28 Aug 2023 12:20:08 -0500
X-Received-Bytes: 4426
 by: Ron Shepard - Mon, 28 Aug 2023 17:20 UTC

On 8/28/23 8:19 AM, gah4 wrote:
> The second version of the Fortran standard in 1977 didn't change much of
> the way floating point was done, but did introduce a CHARACTER data type
> for the first time.

This is true regarding the floating point formats themselves, but an
important feature of f77 was the idea of generic functions. Before f77,
for example, the programmer was required to use SIN(X) for REAL argument
X and DSIN(X) for double precision argument X. The same was true for all
of the intrinsic functions ABS/DABS, SQRT/DSQRT, and so on.

At that time, a REAL variable was likely to be any of 24-bits, 32-bits,
36-bits, 48-bits, 60-bits, or 64-bits on a given compiler, so that made
writing portable programs, where the source code could be used
unchanged, difficult. If your application required, say 8 decimal digits
of precision, then on some machines you needed to use double precision
while on other machines real was sufficient. The generic functions
introduced with f77 helped with that portability issue.

However, f77 did not define a generic way to specify literal constants.
A constant written without an exponent or with an E exponent was REAL
(e.g. 3.14 or 3.14E0), while a constant written with a D exponent was
double precision (e.g. 3.14D0).

You will see many workarounds for these limitations in legacy code. One
of the common ones, which I used when applicable, was to define
parameter constants of the appropriate type, but to specify their values
with double precision literal constants.

parameter (PI = 3.1415926535897932384626433832795028841971D0)

No matter how PI is defined, REAL or DOUBLE PRECISION, it always has the
correct value. Another common practice in legacy codes was to avoid the
REAL and DOUBLE PRECISION declarations and to use the nonstandard REAL*8
declaration instead.

REAL*8 PI

Compilers would then typically map this to either REAL or DOUBLE
PRECISION as appropriate, meaning 48-bit, 60-bit, 64-bit, or 72-bit
floating point. With these two conventions, the programmer could write
portable code that would compile unchanged and run correctly on a wide
variety of hardware and software combinations.

> With the Fortran 90 and 95 standards, it was desired to keep as much as
> possible compatible with the previous versions, so old programs would still
> work the same way they always did.

F90 kept all of these old conventions, but it introduced the new KIND
system. This is one of the nicest features of modern fortran. It allows
portable code to be written in a standard way, and it is open ended to
allow new floating point KIND values to be incorporated in the future.
For example, there are compilers that support 16-bit floating point,
80-bit floating point, and 128-bit floating point, in addition to the
traditional 32-bit REAL and 64-bit DOUBLE PRECISION KINDs. The fortran
KIND system also allows decimal floating point KINDs to be supported,
although none of the compilers I use right now are doing this.

F77 allowed intrinsic procedures to be generic, but it did not allow
programmers to write generic procedures. F90 also allowed this. This is
a nice feature when writing library code and when an application
required mixed-precision and multiple-precision floating point computations.

$.02 -Ron Shepard

Re: Real number precision in fortran

<ucinag$1q86k$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10088&group=comp.lang.fortran#10088

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: garylsc...@sbcglobal.net (Gary Scott)
Newsgroups: comp.lang.fortran
Subject: Re: Real number precision in fortran
Date: Mon, 28 Aug 2023 12:59:44 -0500
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <ucinag$1q86k$1@dont-email.me>
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com>
<3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
<3883c7bc-48d1-4910-bd1a-c55cb92c92bdn@googlegroups.com>
<cH4HM.836316$TPw2.99944@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 28 Aug 2023 17:59:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb26da11c355e7be772dde15f0a10a55";
logging-data="1908948"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tPHQFYp47E//be2wMsXxmmAT7uoG9Fs4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:K/OH3i8Xku+i+gbGRIhmze6IotA=
Content-Language: en-US
In-Reply-To: <cH4HM.836316$TPw2.99944@fx17.iad>
 by: Gary Scott - Mon, 28 Aug 2023 17:59 UTC

On 8/28/2023 12:20 PM, Ron Shepard wrote:
> On 8/28/23 8:19 AM, gah4 wrote:
>> The second version of the Fortran standard in 1977 didn't change much of
>> the way floating point was done, but did introduce a CHARACTER data type
>> for the first time.
>
> This is true regarding the floating point formats themselves, but an
> important feature of f77 was the idea of generic functions. Before f77,
> for example, the programmer was required to use SIN(X) for REAL argument
> X and DSIN(X) for double precision argument X. The same was true for all
> of the intrinsic functions ABS/DABS, SQRT/DSQRT, and so on.
>
> At that time, a REAL variable was likely to be any of 24-bits, 32-bits,
> 36-bits, 48-bits, 60-bits, or 64-bits on a given compiler, so that made
> writing portable programs, where the source code could be used
> unchanged, difficult. If your application required, say 8 decimal digits
> of precision, then on some machines you needed to use double precision
> while on other machines real was sufficient. The generic functions
> introduced with f77 helped with that portability issue.
>
> However, f77 did not define a generic way to specify literal constants.
> A constant written without an exponent or with an E exponent was REAL
> (e.g. 3.14 or 3.14E0), while a constant written with a D exponent was
> double precision (e.g. 3.14D0).
>
> You will see many workarounds for these limitations in legacy code. One
> of the common ones, which I used when applicable, was to define
> parameter constants of the appropriate type, but to specify their values
> with double precision literal constants.
>
>    parameter (PI = 3.1415926535897932384626433832795028841971D0)
>
> No matter how PI is defined, REAL or DOUBLE PRECISION, it always has the
> correct value. Another common practice in legacy codes was to avoid the
> REAL and DOUBLE PRECISION declarations and to use the nonstandard REAL*8
> declaration instead.
>
>    REAL*8 PI
>
> Compilers would then typically map this to either REAL or DOUBLE
> PRECISION as appropriate, meaning 48-bit, 60-bit, 64-bit, or 72-bit
> floating point.

or 96 bits :)

<snip>

Re: Real number precision in fortran

<d6f9c057-cb79-4d41-93b0-f0ddd830344bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10089&group=comp.lang.fortran#10089

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ad4:55cc:0:b0:641:8a6a:328e with SMTP id bt12-20020ad455cc000000b006418a6a328emr737811qvb.8.1693246796713;
Mon, 28 Aug 2023 11:19:56 -0700 (PDT)
X-Received: by 2002:a63:340d:0:b0:565:f28f:6982 with SMTP id
b13-20020a63340d000000b00565f28f6982mr5031949pga.2.1693246796446; Mon, 28 Aug
2023 11:19:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 28 Aug 2023 11:19:55 -0700 (PDT)
In-Reply-To: <uwAr_9YrL-hz5wl9KITOu2l5X1o@jntp>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:b0b9:fad2:4754:2ccc;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:b0b9:fad2:4754:2ccc
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<d24b9f27-36da-4011-963d-eba713b1f16an@googlegroups.com> <3cb57395-be28-4451-9e98-c20ed41386fbn@googlegroups.com>
<uwAr_9YrL-hz5wl9KITOu2l5X1o@jntp>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d6f9c057-cb79-4d41-93b0-f0ddd830344bn@googlegroups.com>
Subject: Re: Real number precision in fortran
From: gah...@u.washington.edu (gah4)
Injection-Date: Mon, 28 Aug 2023 18:19:56 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2189
 by: gah4 - Mon, 28 Aug 2023 18:19 UTC

On Monday, August 28, 2023 at 9:22:17 AM UTC-7, pehache wrote:

(snip)

> The default precision is the one of the REAL type, nothing more. The
> standard does not specify the actual size and precision of this type.
> Although it is nowadays mapped to the IEEE754 single precision 32 bits
> floating point by most (if not all) compilers, it was not the case in the
> past. Notably, on the CRAY machines it was mapped to the hardware native
> 64 bits floating point.
Portable programs in those days would have sets of declarations at the
top, all except the one in use commented out.

Besides those needed for the different bit widths, some considered
finer details of the floating point. For one, there is epsilon, which
depends on the significand size. Or depending on the rounding modes.

Re: Real number precision in fortran

<54381db2-bcf5-4714-b100-b7e0cfc86f1en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10100&group=comp.lang.fortran#10100

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:8a09:b0:76f:441:ec48 with SMTP id qt9-20020a05620a8a0900b0076f0441ec48mr23109qkn.8.1693375355524;
Tue, 29 Aug 2023 23:02:35 -0700 (PDT)
X-Received: by 2002:a17:902:c791:b0:1b9:df8f:888c with SMTP id
w17-20020a170902c79100b001b9df8f888cmr346498pla.8.1693375355260; Tue, 29 Aug
2023 23:02:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Tue, 29 Aug 2023 23:02:34 -0700 (PDT)
In-Reply-To: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=49.185.151.118; posting-account=L5wwzgoAAAAfQcZzW8eLJKqyFogVIeWA
NNTP-Posting-Host: 49.185.151.118
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <54381db2-bcf5-4714-b100-b7e0cfc86f1en@googlegroups.com>
Subject: Re: Real number precision in fortran
From: robi...@dodo.com.au (robin vowels)
Injection-Date: Wed, 30 Aug 2023 06:02:35 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2126
 by: robin vowels - Wed, 30 Aug 2023 06:02 UTC

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.

Re: Real number precision in fortran

<058f2111-ca5a-4e6d-92b7-af3e3337277dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10113&group=comp.lang.fortran#10113

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:90b:b0:63c:f28e:3472 with SMTP id dj11-20020a056214090b00b0063cf28e3472mr25599qvb.10.1693431797801;
Wed, 30 Aug 2023 14:43:17 -0700 (PDT)
X-Received: by 2002:a05:622a:1a83:b0:40f:e0dd:8050 with SMTP id
s3-20020a05622a1a8300b0040fe0dd8050mr25711qtc.5.1693431797602; Wed, 30 Aug
2023 14:43:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Wed, 30 Aug 2023 14:43:17 -0700 (PDT)
In-Reply-To: <54381db2-bcf5-4714-b100-b7e0cfc86f1en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=115.189.83.131; posting-account=KnYfEgoAAAD1tUJTvdAUZ3XojNa5tezZ
NNTP-Posting-Host: 115.189.83.131
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com> <54381db2-bcf5-4714-b100-b7e0cfc86f1en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <058f2111-ca5a-4e6d-92b7-af3e3337277dn@googlegroups.com>
Subject: Re: Real number precision in fortran
From: harper...@gmail.com (jfh)
Injection-Date: Wed, 30 Aug 2023 21:43:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2509
 by: jfh - Wed, 30 Aug 2023 21:43 UTC

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

Re: Real number precision in fortran

<9fc18888-bab4-44a5-8152-3c20ca33b566n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10116&group=comp.lang.fortran#10116

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ad4:4d43:0:b0:649:e869:ec71 with SMTP id m3-20020ad44d43000000b00649e869ec71mr38715qvm.1.1693450200416;
Wed, 30 Aug 2023 19:50:00 -0700 (PDT)
X-Received: by 2002:a05:6808:220c:b0:3a1:f2a4:3d7 with SMTP id
bd12-20020a056808220c00b003a1f2a403d7mr676410oib.1.1693450200263; Wed, 30 Aug
2023 19:50:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Wed, 30 Aug 2023 19:49:59 -0700 (PDT)
In-Reply-To: <058f2111-ca5a-4e6d-92b7-af3e3337277dn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=49.185.182.3; posting-account=L5wwzgoAAAAfQcZzW8eLJKqyFogVIeWA
NNTP-Posting-Host: 49.185.182.3
References: <873f9cc4-6139-4bd3-9ed8-de7e37a76730n@googlegroups.com>
<54381db2-bcf5-4714-b100-b7e0cfc86f1en@googlegroups.com> <058f2111-ca5a-4e6d-92b7-af3e3337277dn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9fc18888-bab4-44a5-8152-3c20ca33b566n@googlegroups.com>
Subject: Re: Real number precision in fortran
From: robi...@dodo.com.au (robin vowels)
Injection-Date: Thu, 31 Aug 2023 02:50:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: robin vowels - Thu, 31 Aug 2023 02:49 UTC

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.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor