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.
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))
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))
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,027 |
Nodes: | 10 (1 / 9) |
Uptime: | 28:49:46 |
Calls: | 13,319 |
Calls today: | 2 |
Files: | 186,574 |
D/L today: |
266 files (76,510K bytes) |
Messages: | 3,352,879 |
Posted today: | 1 |