Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Those who do not understand Unix are condemned to reinvent it, poorly. -- Henry Spencer


devel / comp.lang.fortran / Re: what is point of X=1.0D0*X+1.0D0*Y*W ?

SubjectAuthor
* what is point of X=1.0D0*X+1.0D0*Y*W ?Woozy Song
`* Re: what is point of X=1.0D0*X+1.0D0*Y*W ?Steve Lionel
 +- Re: what is point of X=1.0D0*X+1.0D0*Y*W ?Robinn
 `- Re: what is point of X=1.0D0*X+1.0D0*Y*W ?gah4

1
what is point of X=1.0D0*X+1.0D0*Y*W ?

<ujn9ie$1q6mi$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: suzyw0ng@outlook.com (Woozy Song)
Newsgroups: comp.lang.fortran
Subject: what is point of X=1.0D0*X+1.0D0*Y*W ?
Date: Thu, 23 Nov 2023 18:29:30 +0800
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <ujn9ie$1q6mi$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Nov 2023 10:29:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="991c01002f7c3bc1339b8841338ace12";
logging-data="1907410"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182OKndwz+xjWmprQCqfoO11Z1ynqStj0s="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17.1
Cancel-Lock: sha1:uheV0tt3dCeQn8/EeF86d/+F5D0=
X-Mozilla-News-Host: news://news.eternal-september.org:119
 by: Woozy Song - Thu, 23 Nov 2023 10:29 UTC

Where X and Y are both real, and W is double precision. I presume they
wanted extra precision for the arithmetic, but then it gets quantised
back to 32-bit float.
By the way, this code came from a large oil company with a team of
programmers.

Re: what is point of X=1.0D0*X+1.0D0*Y*W ?

<ks99d8F7kg6U1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!paganini.bofh.team!2.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: steve@seesignature.invalid (Steve Lionel)
Newsgroups: comp.lang.fortran
Subject: Re: what is point of X=1.0D0*X+1.0D0*Y*W ?
Date: Thu, 23 Nov 2023 10:28:40 -0500
Lines: 30
Message-ID: <ks99d8F7kg6U1@mid.individual.net>
References: <ujn9ie$1q6mi$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net fbdx65FLfjF3xvNNm1UOQAZD9xqik1lWDKuBj4Komm2QNKzkja
Cancel-Lock: sha1:ZVKLyVKKRHwE0L8goOqOuy95HcM= sha256:lit2Ma1Pa4KzyqBgpLmMcgVXCJPjF13NIfYZEch/LjE=
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <ujn9ie$1q6mi$1@dont-email.me>
 by: Steve Lionel - Thu, 23 Nov 2023 15:28 UTC

On 11/23/2023 5:29 AM, Woozy Song wrote:
> Where X and Y are both real, and W is double precision. I presume they
> wanted extra precision for the arithmetic, but then it gets quantised
> back to 32-bit float.
> By the way, this code came from a large oil company with a team of
> programmers.

The multiplication by 1.0D0 of each term has no effect whatsoever. If
those were removed, the multiplication of Y*W would convert Y to double,
due to "mixed-mode arithmetic" rules, before doing the operation. Then
when X is added, it too would be converted to double before the
addition. Then the whole result would be rounded back to single
precision for the assignment.

If I were writing this, I'd use the standard conversion intrinsic
functions to make it clear what is happening, as I hate seeing implicit
conversion. For example:

X = REAL(DBLE(X)+(DBLE(Y)*W))

--
Steve Lionel
ISO/IEC JTC1/SC22/WG5 (Fortran) Convenor
Retired Intel Fortran developer/support
Email: firstname at firstnamelastname dot com
Twitter: @DoctorFortran
LinkedIn: https://www.linkedin.com/in/stevelionel
Blog: https://stevelionel.com/drfortran
WG5: https://wg5-fortran.org

Re: what is point of X=1.0D0*X+1.0D0*Y*W ?

