[Update 23 Sept 2012, Float_1_1.zip -- code fix.]
[Update 27 Sept 2012, Float_1_2.zip -- require explicit Float.init() call.]
[Update 1 Nov 2012, finally got my VM translator optimization good enough so the asm fits in ROM.]
[Update 1 June 2013, Float_1_3.zip -- bug fix: x.mult(x) failed if x<0.]
[Update 12 Oct 2014, Float_1_4.zip -- bug fix: missing ()s precedence problem in test code.]
[Update 13 Oct 2014, Float_1_5.zip -- cleanup: all expressions fully ()ed for explicit precedence.]
Here's the result of my latest hacking on Hack:
I wrote a Float class that supports floats with 32-bit mantissas with 10-bit exponents, giving 9-1/3 decimal digit precision with 10±154 range.
It runs on the VM emulator and the CPU emulator (without the call to the test suite). Here's the code if you want to play with it. Binary: Float.hack Source: Float_1_5.zip
The phi computation looks like this:
function void phi()
{
var Float f;
let f = Float.new();
do f.setInt(5);
do f.sqrt();
do f.addInt(1);
do f.divInt(2);
do Output.printString("phi = ");
do f.print(10); // 10 sig. fig.
do Output.println();
do f.dispose();
return;
}
en values were calculated using Taylor series.
Like most late night projects, it could use better comments...
--Mark