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
This commit is contained in:
zik.saleeba 2009-05-27 04:01:52 +00:00
parent 8092d67c70
commit 2cb35ef26a
4 changed files with 53 additions and 1 deletions

View file

@ -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

35
tests/22_floating_point.c Normal file
View file

@ -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);

View file

@ -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

View file

@ -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: $*...