title: Compile-to-JavaScript option that uses a Decimal library instead of IEEE 754 math?
body: <p>In JavaScript <code>0.1 + 0.2 = 0.30000000000000004</code> and <a href="https://stackoverflow.com/questions/588004/is-floating-point-math-broken">Is floating point math broken?</a> explains why because of <a href="https://en.wikipedia.org/wiki/IEEE_754#Basic_formats" rel="nofollow noreferrer">IEEE 754</a> math.  I am working with applications in the finance/accounting domain and want a way to make <code>0.1 + 0.2 = 0.3</code></p>
  
  <p>Therefore, I am looking for a solution that can take code similar to the below example with type annotations for Decimal (using the <a href="http://www.typescriptlang.org/" rel="nofollow noreferrer">TypeScript</a> syntax).</p>
  
  <pre><code>var a:Decimal, b:Decimal, c:Decimal;
  
  a = 0.1;
  b = 0.2;
  
  c = a + b;
  </code></pre>
  
  <p>The compile/macro expansion process could output this code which uses a JavaScript Decimal library (e.g. <a href="https://github.com/MikeMcl/decimal.js/" rel="nofollow noreferrer">decimal.js</a>), so c = <code>0.3</code> and not <code>0.30000000000000004</code></p>
  
  <pre><code>var a, b, c;
  
  a = new Decimal(0.1);
  b = new Decimal(0.2);
  
  c = a.plus(b);
  </code></pre>
  
  <hr>
  
  <p>Mozilla <a href="http://sweetjs.org/" rel="nofollow noreferrer">sweet.js</a> macros seems to support <a href="http://sweetjs.org/doc/main/sweet.html#custom-operators" rel="nofollow noreferrer">custom operators</a> which "let you define your own operators or override the built-in operators."</p>
  
  <p><strong>Question:</strong> Is this behavior possible with sweet.js?  Are there any similar examples?</p>
  
  <hr>
  
  <p>TypeScript transpiles source code and this concept has been asked about before with TypeScript:</p>
  
  <ul>
  <li><a href="https://typescript.codeplex.com/discussions/397848" rel="nofollow noreferrer">Implement Operator overloading in TypeScript...</a></li>
  <li><a href="https://github.com/Microsoft/TypeScript/issues/195" rel="nofollow noreferrer">Suggestion: int type #195</a> </li>
  </ul>
  
  <p><strong>Question:</strong> Can the TypeScript compiler be extended to support this use case?  Would this be appropriate for a feature request?</p>
  
  <hr>
  
  <p>Additionally, a <a href="http://blogs.adobe.com/bparadie/2011/11/22/0-2-0-1-0-30000000000000004/" rel="nofollow noreferrer">blog post</a> in a series about cross-compiling ActionScript to JavaScript concluded they wanted "same wrong result in ActionScript and JavaScript" for consistency reasons, but that did not assume additional type annotations.</p>
  
  <p><strong>Question:</strong> Are there other strategies or compile-to-JavaScript options to achieve this goal?</p>