[decompiler] Print floats as neatly as possible (#307)

* [decompiler] Print floats as neatly as possible

* style fixes

* more

* Update test.bat

* Add and fix tests

* Jesus christ fine
This commit is contained in:
ManDude
2021-03-04 05:47:46 +00:00
committed by GitHub
parent d9aa535dd0
commit e77478e2e6
8 changed files with 115 additions and 87 deletions
+20 -20
View File
@@ -289,31 +289,31 @@ TEST_F(DataDecompTest, ContinuePoint) {
" :name \"finalboss-start\"\n"
" :level 'finalboss\n"
" :trans (new 'static 'vector\n"
" :x 11548456.000000\n"
" :y 2215872.000000\n"
" :z -19409498.000000\n"
" :w 1.000000\n"
" :x 11548456.0\n"
" :y 2215872.0\n"
" :z -19409498.0\n"
" :w 1.0\n"
" )\n"
" :quat (new 'static 'vector\n"
" :y (the-as float #x3f3b851f)\n"
" :w (the-as float #x3f2e425b)\n"
" :y 0.7325\n"
" :w 0.6807\n"
" )\n"
" :camera-trans (new 'static 'vector\n"
" :x 11513311.000000\n"
" :y (the-as float #x4a0869de)\n"
" :z -19435708.000000\n"
" :w 1.000000\n"
" :x 11513311.0\n"
" :y 2234999.5\n"
" :z -19435708.0\n"
" :w 1.0\n"
" )\n"
" :camera-rot (new 'static 'array 'float 9\n"
" (the-as float #x3f169ad4)\n"
" 0.000000\n"
" (the-as float #xbf4ef9db)\n"
" (the-as float #x3ddbf488)\n"
" (the-as float #x3f7db8bb)\n"
" (the-as float #x3d9ff2e5)\n"
" (the-as float #x3f4d288d)\n"
" (the-as float #xbe07fcb9)\n"
" (the-as float #x3f15460b)\n"
" 0.5883\n"
" 0.0\n"
" -0.8085\n"
" 0.1074\n"
" 0.9911\n"
" 0.0781\n"
" 0.8014\n"
" -0.1328\n"
" 0.5831\n"
" )\n"
" :load-commands (('special \"citb-exit-plat-4\" #t))\n"
" :vis-nick 'fin\n"
@@ -341,4 +341,4 @@ TEST_F(DataDecompTest, FloatArray) {
check_forms_equal(decomp.print(),
"(new 'static 'array 'float 7\n"
"1.0 0.0 1.0 0.0 1.0 0.0 1.0)");
}
}
+22 -12
View File
@@ -155,11 +155,11 @@ TEST(GoosBuiltins, Addition) {
// two element adding
EXPECT_EQ(e(i, "(+ 1 2)"), "3");
EXPECT_EQ(e(i, "(+ 1.1 2.2)"), "3.300000");
EXPECT_EQ(e(i, "(+ 1.1 2.2)"), "3.3");
// mixed
EXPECT_EQ(e(i, "(+ 1 1.1)"), "2");
EXPECT_EQ(e(i, "(+ 1.1 1)"), "2.100000");
EXPECT_EQ(e(i, "(+ 1.1 1)"), "2.1");
// many, and check rounding happens at the right time
EXPECT_EQ(e(i, "(+ 1 1.4 1.4 1.4 1.4)"), "5");
@@ -178,11 +178,11 @@ TEST(GoosBuiltins, Multiplication) {
// two element adding
EXPECT_EQ(e(i, "(* 3 2)"), "6");
EXPECT_EQ(e(i, "(* 1.1 2.2)"), "2.420000");
EXPECT_EQ(e(i, "(* 1.1 2.2)"), "2.42");
// mixed
EXPECT_EQ(e(i, "(* 1 1.1)"), "1");
EXPECT_EQ(e(i, "(* 1.1 1)"), "1.100000");
EXPECT_EQ(e(i, "(* 1.1 1)"), "1.1");
// many, and check rounding happens at the right time
EXPECT_EQ(e(i, "(* 3 1.4 1.4 1.4 1.4)"), "3");
@@ -201,11 +201,11 @@ TEST(GoosBuiltins, Subtraction) {
// two element adding
EXPECT_EQ(e(i, "(- 3 2)"), "1");
EXPECT_EQ(e(i, "(- 1.1 2.2)"), "-1.100000");
EXPECT_EQ(e(i, "(- 1.1 2.2)"), "-1.1");
// mixed
EXPECT_EQ(e(i, "(- 1 1.1)"), "0");
EXPECT_EQ(e(i, "(- 1.1 1)"), "0.100000");
EXPECT_EQ(e(i, "(- 1.1 1)"), "0.1");
// many, and check rounding happens at the right time
EXPECT_EQ(e(i, "(- 3 1.4 1.4 1.4 1.4)"), "-1");
@@ -221,11 +221,11 @@ TEST(GoosBuiltins, Division) {
// two element adding
EXPECT_EQ(e(i, "(/ 16 2)"), "8");
EXPECT_EQ(e(i, "(/ 9. 2.)"), "4.500000");
EXPECT_EQ(e(i, "(/ 9. 2.)"), "4.5");
// mixed
EXPECT_EQ(e(i, "(/ 3 2.)"), "1");
EXPECT_EQ(e(i, "(/ 3. 2)"), "1.500000");
EXPECT_EQ(e(i, "(/ 3. 2)"), "1.5");
i.disable_printfs();
for (auto x : {"(/ 1)", "(/ 1.0)", "(/)", "(/ 'a)", "(/ #\\a)", "(/ 1 :test 2)",
@@ -494,7 +494,7 @@ TEST(GoosEval, EvalSelfEvaluating) {
EXPECT_EQ(e(i, "010"), "10");
EXPECT_EQ(e(i, "-010"), "-10");
EXPECT_EQ(e(i, "\"test\""), "\"test\"");
EXPECT_EQ(e(i, "1.2"), "1.200000"); // this depends on how we decide to print floats
EXPECT_EQ(e(i, "1.2"), "1.2"); // this depends on how we decide to print floats
EXPECT_EQ(e(i, "#\\a"), "#\\a");
EXPECT_EQ(e(i, "#\\\\n"), "#\\\\n");
@@ -502,6 +502,16 @@ TEST(GoosEval, EvalSelfEvaluating) {
EXPECT_ANY_THROW(e(i, "#\\\\a"));
}
TEST(GoosEval, FloatEvalAndPrinting) {
Interpreter i;
EXPECT_EQ(e(i, "0.9999979734420776"), "0.999998");
EXPECT_EQ(e(i, "0.999998"), e(i, "0.9999979734420776"));
EXPECT_EQ(e(i, "1."), "1.0");
EXPECT_EQ(e(i, ".03"), "0.03");
EXPECT_EQ(e(i, "0.02999999932944774627685546875"), e(i, "0.03"));
EXPECT_EQ(e(i, "0.5883"), e(i, "0.5882999897"));
}
/*!
* Check named "keyword" arguments
*/
@@ -1020,8 +1030,8 @@ TEST(GoosObject, Float) {
EXPECT_TRUE(different == same);
// check print and inspect
EXPECT_EQ(different.print(), "-12.340000");
EXPECT_EQ(different.inspect(), "[float] -12.340000\n");
EXPECT_EQ(different.print(), "-12.34");
EXPECT_EQ(different.inspect(), "[float] -12.34\n");
}
/*!
@@ -1300,4 +1310,4 @@ TEST(GoosBuiltins, Format) {
TEST(GoosBuiltins, Error) {
Interpreter i;
EXPECT_ANY_THROW(e(i, "(error \"hi\")"));
}
}