Page 1 of 1

What is the difference between Floating-point and Packed Dec

Posted: Mon Jun 08, 2015 6:06 pm
by Rajat Singh
Hi,

What is the difference between Floating-point and Packed Decimal? I have read explnation about it and searched in google but more I read more I get puzzled about it. For "normal life calculation" will not theyjust behave just same? Or should there be compiler considerations too, always?

Re: What is the difference between Floating-point and Packed

Posted: Mon Jun 08, 2015 6:37 pm
by enrico-sorichetti
Floating-point and Packed Decimal?
Floating-point ... the name tells
Packed Decimal ... just a good old plain DECIMAL integer

read and meditate on the z architecture principle of operations
http://www-01.ibm.com/support/docview.w ... c500428f9a

chapters 8/9/18/19/20

Re: What is the difference between Floating-point and Packed

Posted: Mon Jun 08, 2015 10:55 pm
by Robert Sample
For "normal life calculation" will not theyjust behave just same?
This is ABSOLUTELY false. If you have a 7-digit packed decimal variable with value 9999999 and add 1 to it, what result do you get? If you have a floating point variable with the same value and add 1 to it, what do you get? Hint: they will NOT get the same result. This has nothing to do with compiler considerations and everything to do with numeric representation and precision / accuracy of results.

Re: What is the difference between Floating-point and Packed

Posted: Wed Jun 17, 2015 3:22 pm
by Rajat Singh
Thanks enrico.

Robert,

I think I'll get 0000000 in case of packed decimal but what would I get for floating point?

Re: What is the difference between Floating-point and Packed

Posted: Wed Jun 17, 2015 4:00 pm
by enrico-sorichetti
ig You are curious and have a pl/1 compiler available

just compile and run

Code: Select all

****** ***************************** Top of Data ***************************
000001  Float:
000002      Proc Options(Main);
000003      dcl pliretc builtin;
000004      dcl ( f4 ) real float binary(21)  ;
000005      dcl ( f8 ) real float binary(53)  ;
000006      dcl ( f16) real float binary(109) ;
000007      dcl ( d4 ) real float decimal(6)  ;
000008      dcl ( d8 ) real float decimal(16) ;
000009      dcl ( d16) real float decimal(33) ;
000010      f4  = 9999999 ;
000011      f8  = 9999999 ;
000012      f16 = 9999999 ;
000013      d4  = 9999999 ;
000014      d8  = 9999999 ;
000015      d16 = 9999999 ;
000016      put skip list ('Pl/1  said... Float Startd');
000017      put skip list ('f4      =', f4 ) ;
000018      put skip list ('f4 + 1  =', f4 + 1 ) ;
000019      put skip list ('f8      =', f8) ;
000020      put skip list ('f8  + 1 =', f8 + 1 ) ;
000021      put skip list ('f16     =', f16) ;
000022      put skip list ('f16 + 1 =', f16 + 1 ) ;
000023      put skip list ('d4      =', d4 ) ;
000024      put skip list ('d4 + 1  =', d4 + 1 ) ;
000025      put skip list ('d8      =', d8) ;
000026      put skip list ('d8  + 1 =', d8 + 1 ) ;
000027      put skip list ('d16     =', d16) ;
000028      put skip list ('d16 + 1 =', d16 + 1 ) ;
000029      put skip list ('Pl/1  said... Float Ended ');
000030      call pliretc(0) ;
000031      End;
****** **************************** Bottom of Data *************************
an see what is going on when using ...

Code: Select all

999999
9999999
99999999

Re: What is the difference between Floating-point and Packed

Posted: Wed Jun 17, 2015 6:08 pm
by Robert Sample
The floating point number would be 10 million, not 0 -- hence there are definite differences in floating point and packed decimal variables. A floating point value will have 7 to 8 digits of accuracy; an eye-opening experience would be to write and execute a COBOL program that uses floating point variables to multiply 30 times 29 times 28 times ... times 1 and then do the same multiplication from 1 to 30. Due to the limits of floating point variables, the values are not the same.

Re: What is the difference between Floating-point and Packed

Posted: Thu Jul 30, 2015 3:24 pm
by Rajat Singh
Thanks enrico. I don't have PL/I compiler so I could not use the example.

But I looked at this article from wiki: https://en.wikipedia.org/wiki/Floating_point and these line are helping. Though I am trying to understand how I can apply these thoughts to COBOL too:

"The term floating point refers to the fact that a number's radix point (decimal point, or, more commonly in computers, binary point) can "float"; that is, it can be placed anywhere relative to the significant digits of the number. This position is indicated as the exponent component, and thus the floating-point representation can be thought of as a kind of scientific notation."

Re: What is the difference between Floating-point and Packed

Posted: Thu Jul 30, 2015 3:28 pm
by Rajat Singh
Robert Sample wrote:The floating point number would be 10 million, not 0 -- hence there are definite differences in floating point and packed decimal variables. A floating point value will have 7 to 8 digits of accuracy; an eye-opening experience would be to write and execute a COBOL program that uses floating point variables to multiply 30 times 29 times 28 times ... times 1 and then do the same multiplication from 1 to 30. Due to the limits of floating point variables, the values are not the same.
Thanks for the hint. I shall try that. I thought to simulate it in excel too and I think it works similar there too.

Re: What is the difference between Floating-point and Packed

Posted: Thu Jul 30, 2015 5:39 pm
by Robert Sample
Yes, the same thing will happen with any computer application / language -- the issue is with the number of bits used to represent data in floating point values. Mathematically, one-third has an infinite number of digits (0.3333333....) but computers cannot store an infinite number of digits and hence the values used in a computer are approximations of the mathematical value. Do enough multiplications and you're going to exceed the number of bits used eventually, at which time the results start diverging from the mathematical value.

Re: What is the difference between Floating-point and Packed

Posted: Tue Aug 04, 2015 12:12 pm
by Rajat Singh
Thank you all. :)