Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

FWIW, tried this with two less common languages:

    Tcl: + 0.1 0.2 
      0.30000000000000004

    Chicken Scheme: (+ 0.1 0.2)
      0.3
Same results under Windows 8.1 and FreeBSD 10.2. I suppose one is as "right" as the other, at least both answers equally popular among languages.


Also Chicken Scheme:

  (- 0.3 (+ 0.1 0.2))
    -5.55111512312578e-17
Of course you can always (use numbers), but then you have to use (/ 1 20) and (/ 2 10). "0.3" is still considered "inexact", because of the decimal point. I don't like this - finite decimals are perfectly rational numbers and trivially convertible, why can't the interpreter treat them as such?


Another less-common language. The docs suggests they use "C doubles" for all floats.

    Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.6.6)

    ?- Sum is 0.1 + 0.2.
    Sum = 0.30000000000000004.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: