Topic
  • 4 replies
  • Latest Post - ‏2013-05-29T05:47:53Z by markboonie
markboonie
markboonie
9 Posts

Pinned topic Data type conversion rules

‏2013-05-17T21:03:59Z |

Where are the rules defined for converting between types of data?  I used PUT EDIT to display the contents of two variables declared as FIXED DEC(10. 2) and FIXED DEC(7,3), but I had them output as Binary values.  The first value was printed as 27 bits, and the second one as 14 bits.  The binary values are correct (after truncation of the fractional portion of the value), but I have no idea why the lengths are 27 and 14.  Thanks.

- mb

  • markboonie
    markboonie
    9 Posts
    ACCEPTED ANSWER

    Re: Data type conversion rules

    ‏2013-05-29T05:46:06Z  
    • pelderon
    • ‏2013-05-24T23:45:53Z

    These rules are described in the LRM, but they sometimes can be complicated.

    If you could show the PUT EDIT statements you were using, I could explain how you got the results you saw

    Curious -- I just got notification of this post two hours ago.

    I was using:

    Dcl TempDec102 Dec (10,2);
    Dcl TempDec73  Dec (7,3);
    ...
    Put Skip Edit (TempDec102) (B);
    Put Skip Edit (TempDec73 ) (B);

    A co-worker pointed out the following:

     The documented conversion rules for PL/I in the language reference section "Converting other data attributes" use a factor of 3.32 binary digits per decimal digit, rounded up to the next digit.  The first case has 8 decimal digits before the point, giving 8*3.32 = 26.56 which rounds up to 27.  The second case has 4 decimal digits, giving 13.28 which rounds up to 14.

    That explains the behavior.  I had assumed that the compiler would do something like assign the value to a BIN(31) and display the entire 31 bits, or something like that.  My apologies for not following up by posting the answer.

    - mb

     
  • pelderon
    pelderon
    11 Posts

    Re: Data type conversion rules

    ‏2013-05-24T23:45:53Z  

    These rules are described in the LRM, but they sometimes can be complicated.

    If you could show the PUT EDIT statements you were using, I could explain how you got the results you saw

  • Robin400
    Robin400
    33 Posts

    Re: Data type conversion rules

    ‏2013-05-27T01:04:35Z  

    What format did you use?

  • markboonie
    markboonie
    9 Posts

    Re: Data type conversion rules

    ‏2013-05-29T05:46:06Z  
    • pelderon
    • ‏2013-05-24T23:45:53Z

    These rules are described in the LRM, but they sometimes can be complicated.

    If you could show the PUT EDIT statements you were using, I could explain how you got the results you saw

    Curious -- I just got notification of this post two hours ago.

    I was using:

    Dcl TempDec102 Dec (10,2);
    Dcl TempDec73  Dec (7,3);
    ...
    Put Skip Edit (TempDec102) (B);
    Put Skip Edit (TempDec73 ) (B);

    A co-worker pointed out the following:

     The documented conversion rules for PL/I in the language reference section "Converting other data attributes" use a factor of 3.32 binary digits per decimal digit, rounded up to the next digit.  The first case has 8 decimal digits before the point, giving 8*3.32 = 26.56 which rounds up to 27.  The second case has 4 decimal digits, giving 13.28 which rounds up to 14.

    That explains the behavior.  I had assumed that the compiler would do something like assign the value to a BIN(31) and display the entire 31 bits, or something like that.  My apologies for not following up by posting the answer.

    - mb

     
  • markboonie
    markboonie
    9 Posts

    Re: Data type conversion rules

    ‏2013-05-29T05:47:53Z  
    • Robin400
    • ‏2013-05-27T01:04:35Z

    What format did you use?

    As indicated in my response to the previous append, my notifications seem to be delayed -- notification for this one arrived only 15 minutes ago.

    See my response to the previous append -- thanks!

    - mb