gnucobol-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [open-cobol-list] displaying max values in comp-5 field


From: Gary Cutler
Subject: Re: [open-cobol-list] displaying max values in comp-5 field
Date: Tue, 28 Jul 2009 06:55:11 -0400

Have you checked out the compiler's "-fnotrunc" option?  My testing has
shown that when you compile with this option (which turns off binary field
truncation), not only does truncation stop but arithmetic operations against
all numeric USAGEs (including DISPLAY) runs MUCH faster.

Try this test program, compiled with and without "-fnotrunc":

       IDENTIFICATION DIVISION.
       PROGRAM-ID. mathtest.
      *****************************************************************
      ** This compares the performance of performing arithmetic op-  **
      ** Erations against USAGE DISPLAY, COMP and COMP-5 numeric     **
      ** data.                                                       **
      **                                                             **
      ** Each data item will have 7 added to it ten million times.   **
      ** The time (to one-one-hundtredth of a second will be         **
      ** retrieved before and after each test and the difference     **
      ** between the two will be DISPLAYed.                          **
      **                                                             **
      ** Compile (and execute) this program twice - once with binary **
      ** truncation turned off (-fnotrunc) and once with it turned   **
      ** on (the default); you'll see some AMAZING differences in    **
      ** execution times!                                            **
      **                                                             **
      ** Remember that COBOL is retrieving wall-clock time, not      **
      ** actual CPU-used time, so other activities taking place on   **
      ** your PC may influence the timings - run the program multi-  **
      ** ple times to get your best view of the relative timings.    **
      **                                                             **
      ** AUTHOR:       GARY L. CUTLER                                **
      **               address@hidden                            **
      **                                                             **
      ** DATE-WRITTEN: June 10, 2009                                 **
      **                                                             **
      *****************************************************************
      **  DATE  CHANGE DESCRIPTION                                   **
      ** ====== ==================================================== **
      ** GC0609 INITIAL CODING.                                      **
      *****************************************************************
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Binary-Item         COMP    PIC S9(9) VALUE 0.

       01  Comp-Item           COMP    PIC S9(9) VALUE 0.

       01  Comp-5-Item         COMP-5  PIC S9(9) VALUE 0.

       01  Display-Item        DISPLAY PIC S9(9) VALUE 0.

       01  Old-Time.
           05 OT-Hours                 PIC 9(2).
           05 OT-Minutes               PIC 9(2).
           05 OT-Seconds               PIC 9(2).
           05 OT-Hundredths            PIC 9(2).

       78  Repeat-Count                VALUE 10000000.

       01  The-Time.
           05 TT-Hours                 PIC 9(2).
           05 TT-Minutes               PIC 9(2).
           05 TT-Seconds               PIC 9(2).
           05 TT-Hundredths            PIC 9(2).

       01  Time-Diff                   PIC ZZ9.99.
       PROCEDURE DIVISION.

       010-Test-Usage-DISPLAY.
           ACCEPT Old-Time FROM TIME.
           PERFORM Repeat-Count TIMES
               ADD 7 TO Display-Item
           END-PERFORM.
      D    DISPLAY 'Display-Item=' Display-Item.
           PERFORM 100-Determine-Time-Diff.
           DISPLAY 'USAGE DISPLAY: ' Time-Diff ' SECONDS'.

       020-Test-Usage-COMP.
           ACCEPT Old-Time FROM TIME.
           PERFORM Repeat-Count TIMES
               ADD 7 TO Comp-Item
           END-PERFORM.
      D    DISPLAY 'Comp-Item=' Comp-Item.
           PERFORM 100-Determine-Time-Diff.
           DISPLAY 'USAGE COMP:    ' Time-Diff ' SECONDS'.

       030-Test-Usage-COMP-5.
           ACCEPT Old-Time FROM TIME.
           PERFORM Repeat-Count TIMES
               ADD 7 TO Comp-5-Item
           END-PERFORM.
      D    DISPLAY 'Comp-5-Item=' Comp-5-Item.
           PERFORM 100-Determine-Time-Diff.
           DISPLAY 'USAGE COMP-5:  ' Time-Diff ' SECONDS'.

       040-Test-Usage-BINARY.
           ACCEPT Old-Time FROM TIME.
           PERFORM Repeat-Count TIMES
               ADD 7 TO Binary-Item
           END-PERFORM.
      D    DISPLAY 'Binary-Item=' Comp-5-Item.
           PERFORM 100-Determine-Time-Diff.
           DISPLAY 'USAGE BINARY:  ' Time-Diff ' SECONDS'.

       099-Done.
           STOP RUN.
           
       100-Determine-Time-Diff.
           ACCEPT The-Time FROM TIME.
           COMPUTE Time-Diff =
              ((  TT-Hours * 360000 
                + TT-Minutes * 6000
                + TT-Seconds * 100
                + TT-Hundredths)
              -
               (  OT-Hours * 360000 
                + OT-Minutes * 6000
                + OT-Seconds * 100
                + OT-Hundredths)) / 100.
               
In my experience, by the way, it appears that the truncation happens when
you refer to the field, not when you save a value into it - it appears that
full binary precision is maintained.






-----Original Message-----
From: Bill Klein [mailto:address@hidden 
Sent: Monday, July 27, 2009 23:00
To: 'vince coen'; address@hidden
Subject: Re: [open-cobol-list] displaying max values in comp-5 field

Vince,
  Do you know of any compilers that do truncation with COMP-5?  I know LOTS
that do with COMP or BINARY.  But almost all compilers that I know of that
have COMP-5 as an extension, have it explicitly so it will NOT truncate
based on picture clause (i.e. base 10).  Most, but not all, also have COMP-5
in "operations system - best - binary" format, i.e. little-endian /
big-endian automatically done based not he O/S on which the compiler is run.

Again,
  If the compiler allows for

01  aGroup.
 05  Num1  Pic S9(4) Com-5.
          ...
Move High-Values to aGroup
Display Num1

then it SHOULD (IMHO) display the full value of the data item.  If the
display doesn't work that way, then the compiler should reject it.

> -----Original Message-----
> From: vince coen [mailto:address@hidden 
> Sent: Monday, July 27, 2009 6:24 AM
> To: address@hidden
> Subject: Re: [open-cobol-list] displaying max values in comp-5 field
> 
> Hi
> On Monday 27 July 2009, Sergey Kashyrin wrote:
> > Hi,
> >
> > I think it's not about that
> > It's about DISPLAY which actually not suppose to display 
> ANY binary or
> > comp-3/4/5 fields. I don't see any contradictions with formal Cobol.
> 
> Oops, I 'assumed' that you had moved it to a numeric display 
> field prior to 
> display, but my argument is still valid against various 
> compilers in that 
> auto truncation can occur and manipulating a s9(4) field 
> after over flow any 
> thing can and no doubt will, happen so it is still verifyable 
> to fix by 
> change to s9(5) as needed.
> 
> There again I have programmed in the basis of a specific 
> compilers behaviour 
> as against what the language specs say. It is only over the 
> last few years 
> that I have changed my programming style to match the 
> language specs knowing 
> that the compiler will no doubt change during the life of the 
> app which will 
> be longer than I have anticipated as proven with code written 
> in the 60's and 
> 70's now being converted from MF workbench to run under Open Cobol.
> 
> Vince
> 
> >
> > Not going to do any fixes on that, correct me if I wrong
> >
> > Regards
> > SKA
> >
> > ----- Original Message -----
> > From: "vince coen" <address@hidden>
> > To: <address@hidden>
> > Sent: Sunday, July 26, 2009 7:05 AM
> > Subject: [open-cobol-list] displaying max values in comp-5 field
> >
> > > Hi;
> > >
> > > On Saturday 25 July 2009, Robert Keane wrote:
> > >> Hello All,
> > >>
> > >>
> > >> I've found a problem when displaying the maximum value 
> in a comp-5
> > >> field. If an s9(4) comp-5 can hold +32767 or -32768. 
> After initializing
> > >> or moving +32767 or -32768 to the s9(4) comp-5 field the 
> display gives
> > >> +2767 or -2768, the high order digit is dropped. However 
> if the comp-5
> > >> field is moved to a field defined with enough z's the 
> display is ok.
> > >
> > > A dropped leading digit does not supprise me.  Moving 
> above 9,999 to a
> > > pic s9 (4) will result in truncation. Solution is to 
> increase picture
> > > size to reflect the maximum value your field will get to 
> in this case pic
> > > s9(5) comp-5.
> > >
> > > Or better still use binary-short, its more effective for 
> arithmetic etc
> > > in OC.
> > >
> > > Vince
> > >
> >
> 
> --------------------------------------------------------------
> ----------------
> _______________________________________________
> open-cobol-list mailing list
> address@hidden
> https://lists.sourceforge.net/lists/listinfo/open-cobol-list
> 


----------------------------------------------------------------------------
--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus
on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
open-cobol-list mailing list
address@hidden
https://lists.sourceforge.net/lists/listinfo/open-cobol-list



reply via email to

[Prev in Thread] Current Thread [Next in Thread]