COBOL-对于相同的COMPUTE,从大型机到PC的答案不同 [英] COBOL - Differing answer from mainframe to PC for same COMPUTE

查看:107
本文介绍了COBOL-对于相同的COMPUTE,从大型机到PC的答案不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的虚拟COBOL程序,可以执行虚拟COMPUTE并显示结果.

I have this very simple dummy COBOL program which does a dummy COMPUTE and displays the result.

   ID DIVISION.
   PROGRAM-ID. DUMMYPGM.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 NUM-A PIC 9(3) VALUE 399.
   01 NUM-B PIC 9(3) VALUE 211.
   01 NUM-C PIC 9(3).
  *
   PROCEDURE DIVISION.
   MAIN.
       COMPUTE NUM-C = ((NUM-A / 100) - (NUM-B / 100)) * 100
       DISPLAY 'NUM-C IS ' NUM-C
       STOP RUN.

当我在大型机上编译此代码(使用编译器MVS Enterprise COBOL V4.2)并执行它时,我得到"NUM-C IS 100",可能是因为(399/100)被视为3而不是A计算中为3.99(211/100也是如此).

When I compile this code on a mainframe (with compiler MVS Enterprise COBOL V4.2) and execute it, I get "NUM-C IS 100", probably because (399 / 100) is treated as a 3 instead of a 3.99 in the calculation (and same goes for 211 / 100).

但是,当我在PC上(使用GnuCobol编译器)编译相同的确切代码并执行它时,我得到"NUM-C IS 188". PC的答案是正确的,但是我想使其表现得与大型机类似(因此,在该计算语句中失去了精确度,从而得到100而不是188)...我该怎么做?

But when I compile the same exact code on a PC (with the GnuCobol compiler) and execute it, I get "NUM-C IS 188". The PC's answer is correct , but I would like to make it behave like the mainframe (and thus, losing precision in that compute statement to give 100 instead of 188)... How would I do that ?

上面的原因是该代码的一般表达方式:

The reason for the above is a general expression of this code:

 COMPUTE PDISCR = (((((X(1) + DX - XBRAK) * (ABRAK(1) / 1000)) / 100)
                  + PHT(1) + DPH - PHBRAK) * 2) + ((V(1) + DV 
                  + VBRAKMPM) * (V(1) + DV - VBRAKMPM) / 100000)) 

这是一个已有50年历史的Train模拟程序的一部分,我需要将该程序迁移到GnuCOBOL. COMPUTE中使用的所有字段都是整数.我需要能够从GnuCOBOL得到相同的答案.

This is part of a 50-year-old Train simulation program, which I need to migrate to GnuCOBOL. All the fields used in the COMPUTE are integers. I need to be able to get the same answer from GnuCOBOL.

针对OpenCOBOL/GnuCOBOL直至2.0进行了确认.

Confirmed for OpenCOBOL/GnuCOBOL up to 2.0.

推荐答案

https://lwn.net/Articles/733129/

此链接提到gnuCobol 2.2的新std选项:ibm-strict.我想知道这是否会迫使compute语句执行您想要的操作.

This link mentions a new std option for gnuCobol 2.2: ibm-strict. I wonder if that would force the compute statement to do what you want.

这篇关于COBOL-对于相同的COMPUTE,从大型机到PC的答案不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