Changeset 8351 for code/trunk/src/libraries/util/ExprParser.cc
- Timestamp:
- Apr 28, 2011, 7:15:14 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/util/ExprParser.cc
r7184 r8351 52 52 { 53 53 this->failed_ = false; 54 this->variables_["pi"] = math::pi _d;55 this->variables_["e"] = math::e _d;56 } 57 58 void ExprParser::setVariable(const std::string& varname, doublevalue)54 this->variables_["pi"] = math::pi; 55 this->variables_["e"] = math::e; 56 } 57 58 void ExprParser::setVariable(const std::string& varname, float value) 59 59 { 60 60 this->variables_[varname] = value; … … 78 78 //Private functions: 79 79 /******************/ 80 doubleExprParser::parse_argument()81 { 82 doublevalue = parse_expr_8();80 float ExprParser::parse_argument() 81 { 82 float value = parse_expr_8(); 83 83 if (*reading_stream == ',') 84 84 { … … 93 93 } 94 94 95 doubleExprParser::parse_last_argument()96 { 97 doublevalue = parse_expr_8();95 float ExprParser::parse_last_argument() 96 { 97 float value = parse_expr_8(); 98 98 if (*reading_stream == ')') 99 99 { … … 108 108 } 109 109 110 doubleExprParser::parse_expr_8()111 { 112 doublevalue = parse_expr_7();110 float ExprParser::parse_expr_8() 111 { 112 float value = parse_expr_7(); 113 113 for(;;) 114 114 { … … 124 124 125 125 126 doubleExprParser::parse_expr_7()127 { 128 doublevalue = parse_expr_6();126 float ExprParser::parse_expr_7() 127 { 128 float value = parse_expr_6(); 129 129 for(;;) 130 130 { … … 139 139 } 140 140 141 doubleExprParser::parse_expr_6()142 { 143 doublevalue = parse_expr_5();141 float ExprParser::parse_expr_6() 142 { 143 float value = parse_expr_5(); 144 144 for(;;) 145 145 { … … 158 158 } 159 159 160 doubleExprParser::parse_expr_5()161 { 162 doublevalue = parse_expr_4();160 float ExprParser::parse_expr_5() 161 { 162 float value = parse_expr_4(); 163 163 for(;;) 164 164 { … … 183 183 } 184 184 185 doubleExprParser::parse_expr_4()186 { 187 doublevalue = parse_expr_3();185 float ExprParser::parse_expr_4() 186 { 187 float value = parse_expr_3(); 188 188 for(;;) 189 189 { … … 202 202 } 203 203 204 doubleExprParser::parse_expr_3()205 { 206 doublevalue = parse_expr_2();204 float ExprParser::parse_expr_3() 205 { 206 float value = parse_expr_2(); 207 207 for(;;) 208 208 { … … 217 217 case modulo: 218 218 { 219 doubletemp = parse_expr_2();219 float temp = parse_expr_2(); 220 220 value = value - floor(value/temp)*temp; 221 221 break; … … 227 227 } 228 228 229 doubleExprParser::parse_expr_2()230 { 231 doublevalue = parse_expr_1();229 float ExprParser::parse_expr_2() 230 { 231 float value = parse_expr_1(); 232 232 while (*reading_stream != '\0') 233 233 { … … 246 246 } 247 247 248 doubleExprParser::parse_expr_1()248 float ExprParser::parse_expr_1() 249 249 { 250 250 PARSE_BLANKS; 251 doublevalue;251 float value; 252 252 253 253 unary_operator op = parse_unary_operator(); … … 262 262 else if ((*reading_stream > 47 && *reading_stream < 59) || *reading_stream == 46) 263 263 { // number 264 value = strtod(reading_stream, const_cast<char**>(&reading_stream));264 value = (float)strtod(reading_stream, const_cast<char**>(&reading_stream)); 265 265 } 266 266 else if ((*reading_stream > 64 && *reading_stream < 91) || (*reading_stream > 96 && *reading_stream < 123) || *reading_stream == 46) … … 306 306 { 307 307 value = parse_last_argument(); 308 value = 0.5 *log((value + 1)/(value - 1));308 value = 0.5f*log((value + 1.0f)/(value - 1.0f)); 309 309 } 310 310 CASE("int") … … 325 325 { 326 326 value = parse_last_argument(); 327 value = (value>0 ? 1 : (value<0 ? -1 : 0));327 value = (value>0.0f ? 1.0f : (value<0.0f ? -1.0f : 0.0f)); 328 328 } 329 329 CASE("sqrt") 330 330 value = sqrt(parse_last_argument()); 331 331 CASE("degrees") 332 value = parse_last_argument()*180 /math::pi_d;332 value = parse_last_argument()*180.0f/math::pi; 333 333 CASE("radians") 334 value = parse_last_argument()*math::pi _d/180;334 value = parse_last_argument()*math::pi/180.0f; 335 335 CASE("mod") 336 336 { 337 337 value = parse_argument(); 338 doublevalue2 = parse_last_argument();338 float value2 = parse_last_argument(); 339 339 value = value - floor(value/value2)*value2; 340 340 } … … 356 356 else 357 357 { 358 std::map<std::string, double>::const_iterator it = this->variables_.find(word);358 std::map<std::string, float>::const_iterator it = this->variables_.find(word); 359 359 if (it != this->variables_.end()) 360 360 value = it->second;
Note: See TracChangeset
for help on using the changeset viewer.