<6563d165$0$708$14726298@news.sunsite.dk>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Subject: Re: what is point of X=1.0D0*X+1.0D0*Y*W ?
Newsgroups: comp.lang.fortran
References: <ujn9ie$1q6mi$1@dont-email.me> <ks99d8F7kg6U1@mid.individual.net>
From: 32s116e@gmail.invalid (Robinn)
Date: Mon, 27 Nov 2023 07:14:33 +0800
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17.1
MIME-Version: 1.0
In-Reply-To: <ks99d8F7kg6U1@mid.individual.net>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 26
Message-ID: <6563d165$0$708$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: 5f737f03.news.sunsite.dk
X-Trace: 1701040486 news.sunsite.dk 708 116e32s@gmail.com/49.192.213.112:42010
X-Complaints-To: staff@sunsite.dk
 by: Robinn - Sun, 26 Nov 2023 23:14 UTC

Steve Lionel wrote:
> On 11/23/2023 5:29 AM, Woozy Song wrote:
>> Where X and Y are both real, and W is double precision. I presume they
>> wanted extra precision for the arithmetic, but then it gets quantised
>> back to 32-bit float.
>> By the way, this code came from a large oil company with a team of
>> programmers.
>
> The multiplication by 1.0D0 of each term has no effect whatsoever. If
> those were removed, the multiplication of Y*W would convert Y to double,
> due to "mixed-mode arithmetic" rules, before doing the operation. Then
> when X is added, it too would be converted to double before the
> addition. Then the whole result would be rounded back to single
> precision for the assignment.
>
> If I were writing this, I'd use the standard conversion intrinsic
> functions to make it clear what is happening, as I hate seeing implicit
> conversion. For example:
>
> X = REAL(DBLE(X)+(DBLE(Y)*W))
>

Yeah, I have been doing that recently. Compiled a package with -Wall,
and there were shit-tons of implicit conversions. Rather disturbing, as
default behaviour for real to integer is INT(), when in a few cases it
seemed NINT() would the correct behaviour.

Re: what is point of X=1.0D0*X+1.0D0*Y*W ?

<uk1tsh$3o5fq$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gah@ugcs.caltech.edu (gah4)
Newsgroups: comp.lang.fortran
Subject: Re: what is point of X=1.0D0*X+1.0D0*Y*W ?
Date: Mon, 27 Nov 2023 03:17:34 -0800
Organization: UW
Lines: 49
Message-ID: <uk1tsh$3o5fq$1@dont-email.me>
References: <ujn9ie$1q6mi$1@dont-email.me> <ks99d8F7kg6U1@mid.individual.net>
Reply-To: gah4@u.washington.edu
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 27 Nov 2023 11:17:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="32d341b322e3fde3f5423c8dbb5367d8";
logging-data="3937786"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+k140YHey2LZUksSQXYBpG"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:DxVFnntfJPC9i1ckMMfI9unWvy8=
Content-Language: en-US
In-Reply-To: <ks99d8F7kg6U1@mid.individual.net>
 by: gah4 - Mon, 27 Nov 2023 11:17 UTC

On 11/23/23 7:28 AM, Steve Lionel wrote:
> On 11/23/2023 5:29 AM, Woozy Song wrote:
>> Where X and Y are both real, and W is double precision. I presume they
>> wanted extra precision for the arithmetic, but then it gets quantised
>> back to 32-bit float.
>> By the way, this code came from a large oil company with a team of
>> programmers.

> The multiplication by 1.0D0 of each term has no effect whatsoever. If
> those were removed, the multiplication of Y*W would convert Y to double,
> due to "mixed-mode arithmetic" rules, before doing the operation. Then
> when X is added, it too would be converted to double before the
> addition. Then the whole result would be rounded back to single
> precision for the assignment.

> If I were writing this, I'd use the standard conversion intrinsic
> functions to make it clear what is happening, as I hate seeing implicit
> conversion. For example:

> X = REAL(DBLE(X)+(DBLE(Y)*W))

In the Fortran 66 days, there was worry that constants would
be converted at run-time, if needed.

We were told to use 1.0 instead of 1 in REAL expressions.

As well as I know, compilers did compile time conversions long
before this recommendation went away. Though often enough, I still
write 1.0, as it makes it more obvious that the expression is REAL.

As for conversions, Java requires a cast for narrowing conversions.

Widening conversions in the order:

byte --> {short, char} --> int --> long --> float --> double

don't require a cast, but the other way, narrowing, do.

Note that this is true, even though significant bits might be lost
in the int --> float and long --> double cases.

The unsigned 16 bit char, and signed 16 bit short, require a
cast in both directions.

As to the original question, often double precision is needed
in intermediate values, even when the final result is single precision.

But also, it is possible that the type declarations changed over the
years, but not the line in question.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor