What is the difference between Floating-point and Packed Dec
-
- Registered Member
- Posts: 12
- Joined: Tue Dec 02, 2014 9:46 am
What is the difference between Floating-point and Packed Dec
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?
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?
-
- Global Moderator
- Posts: 827
- Joined: Wed Sep 11, 2013 3:57 pm
Re: What is the difference between Floating-point and Packed
Floating-point ... the name tellsFloating-point and Packed Decimal?
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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What is the difference between Floating-point and Packed
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.For "normal life calculation" will not theyjust behave just same?
-
- Registered Member
- Posts: 12
- Joined: Tue Dec 02, 2014 9:46 am
Re: What is the difference between Floating-point and Packed
Thanks enrico.
Robert,
I think I'll get 0000000 in case of packed decimal but what would I get for floating point?
Robert,
I think I'll get 0000000 in case of packed decimal but what would I get for floating point?
-
- Global Moderator
- Posts: 827
- Joined: Wed Sep 11, 2013 3:57 pm
Re: What is the difference between Floating-point and Packed
ig You are curious and have a pl/1 compiler available
just compile and run
an see what is going on when using ...
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 *************************
Code: Select all
999999
9999999
99999999
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What is the difference between Floating-point and Packed
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.
-
- Registered Member
- Posts: 12
- Joined: Tue Dec 02, 2014 9:46 am
Re: What is the difference between Floating-point and Packed
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."
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."
-
- Registered Member
- Posts: 12
- Joined: Tue Dec 02, 2014 9:46 am
Re: What is the difference between Floating-point and Packed
Thanks for the hint. I shall try that. I thought to simulate it in excel too and I think it works similar there too.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.
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What is the difference between Floating-point and Packed
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.
-
- Registered Member
- Posts: 12
- Joined: Tue Dec 02, 2014 9:46 am
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute