Anonymous user
Generalised floating point addition: Difference between revisions
Generalised floating point addition (view source)
Revision as of 17:27, 22 December 2020
, 3 years ago→base ten only: separated the boxed comments to the REXX section header, added/changed whitespace and comments.
(Added Wren) |
m (→base ten only: separated the boxed comments to the REXX section header, added/changed whitespace and comments.) |
||
Line 976:
=={{header|REXX}}==
===base ten only===
<lang rexx>/*REXX pgm to perform generalized floating point addition using BCD nums*/▼
┌─┘ This REXX program uses an uncompressed (or zoned) BCD which └─┐▼
▲/*┌────────────────────────────────────────────────────────────────────┐
│ consumes one byte for each represented digit. A leading sign (+ or -) │▼
▲┌─┘ This REXX program uses an uncompressed (or zoned) BCD which └─┐
│ is optional. An exponent is also allowed which is preceded by a ^. │▼
▲│ consumes one byte for each represented digit. A leading sign (+ or -) │
│ The value of the exponent may have a leading sign (+ or -). │
▲│ is optional. An exponent is also allowed which is preceded by a ^. │
│ as the signs and exponent indicator. There is essentially no limit on │▼
│ the number of digits in the mantissa or the exponent, but the value of │
▲│ as the signs and exponent indicator. There is essentially no limit on │
│
│ and then a number is added to that sum, and the resultant sum should │
│
└─┐ The number of digits for the precision is automatically adjusted. ┌─┘▼
▲│ │
▲└─┐ The number of digits for the precision is automatically adjusted. ┌─┘
▲<lang rexx>/*REXX
▲ └────────────────────────────────────────────────────────────────────┘*/
maxW= linesize() - 1 /*
/*Not all REXXes have the LINESIZE
_123= 012345679; reps= 0; mult= 63 /*vars used to construct test cases. */
say ' # addend uncompressed (zoned) BCD number' /*display the header
say left('── ────── ─', maxW, '─') /*
do j=-7 to 21 /*traipse through the test cases. */
reps= reps + 1 /*increase number of repetitions. */
BCD.j= strip(copies(_123, reps)'^'mult,'L',0)
if j//3==0 then BCD.J= '+'BCD.j /*add a leading
parse var BCD.j '^' pow /*get the exponent part of the
addend.j= '1e'pow /*build
_=right(j, 2) right(addend.j, 6) /*construct the prefix for a line. */
aLine= _ BCD.j /*construct a line
if length(aLine)<maxW then say aLine /*
else say _ ' ['length(BCD.j)
mult= mult - 9 /*decrease the multiplier's exponent. */
maxDigs= length(BCD.j) + abs(pow) + 5 /*compute
if maxDigs>digits() then numeric digits maxDigs /*
end /*j*/
say copies('═', maxW) /*display a fence for separation. */
times= 81 /*the number of times to add it. */
do k=-7 to 21 /*traipse through the test cases. */
parse var BCD.k mantissa '^' exponent /*decompose the zoned BCD
x= mantissa'e'exponent /*reconstitute the original
sum= 0 /*prepare for the 81 additions. */
do times
sum= sum + x /*multiplying the hard way,
end
sum= (sum + addend.k) / 1 /*
_= format(sum, , , , 0) /*force sum
say right(k,3) 'sum=' translate(_, "e", 'E')
end /*k*/
▲exit /*stick a fork in it, we're done.*/</lang>
This REXX program makes use of '''LINESIZE''' REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console).
<br>The '''LINESIZE.REX''' REXX program is included here
<pre>
# addend uncompressed (zoned) BCD number
|