Ticket #6398: deskcalc_out_of_range.patch

File deskcalc_out_of_range.patch, 1.6 KB (added by jscipione, 14 years ago)

patch to error when result is out of range (input out of domain)

Line 
1Index: src/kits/shared/ExpressionParser.cpp
2===================================================================
3--- src/kits/shared/ExpressionParser.cpp (revision 37774)
4+++ src/kits/shared/ExpressionParser.cpp (working copy)
5@@ -579,9 +579,13 @@
6 return values[0].abs();
7 } else if (strcasecmp("acos", token.string.String()) == 0) {
8 _InitArguments(values, 1);
9+ if (values[0] < -1 || values[0] > 1)
10+ throw ParseException("out of domain", token.position);
11 return values[0].acos();
12 } else if (strcasecmp("asin", token.string.String()) == 0) {
13 _InitArguments(values, 1);
14+ if (values[0] < -1 || values[0] > 1)
15+ throw ParseException("out of domain", token.position);
16 return values[0].asin();
17 } else if (strcasecmp("atan", token.string.String()) == 0) {
18 _InitArguments(values, 1);
19@@ -606,9 +610,13 @@
20 return values[0].floor();
21 } else if (strcasecmp("ln", token.string.String()) == 0) {
22 _InitArguments(values, 1);
23+ if (values[0] <= 0)
24+ throw ParseException("out of domain", token.position);
25 return values[0].log();
26 } else if (strcasecmp("log", token.string.String()) == 0) {
27 _InitArguments(values, 1);
28+ if (values[0] <= 0)
29+ throw ParseException("out of domain", token.position);
30 return values[0].log10();
31 } else if (strcasecmp("pow", token.string.String()) == 0) {
32 _InitArguments(values, 2);
33@@ -621,6 +629,8 @@
34 return values[0].sinh();
35 } else if (strcasecmp("sqrt", token.string.String()) == 0) {
36 _InitArguments(values, 1);
37+ if (values[0] < 0)
38+ throw ParseException("out of domain", token.position);
39 return values[0].sqrt();
40 } else if (strcasecmp("tan", token.string.String()) == 0) {
41 _InitArguments(values, 1);