Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an example in COBOL #247

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions _posts/2024-04-01-cobol.md
Original file line number Diff line number Diff line change
@@ -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