As far as programming goes, I spend more time — at least lately — debating what new things to learn rather than actually learning new things. And I generally haven’t gone about these debates in a systematic manner. I mostly go to Google and type some variant of “should i learn haskell or go” and skim through some blog posts and Reddit threads and then I do something unrelated for a couple hours while I worry about future proofing my skills and then I return to Google and type in the same phrase and click on the same links.
const price = 1.2; const quantity = 3; const total = price * quantity; // Outputs 3.5999999999999996 // instead of 3.6 console.log(total);
I can demonstrate the same problem in Python. If I go to my command line and type
python to open a REPL, I can naively yield:
>>> x = 0.1 >>> y = 0.2 >>> x + y 0.30000000000000004
While on a Hacker News thread about ReasonML, I saw someone comment:
let price = 1.2; let quantity = 3.0; let total = price *. quantity; Js.log(total);
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; var total = 1.2 * 3.0; console.log(total); var price = 1.2; var quantity = 3.0; exports.price = price; exports.quantity = quantity; exports.total = total; /* Not a pure module */