Re: Decimal arithmetic

2012-07-15 Thread Don Higgins
For those interested in seeing what a COBOL program with support for decimal 
floating point (DFP) and packed decimal (PD) can do, you can try out zcobol 
compiler which is free open source component included with z390 portable 
mainframe assembler.  The z390 and zcobol free open source tools can be 
downloaded via www.z390.org and installed and run on any Windows, Linux, or 
Apple OSX PC.  The only pre-requisite is a version of J2SE java 1.6+ which can 
be downloaded for free from www.oracle.com.

The zcobol compiler supports 15 numberic data types including HFP, BFP, and DFP 
floating point and packed decimal.  The compiler generates HLASM compatible 
mainframe source assembler with data field labels and paragraph label for 
readability.  The HLASM source can then be assembled, linked, and executed 
using z390 emulator on PC or the source can be ported to mainframe.  There is a 
paper with example described here:

 http://www.z390.org/zcobol/demo/callcomp/zCOBOL_COMPUTE.pdf 

The example is available in machine readable form including COBOL source and 
all generated files and listings:

http://www.z390.org/zcobol/demo/callcomp/CALLCOMP.ZIP 

Don Higgins
d...@higgins.net

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Decimal arithmetic

2012-07-14 Thread glen herrmannsfeldt
(someone wrote)
 Some years ago this situation changed dramatically.  Mike
 Cowlishaw---he who designed REXX---devised what is now ANSI decimal
 floating point  (DFP).  DFP behaves consistently in ways that do not
 surprise accountants.  (All three floating-point formats are supported
 by zArchitecture hardware.)

According to D.E.Knuth, there are two things that should not be
done in floating point: financial calculations and typesetting.

Floating point is great for quantities with a relative error.
That is, where the uncertainty in measurement scales with the value.
One can measure lengths in nanometers or gigameters to about
one part in 100 million or so at best(*)

For quantities where the uncertainty does not depend on the 
magnitude, fixed point is a better choice. I expect my bank to
keep my balance to the cent, when I have either $1.00 or 
(rarely) $1,000,000.00 in my account.

Digital typesetting needs to be able to position glyphs on the
page consistently. The eye is amazingly sensitive to some types
of positioning errors. Knuth has an example of a typesetting
machine that was thought to have 5333 dot/inch resolution, but
turned out to be 5333 and a third dpi. The difference was visible
in printed output. TeX and Metafont use only fixed point arithmetic
for any calculation that affects the printed page. Some messages
to the user use floating point arithmetic.
 
 Although there has been ample tIme to do so, IBM COBOL does not yet
 support DFP.  It should.   When IBM COBOL does support DFP, it will be
 possible to eliminate packed-decimal (except as a transitional data
 type in certain conversion operations) from COBOL routines; and doing
 so will confer large performance advantages.

I suppose if one is careful in how it is used. Still, the 15 
decimal digits from S/360 packed decimal should be enough for
most uses. (31 digits for add/subtract.) 

--

(*)

(The lattice constant for crystalline Silicon is
 543.102 0504 x 10^-12 m with a relative error of 1.6 
in 100,000,000.)

The radius of the earth is about 6371km. Because the earth isn't
a perfect sphere it is hard to give it much more accurately, though
one could measure the distance between two points on the earth
more accurately. The semi-major axis of the earth's orbit 
is 149598261km, so again to about one part in 100,000,000.

The period of the earth's orbit is 365.256363004 days, or known
to about 1 part in ten to the 11th. Optical spectra lines can
also be measured to a similar relative uncertainty.

-- glen

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN