Menu

Floating point and pic 9.99

GnuCOBOL
2024-07-30
2024-08-01
  • Alain Reymond

    Alain Reymond - 2024-07-30

    Hello,

    here is a small program :

           1 mydouble usage float-long.
           1 wss-test pic -99.99.
           procedure division.
           move -21.42 to mydouble
           display "double  : " mydouble
           move -21.42 to wss-test
           move wss-test to mydouble
           display "wss-test: " wss-test
           display "double  : " mydouble
    

    Here is the result using Gnucobol:

    double  : -21.42
    wss-test: -21.42
    double  : 13224.42
    

    and using MF:

    double  : -.214200000000000015E 002
    wss-test: -21.42
    double  : -.214200000000000015E 002
    

    The result of the move from a pic -99.99 is "correct" under MF - at least with 12 zeroes precision - but not with Gnucobol. Is there a reason or is it a bug ?
    Regards.

     
  • Alain Reymond

    Alain Reymond - 2024-08-01

    As follow-up, the solution is ti use the numval function :
    move numval(wss-test) to mydouble
    But the difference of behaviour of the two compilers is still astonishing.

     
  • Ralph Linkletter

    I believe this to be the proper assignment.
    1 wss-test pic S99V99.
    move wss-test to mydouble

    1 wss-test pic -99.99.
    Defined as above is a numeric edited field.
    As such the intent of usage is a receiving field only .

    Behavior in using a numeric edited field in the manner of your example would produce unpredictable results regardless the compiler vendor.

    I would suspect that a warning diagnostic was produced ?

     

    Last edit: Ralph Linkletter 2024-08-01
  • Alain Reymond

    Alain Reymond - 2024-08-01

    You are absolutely right.
    No warning issued.
    I was just confused because we are porting (or trying to!) an app from MF to Gnucobol and it works without any problem under MF.
    Now, we know!

     

Log in to post a comment.