3 ms·
Indeed old programming languages get it right: Fortran (the oldest still in use): $ cat sub.f C Prints 0.3-0.2 and 0.2-0.3 PRINT 4, 0.3-0.2,
by informatimago 14y ago
Indeed old programming languages get it right:
Fortran (the oldest still in use):
$ cat sub.f
C Prints 0.3-0.2 and 0.2-0.3
PRINT 4, 0.3-0.2, 0.2-0.1
4 FORMAT ('0.3-0.2=',F3.1,' 0.2-0.1=',F3.1)
STOP 1
END
$ gfortran sub.f -o sub
$ ./sub
0.3-0.2=0.1 0.2-0.1=0.1
STOP 1
$
Lisp (the second oldest still in use):
cl-user> (values (- 3/10 2/10) (- 2/10 1/10))
1/10
1/10
Cobol (the third oldest still in use):
$ cat sub.cob
IDENTIFICATION DIVISION.
PROGRAM-ID. DIFFERENCE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
77 out32 pic 9.9.
77 out21 pic 9.9.
PROCEDURE DIVISION.
subtract 0.2 from 0.3 giving out32.
subtract 0.1 from 0.2 giving out21.
display '; 0.3 - 0.2 = ' out32 .
display '; 0.2 - 0.1 = ' out21 .
goback.
$ cobc -fixed -Wcolumn-overflow -Wparentheses -x sub.cob
$ ./sub
; 0.3 - 0.2 = 0.1
; 0.2 - 0.1 = 0.1
$
- zerohp 14y agoThese code samples don't test equality. Printing the output probably rounds off the difference.