[Orxonox-commit 3646] r8331 - code/branches/kicklib2/src/libraries/util
rgrieder at orxonox.net
rgrieder at orxonox.net
Tue Apr 26 02:50:03 CEST 2011
Author: rgrieder
Date: 2011-04-26 02:50:03 +0200 (Tue, 26 Apr 2011)
New Revision: 8331
Modified:
code/branches/kicklib2/src/libraries/util/ExprParser.cc
code/branches/kicklib2/src/libraries/util/ExprParser.h
Log:
Converted ExprParser to use float instead of double.
Modified: code/branches/kicklib2/src/libraries/util/ExprParser.cc
===================================================================
--- code/branches/kicklib2/src/libraries/util/ExprParser.cc 2011-04-25 22:33:09 UTC (rev 8330)
+++ code/branches/kicklib2/src/libraries/util/ExprParser.cc 2011-04-26 00:50:03 UTC (rev 8331)
@@ -51,11 +51,11 @@
ExprParser::ExprParser()
{
this->failed_ = false;
- this->variables_["pi"] = math::pi_d;
- this->variables_["e"] = math::e_d;
+ this->variables_["pi"] = math::pi;
+ this->variables_["e"] = math::e;
}
- void ExprParser::setVariable(const std::string& varname, double value)
+ void ExprParser::setVariable(const std::string& varname, float value)
{
this->variables_[varname] = value;
}
@@ -77,9 +77,9 @@
//Private functions:
/******************/
- double ExprParser::parse_argument()
+ float ExprParser::parse_argument()
{
- double value = parse_expr_8();
+ float value = parse_expr_8();
if (*reading_stream == ',')
{
++reading_stream;
@@ -92,9 +92,9 @@
}
}
- double ExprParser::parse_last_argument()
+ float ExprParser::parse_last_argument()
{
- double value = parse_expr_8();
+ float value = parse_expr_8();
if (*reading_stream == ')')
{
++reading_stream;
@@ -107,9 +107,9 @@
}
}
- double ExprParser::parse_expr_8()
+ float ExprParser::parse_expr_8()
{
- double value = parse_expr_7();
+ float value = parse_expr_7();
for(;;)
{
switch (op)
@@ -123,9 +123,9 @@
}
- double ExprParser::parse_expr_7()
+ float ExprParser::parse_expr_7()
{
- double value = parse_expr_6();
+ float value = parse_expr_6();
for(;;)
{
switch (op)
@@ -138,9 +138,9 @@
};
}
- double ExprParser::parse_expr_6()
+ float ExprParser::parse_expr_6()
{
- double value = parse_expr_5();
+ float value = parse_expr_5();
for(;;)
{
switch (op)
@@ -157,9 +157,9 @@
};
}
- double ExprParser::parse_expr_5()
+ float ExprParser::parse_expr_5()
{
- double value = parse_expr_4();
+ float value = parse_expr_4();
for(;;)
{
switch (op)
@@ -182,9 +182,9 @@
};
}
- double ExprParser::parse_expr_4()
+ float ExprParser::parse_expr_4()
{
- double value = parse_expr_3();
+ float value = parse_expr_3();
for(;;)
{
switch (op)
@@ -201,9 +201,9 @@
};
}
- double ExprParser::parse_expr_3()
+ float ExprParser::parse_expr_3()
{
- double value = parse_expr_2();
+ float value = parse_expr_2();
for(;;)
{
switch (op)
@@ -216,7 +216,7 @@
break;
case modulo:
{
- double temp = parse_expr_2();
+ float temp = parse_expr_2();
value = value - floor(value/temp)*temp;
break;
}
@@ -226,9 +226,9 @@
};
}
- double ExprParser::parse_expr_2()
+ float ExprParser::parse_expr_2()
{
- double value = parse_expr_1();
+ float value = parse_expr_1();
while (*reading_stream != '\0')
{
op = parse_binary_operator();
@@ -245,10 +245,10 @@
return value;
}
- double ExprParser::parse_expr_1()
+ float ExprParser::parse_expr_1()
{
PARSE_BLANKS;
- double value;
+ float value;
unary_operator op = parse_unary_operator();
PARSE_BLANKS;
@@ -261,7 +261,7 @@
}
else if ((*reading_stream > 47 && *reading_stream < 59) || *reading_stream == 46)
{ // number
- value = strtod(reading_stream, const_cast<char**>(&reading_stream));
+ value = (float)strtod(reading_stream, const_cast<char**>(&reading_stream));
}
else if ((*reading_stream > 64 && *reading_stream < 91) || (*reading_stream > 96 && *reading_stream < 123) || *reading_stream == 46)
{ // variable or function
@@ -305,7 +305,7 @@
CASE("atanh")
{
value = parse_last_argument();
- value = 0.5*log((value + 1)/(value - 1));
+ value = 0.5f*log((value + 1.0f)/(value - 1.0f));
}
CASE("int")
value = floor(parse_last_argument());
@@ -324,18 +324,18 @@
CASE("sign")
{
value = parse_last_argument();
- value = (value>0 ? 1 : (value<0 ? -1 : 0));
+ value = (value>0.0f ? 1.0f : (value<0.0f ? -1.0f : 0.0f));
}
CASE("sqrt")
value = sqrt(parse_last_argument());
CASE("degrees")
- value = parse_last_argument()*180/math::pi_d;
+ value = parse_last_argument()*180.0f/math::pi;
CASE("radians")
- value = parse_last_argument()*math::pi_d/180;
+ value = parse_last_argument()*math::pi/180.0f;
CASE("mod")
{
value = parse_argument();
- double value2 = parse_last_argument();
+ float value2 = parse_last_argument();
value = value - floor(value/value2)*value2;
}
CASE("pow")
@@ -355,7 +355,7 @@
}
else
{
- std::map<std::string, double>::const_iterator it = this->variables_.find(word);
+ std::map<std::string, float>::const_iterator it = this->variables_.find(word);
if (it != this->variables_.end())
value = it->second;
else
Modified: code/branches/kicklib2/src/libraries/util/ExprParser.h
===================================================================
--- code/branches/kicklib2/src/libraries/util/ExprParser.h 2011-04-25 22:33:09 UTC (rev 8330)
+++ code/branches/kicklib2/src/libraries/util/ExprParser.h 2011-04-26 00:50:03 UTC (rev 8331)
@@ -56,7 +56,7 @@
{
COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl;
}
- double result = expr.getResult();
+ float result = expr.getResult();
}
else
COUT(1) << "Error: Cannot calculate expression: Parse error." << std::endl;
@@ -124,41 +124,41 @@
ExprParser();
void parse(const std::string& str);
const std::string& getRemains() { return this->remains_; }
- double getResult() { return this->result_; }
+ float getResult() { return this->result_; }
bool getSuccess() { return !this->failed_; }
- void setVariable(const std::string& varname, double value);
+ void setVariable(const std::string& varname, float value);
private:
- double parse_expr_1();
- double parse_expr_2();
- double parse_expr_3();
- double parse_expr_4();
- double parse_expr_5();
- double parse_expr_6();
- double parse_expr_7();
- double parse_expr_8();
+ float parse_expr_1();
+ float parse_expr_2();
+ float parse_expr_3();
+ float parse_expr_4();
+ float parse_expr_5();
+ float parse_expr_6();
+ float parse_expr_7();
+ float parse_expr_8();
char* parse_word(char* str);
binary_operator parse_binary_operator();
unary_operator parse_unary_operator();
- double parse_argument();
- double parse_last_argument();
+ float parse_argument();
+ float parse_last_argument();
binary_operator op;
const char* reading_stream;
bool failed_;
- double result_;
+ float result_;
std::string remains_;
- std::map<std::string, double> variables_;
+ std::map<std::string, float> variables_;
};
//Endzeichen für float expression: ')', '}', ']', ',', ';'
- _UtilExport bool parse_float(char* const, char**, double*);
+ _UtilExport bool parse_float(char* const, char**, float*);
//Endzeichen angegeben
- _UtilExport bool parse_float(char* const, char**, char, double*);
+ _UtilExport bool parse_float(char* const, char**, char, float*);
//Letzter Teil-float eines Vektors parsen (keine Vergleichs- und Logikoperationen)
- _UtilExport bool parse_vector_float(char* const, char**, bool, double*);
+ _UtilExport bool parse_vector_float(char* const, char**, bool, float*);
}
#endif /* _FloatParser_H__ */
More information about the Orxonox-commit
mailing list