• Redefining a V as two integers?

    From Bruce Axtens@21:1/5 to All on Fri Jan 13 23:11:03 2023
    Suppose I have

    01 FLOATING-NUMBER PIC 9(16)V9(16).

    Is it possible to redefine it as two numbers holding the left and right of decimal point values?

    01 SINKING-NUMBER REDEFINES FLOATING-NUMBER.
    03 LEFT-OF-DECIMAL PIC 9(16).
    03 RIGHT-OF-DECIMAL PIC 9(16).

    for example.

    -- Bruce

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Axtens@21:1/5 to All on Fri Jan 13 23:18:13 2023
    To answer myself, "Yes, but"

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 FLOATER PIC 9(8)V9(8).
    01 SINKER REDEFINES FLOATER.
    03 LEFTOF PIC 9(8).
    03 RIGHTOF PIC 9(8).
    PROCEDURE DIVISION.
    INITIALIZE SINKER.
    MOVE 123.456789 TO FLOATER.
    DISPLAY LEFTOF.
    DISPLAY RIGHTOF.
    STOP RUN.

    00000123
    45678900

    Is there a better way?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rick Smith@21:1/5 to bruce....@gmail.com on Sat Jan 14 05:38:22 2023
    On Saturday, January 14, 2023 at 2:18:14 AM UTC-5, bruce....@gmail.com wrote:
    To answer myself, "Yes, but"

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 FLOATER PIC 9(8)V9(8).
    01 SINKER REDEFINES FLOATER.
    03 LEFTOF PIC 9(8).
    03 RIGHTOF PIC 9(8).
    PROCEDURE DIVISION.
    INITIALIZE SINKER.
    MOVE 123.456789 TO FLOATER.
    DISPLAY LEFTOF.
    DISPLAY RIGHTOF.
    STOP RUN.

    00000123
    45678900

    Is there a better way?

    What you have done to separate the digits is implicit.
    Clarity requires something explicit.

    If clarity is better, then reference modification or UNSTRING
    would by more clear.

    MOVE FLOATER (1:8) TO LEFTOF
    MOVE FLOATER (9:8) TO RIGHTOF

    or

    UNSTRING FLOATER INTO RIGHTOF LEFTOF

    But, do you only want the digits or the value? To preserve
    the value, a "V" should be inserted in RIGHTOF as in
    V9(8). In which case, a MOVE statement would make
    it clear.

    MOVE FLOATER TO LEFTOF RIGHTOF

    Which uses truncation to separate the number while
    preserving the values of the parts.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Axtens@21:1/5 to Rick Smith on Sun Jan 15 03:37:46 2023
    On Saturday, 14 January 2023 at 9:38:23 pm UTC+8, Rick Smith wrote:
    ...
    I'm still thinking about the UNSTRING but in the interim I found INTEGER-PART and FRACTION-PART.

    Clearly, I'm doing something wrong here.

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 FLOATER PIC 9(8)V9(8).
    01 LEFTOF PIC 9(8).
    01 RIGHTOF PIC 9(8).
    PROCEDURE DIVISION.
    MOVE 123.456789 TO FLOATER.
    MOVE FUNCTION INTEGER-PART(FLOATER) TO LEFTOF.
    MOVE FUNCTION FRACTION-PART(FLOATER) TO RIGHTOF.
    DISPLAY LEFTOF " . " RIGHTOF.
    STOP RUN.



    00000123 . 00000000

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rick Smith@21:1/5 to bruce....@gmail.com on Sun Jan 15 05:01:51 2023
    On Sunday, January 15, 2023 at 6:37:48 AM UTC-5, bruce....@gmail.com wrote:
    On Saturday, 14 January 2023 at 9:38:23 pm UTC+8, Rick Smith wrote:
    ...
    I'm still thinking about the UNSTRING but in the interim I found INTEGER-PART and FRACTION-PART.

    Clearly, I'm doing something wrong here.
    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 FLOATER PIC 9(8)V9(8).
    01 LEFTOF PIC 9(8).
    01 RIGHTOF PIC 9(8).
    PROCEDURE DIVISION.
    MOVE 123.456789 TO FLOATER.
    MOVE FUNCTION INTEGER-PART(FLOATER) TO LEFTOF.
    MOVE FUNCTION FRACTION-PART(FLOATER) TO RIGHTOF.
    DISPLAY LEFTOF " . " RIGHTOF.
    STOP RUN.



    00000123 . 00000000

    FRACTION-PART preserves the value, you need
    01 RIGHTOF PIC V9(8). *> Note the "V" in the picture

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vincent Coen@21:1/5 to Bruce Axtens on Sun Jan 15 15:55:00 2023
    Hello Bruce!

    Sunday January 15 2023 11:37, Bruce Axtens wrote to All:

    On Saturday, 14 January 2023 at 9:38:23 pm UTC+8, Rick Smith wrote:
    ...
    I'm still thinking about the UNSTRING but in the interim I found INTEGER-PART and FRACTION-PART.

    Clearly, I'm doing something wrong here.

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 FLOATER PIC 9(8)V9(8).
    01 LEFTOF PIC 9(8).
    01 RIGHTOF PIC 9(8).
    PROCEDURE DIVISION.
    MOVE 123.456789 TO FLOATER.
    MOVE FUNCTION INTEGER-PART(FLOATER) TO LEFTOF.
    MOVE FUNCTION FRACTION-PART(FLOATER) TO RIGHTOF.
    DISPLAY LEFTOF " . " RIGHTOF.
    STOP RUN.



    00000123 . 00000000


    I added a display after the move 123 etc as display "original = " floater.

    Changed to 01 RIGHTOF PIC v9(8). Note added 'v'.
    so the code now looks like :
    >>source free
    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 FLOATER PIC 9(8)V9(8).
    01 LEFTOF PIC 9(8).
    01 RIGHTOF PIC v9(8).
    PROCEDURE DIVISION.
    MOVE 123.456789 TO FLOATER.
    display "original = " floater.
    MOVE FUNCTION INTEGER-PART(FLOATER) TO LEFTOF.
    MOVE FUNCTION FRACTION-PART(FLOATER) TO RIGHTOF.
    DISPLAY LEFTOF " . " RIGHTOF.
    STOP RUN.

    cobc -xj test1.cbl
    original = 00000123.45678900
    00000123 . 00000000

    Used :
    cobc (GnuCOBOL) 3.2-dev.0
    Copyright (C) 2022 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    Built Dec 16 2022 21:51:57
    Packaged Dec 16 2022 21:51:10 UTC
    C version "10.4.0"
    On Linux Mageia v8 X64.

    Vincent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to bruce.axtens@gmail.com on Sun Jan 15 15:58:15 2023
    In article <f8eb7b04-7406-462c-919c-ff52e42805c2n@googlegroups.com>,
    Bruce Axtens <bruce.axtens@gmail.com> wrote:
    To answer myself, "Yes, but"

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 FLOATER PIC 9(8)V9(8).
    01 SINKER REDEFINES FLOATER.
    03 LEFTOF PIC 9(8).
    03 RIGHTOF PIC 9(8).
    PROCEDURE DIVISION.
    INITIALIZE SINKER.
    MOVE 123.456789 TO FLOATER.
    DISPLAY LEFTOF.
    DISPLAY RIGHTOF.
    STOP RUN.

    00000123
    45678900

    Is there a better way?

    This thread has been running for a few days but I'm taking it 'back to the
    top' for a simple reason.

    Given the responses to the answers I'm uncertain as to the nature of the question. Please be so kind as to complete the following question:

    'I have an implied-decimal numeric field defined as PIC S9(8)V9(8). What
    is the best way to...?'

    'Better' on a computational platform can be many things: most efficient in speed, uses less disk/core, easiest for a 2-year programmer to maintain
    during a 3:AM kerflooie... each of these might supply a different answer.

    What'cha lookin'a do?

    (oh... and as a matter of aesthetics you might want to change that
    HELLO-WORLD to SKELPROG)

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vincent Coen@21:1/5 to Bruce Axtens on Sun Jan 15 16:16:08 2023
    Hello Bruce!

    Sunday January 15 2023 11:37, Bruce Axtens wrote to All:

    On Saturday, 14 January 2023 at 9:38:23 pm UTC+8, Rick Smith wrote:
    ...
    I'm still thinking about the UNSTRING but in the interim I found INTEGER-PART and FRACTION-PART.

    Clearly, I'm doing something wrong here.

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 FLOATER PIC 9(8)V9(8).
    01 LEFTOF PIC 9(8).
    01 RIGHTOF PIC 9(8).
    PROCEDURE DIVISION.
    MOVE 123.456789 TO FLOATER.
    MOVE FUNCTION INTEGER-PART(FLOATER) TO LEFTOF.
    MOVE FUNCTION FRACTION-PART(FLOATER) TO RIGHTOF.
    DISPLAY LEFTOF " . " RIGHTOF.
    STOP RUN.



    00000123 . 00000000


    GnuCobol Programmers Reference and Guide has been updated accordingly.


    Vincent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Axtens@21:1/5 to docd...@panix.com on Sun Jan 15 22:00:34 2023
    On Sunday, 15 January 2023 at 11:58:17 pm UTC+8, docd...@panix.com wrote:
    In article <f8eb7b04-7406-462c...@googlegroups.com>,
    Bruce Axtens <bruce....@gmail.com> wrote:

    What'cha lookin'a do?

    I wanted to split a floating point number into two integers being the left of decimal point and the right of decimal point. Even as I typed that I started to wonder: if 123.456 gets split into 123 and 456, what does the 456 actually represent? It
    certainly doesn't represent four hundred and fifty six.

    -- Bruce

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Axtens@21:1/5 to Vincent Coen on Sun Jan 15 22:01:25 2023
    On Monday, 16 January 2023 at 12:16:59 am UTC+8, Vincent Coen wrote:
    Hello Bruce!
    GnuCobol Programmers Reference and Guide has been updated accordingly. > Vincent

    Glad to be of assistance ... I think ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to bruce.axtens@gmail.com on Mon Jan 16 22:52:11 2023
    In article <0226710a-e195-4e5c-8830-d87e9f0f3f95n@googlegroups.com>,
    Bruce Axtens <bruce.axtens@gmail.com> wrote:
    On Sunday, 15 January 2023 at 11:58:17 pm UTC+8, docd...@panix.com wrote:
    In article <f8eb7b04-7406-462c...@googlegroups.com>,
    Bruce Axtens <bruce....@gmail.com> wrote:

    What'cha lookin'a do?

    I wanted to split a floating point number into two integers being the
    left of decimal point and the right of decimal point. Even as I typed
    that I started to wonder: if 123.456 gets split into 123 and 456, what
    does the 456 actually represent? It certainly doesn't represent four
    hundred and fifty six.

    My studies in arithmetics are ancient and of small quantity, Mr Axtens,
    but I think you've hit this nail squarely head-on: 123.456 is a number (in
    the sense of 'an enumerated quantity') while 'floating point' is a representation of a number. Attempting to euqate a thing with the way it
    is represented can lead to attractive confusions.

    Rene Magritte came up with 'The Treachery of Images' in 1929. Maybe it's
    time to revisit and ponder.

    https://en.wikipedia.org/wiki/The_Treachery_of_Images#/media/File:MagrittePipe.jpg

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)