Thread View: comp.lang.fortran
2 messages
2 total messages
Started by robin
Sat, 27 Sep 2003 14:18
Re: Precision of floating point multiply
Author: robin
Date: Sat, 27 Sep 2003 14:18
Date: Sat, 27 Sep 2003 14:18
67 lines
4394 bytes
4394 bytes
"Glen Herrmannsfeldt" <gah@ugcs.caltech.edu> writes: > An article by W. Kahan titled "How Java's Floating-Point Hurts Everyone > Everywhere" (and which describes much more than Java) includes a discussion > about the results of floating point multiply. > > > According to his description, until 1963 IBM Fortran compilers would > generate double precision results for floating point multiply of two single > precision numbers, at least when it was being summed into a double precision > variable. He then explains that IBM changed this in IBSYS 13, anticipating > S/360. > > As far as I can tell, the Fortran-66 standard requires a single precision > product when multiplying single precision numbers, though I don't know how > much impact IBM had on Fortran-66. > > The reason why this comment is surprising to me is that S/360 (along with > S/370 and ESA/390) do not have a single precision multipy instruction with a > single precision product. The product is always double precision. While this is true, it is also true that subsequent single-precision operations using the result will use only the single-precision product. Furthermore, storing the result into a single-precision variable will store only the single-precision product. To store a double-precision product, an STE will do, followed by a MVC STE+4(4),=F'0', or SDR 0,0 LER 0,4 STD 0, result The sequence SDR 0,0 LE 0,4 will convert the DP FPR 4 to single prec. for subsequent use with DP operands. > I have > checked the code generated by both the G and H compilers, and both, after > generating the multiply instruction generate at least two more instructions > to truncate the product to single precision. > > It, then, seems unlikely to me that the change was made to accomodate S/360, > when the S/360 hardware had exactly the opposite effect. I don't know what > the status of Fortran-66 was in 1963, though, and what influence that may > have had. > > As far as I know, Fortran still requires floating point multiply to generate > a result with no more precision than the arguments that went into it. The intrinsic DPROD will generate a DP product from SP arguments. > W.Kahan describes well the advantage of summing a double precision product > of single precision arguments, yet the Fortran standard doesn't seem to > follow it. (Someone with a more recent standard can comment on this.) > > PL/I has the MULTIPLY function where one can specify the desired result > precision. At least one compiler I know of expands both operands before > doing a double precision multiply when double precision is desired. > > If someone wanted to comment about other hardware or compilers in use in the > 1960's and 1970's, that might also be useful. > > I would, in the end, like to thank W.Kahan for his unceasing drive to > improve the results of floating point hardware and software, and hope for > only constructive discussion of this problem. > > -- glen
Re: Precision of floating point multiply
Author: Sven Pran
Date: Sat, 27 Sep 2003 16:54
Date: Sat, 27 Sep 2003 16:54
57 lines
3585 bytes
3585 bytes
"robin" wrote > "Glen Herrmannsfeldt" writes: > > According to his description, until 1963 IBM Fortran compilers would > > generate double precision results for floating point multiply of two single > > precision numbers, at least when it was being summed into a double precision > > variable. He then explains that IBM changed this in IBSYS 13, anticipating > > S/360. > > > > As far as I can tell, the Fortran-66 standard requires a single precision > > product when multiplying single precision numbers, though I don't know how > > much impact IBM had on Fortran-66. > > > > The reason why this comment is surprising to me is that S/360 (along with > > S/370 and ESA/390) do not have a single precision multipy instruction with a > > single precision product. The product is always double precision. > > While this is true, it is also true that subsequent single-precision > operations using the result will use only the single-precision > product. With the Fortran language as implemented on IBM computers in the 360 series you specified all variables either implicit or explicit. Variables having names beginning with one of the characters "I" through "N" were INtegers by default, the rest were single precision real numbers by default. How the multiplication was performed internally mattered very little for code something like A = B * C. According to the specifications for the Fortran compiler all real number calculations were carried out at maximum precision for intermediate results; rounding to the specific precision took place only when a result was stored in the target variable. Therefore the result for: Y = some second calculation on (the result of some first calculation on (A,B,C) ) could very well be different from the result for: Y := some first calculation on: (A, B, C) followed by Y = some second calculation on (Y) because also the intermediate result was rounded in the second case, not in the first. Sven
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads