Hacker News new | comments | show | ask | jobs | submit login

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
    $



These code samples don't test equality. Printing the output probably rounds off the difference.




Applications are open for YC Winter 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: