diff --git a/_posts/2024-04-01-cobol.md b/_posts/2024-04-01-cobol.md new file mode 100644 index 0000000..023eb7f --- /dev/null +++ b/_posts/2024-04-01-cobol.md @@ -0,0 +1,25 @@ +--- +title: COBOL +code: |- + IDENTIFICATION DIVISION. + PROGRAM-ID. HFPMATH. + DATA DIVISION. + WORKING-STORAGE SECTION. + 77 X-32 USAGE COMP-1. + 77 X-64 USAGE COMP-2. + PROCEDURE DIVISION. + COMPUTE X-32 = 0.1 + 0.2. + DISPLAY X-32. + COMPUTE X-64 = 0.1 + 0.2. + DISPLAY X-64. + MOVE 0.1 TO X-64. + DISPLAY X-64. +result: |- + 0.30000001 + 0.3 + 0.09999999999999999 +--- + +COBOL encodes floating-point numbers using the [HFP][1] format instead of IEEE754, leading to different but analogous computation inaccuracies. + +[1]: https://en.wikipedia.org/wiki/IBM_hexadecimal_floating-point