darknesswind / NutCracker

fork from DamianXVI's squirrel decompiler
22 stars 11 forks source link

floating-point precision is lost (and it's also ugly) #19

Open AdamMil opened 5 years ago

AdamMil commented 5 years ago

NutCracker loses precision when outputting floating point numbers. For example, the script print(1e-16); is decompiled as this.print(0.00000000); which is clearly not the same thing. The script print(0.9); is decompiled as this.print(0.89999998); which might be the same thing but also might not be, and definitely looks bad.

Also, the output is ugly. print(1.0); is decompiled as this.print(1.00000000);. This gets especially noticeable with math-heavy code.

Basically, the floating-point number printer should be fixed to print in a round-trippable format that's no longer than necessary to convey the correct value.