code-dot-org/code-dot-org — pull request #167 by joshlory (2014-10-10 23:45:28+00:00)
Title: Add exact js-numbers support to Blockly

This change converts the basic 'math_number' and 'math_arithmetic' blocks to use the js-numbers (jsnums) lib. Any inexact types passed to the 'math_arithmetic' block are converted to exact types before being operated on.

Existing levels "just work" because we override the .valueOf() method on exact types. Whenever an exact type is compared or operated on by non-exact operators it is automatically coerced to an inexact JavaScript Number.

I added some basic codegen.js fixup to strip out `jsnum.ensureExact(...)` and convert `.add` etc. to `+`. There are still extra parens being generated -- I'll need to investigate if we go this route.