From 2cb35ef26a38ba34e606e9742e5cc9e823ecf867 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Wed, 27 May 2009 04:01:52 +0000 Subject: [PATCH] Fixed a problem with floating point prefix expressions. Added a regression test for floating point. git-svn-id: http://picoc.googlecode.com/svn/trunk@293 21eae674-98b7-11dd-bd71-f92a316d2d60 --- expression.c | 2 ++ tests/22_floating_point.c | 35 ++++++++++++++++++++++++++++++++++ tests/22_floating_point.expect | 14 ++++++++++++++ tests/Makefile | 3 ++- 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/22_floating_point.c create mode 100644 tests/22_floating_point.expect diff --git a/expression.c b/expression.c index 4443b66..07805c0 100644 --- a/expression.c +++ b/expression.c @@ -339,6 +339,8 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack case TokenMinus: ResultFP = -TopValue->Val->FP; break; default: ProgramFail(Parser, "invalid operation"); break; } + + ExpressionPushFP(Parser, StackTop, ResultFP); } else #endif diff --git a/tests/22_floating_point.c b/tests/22_floating_point.c new file mode 100644 index 0000000..6673c19 --- /dev/null +++ b/tests/22_floating_point.c @@ -0,0 +1,35 @@ +// variables +float a = 12.34 + 56.78; +printf("%f\n", a); + +// infix operators +printf("%f\n", 12.34 + 56.78); +printf("%f\n", 12.34 - 56.78); +printf("%f\n", 12.34 * 56.78); +printf("%f\n", 12.34 / 56.78); + +// comparison operators +printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78); +printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34); +printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34); + +// assignment operators +a = 12.34; +a += 56.78; +printf("%f\n", a); + +a = 12.34; +a -= 56.78; +printf("%f\n", a); + +a = 12.34; +a *= 56.78; +printf("%f\n", a); + +a = 12.34; +a /= 56.78; +printf("%f\n", a); + +// prefix operators +printf("%f\n", +12.34); +printf("%f\n", -12.34); diff --git a/tests/22_floating_point.expect b/tests/22_floating_point.expect new file mode 100644 index 0000000..efeed32 --- /dev/null +++ b/tests/22_floating_point.expect @@ -0,0 +1,14 @@ +69.12 +69.12 +-44.44 +700.6652 +0.21733 +1 1 0 0 0 1 +0 1 1 1 0 0 +0 0 0 1 1 1 +69.12 +-44.44 +700.6652 +0.21733 +12.34 +-12.34 diff --git a/tests/Makefile b/tests/Makefile index b9be41a..ffef79a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -18,7 +18,8 @@ TESTS= 00_assignment.test \ 17_enum.test \ 18_include.test \ 19_pointer_arithmetic.test \ - 20_pointer_comparison.test + 20_pointer_comparison.test \ + 22_floating_point.test %.test: %.expect %.c @echo Test: $*...