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:
parent
8092d67c70
commit
2cb35ef26a
|
@ -339,6 +339,8 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
case TokenMinus: ResultFP = -TopValue->Val->FP; break;
|
case TokenMinus: ResultFP = -TopValue->Val->FP; break;
|
||||||
default: ProgramFail(Parser, "invalid operation"); break;
|
default: ProgramFail(Parser, "invalid operation"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExpressionPushFP(Parser, StackTop, ResultFP);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
35
tests/22_floating_point.c
Normal file
35
tests/22_floating_point.c
Normal 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);
|
14
tests/22_floating_point.expect
Normal file
14
tests/22_floating_point.expect
Normal 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
|
|
@ -18,7 +18,8 @@ TESTS= 00_assignment.test \
|
||||||
17_enum.test \
|
17_enum.test \
|
||||||
18_include.test \
|
18_include.test \
|
||||||
19_pointer_arithmetic.test \
|
19_pointer_arithmetic.test \
|
||||||
20_pointer_comparison.test
|
20_pointer_comparison.test \
|
||||||
|
22_floating_point.test
|
||||||
|
|
||||||
%.test: %.expect %.c
|
%.test: %.expect %.c
|
||||||
@echo Test: $*...
|
@echo Test: $*...
|
||||||
|
|
Loading…
Reference in a new issue