Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8331


Ignore:
Timestamp:
Apr 26, 2011, 2:50:03 AM (13 years ago)
Author:
rgrieder
Message:

Converted ExprParser to use float instead of double.

Location:
code/branches/kicklib2/src/libraries/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2/src/libraries/util/ExprParser.cc

    r7184 r8331  
    5252    {
    5353        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, double value)
     54        this->variables_["pi"] = math::pi;
     55        this->variables_["e"] = math::e;
     56    }
     57
     58    void ExprParser::setVariable(const std::string& varname, float value)
    5959    {
    6060        this->variables_[varname] = value;
     
    7878    //Private functions:
    7979    /******************/
    80     double ExprParser::parse_argument()
    81     {
    82         double value = parse_expr_8();
     80    float ExprParser::parse_argument()
     81    {
     82        float value = parse_expr_8();
    8383        if (*reading_stream == ',')
    8484        {
     
    9393    }
    9494
    95     double ExprParser::parse_last_argument()
    96     {
    97         double value = parse_expr_8();
     95    float ExprParser::parse_last_argument()
     96    {
     97        float value = parse_expr_8();
    9898        if (*reading_stream == ')')
    9999        {
     
    108108    }
    109109
    110     double ExprParser::parse_expr_8()
    111     {
    112         double value = parse_expr_7();
     110    float ExprParser::parse_expr_8()
     111    {
     112        float value = parse_expr_7();
    113113        for(;;)
    114114        {
     
    124124
    125125
    126     double ExprParser::parse_expr_7()
    127     {
    128         double value = parse_expr_6();
     126    float ExprParser::parse_expr_7()
     127    {
     128        float value = parse_expr_6();
    129129        for(;;)
    130130        {
     
    139139    }
    140140
    141     double ExprParser::parse_expr_6()
    142     {
    143         double value = parse_expr_5();
     141    float ExprParser::parse_expr_6()
     142    {
     143        float value = parse_expr_5();
    144144        for(;;)
    145145        {
     
    158158    }
    159159
    160     double ExprParser::parse_expr_5()
    161     {
    162         double value = parse_expr_4();
     160    float ExprParser::parse_expr_5()
     161    {
     162        float value = parse_expr_4();
    163163        for(;;)
    164164        {
     
    183183    }
    184184
    185     double ExprParser::parse_expr_4()
    186     {
    187         double value = parse_expr_3();
     185    float ExprParser::parse_expr_4()
     186    {
     187        float value = parse_expr_3();
    188188        for(;;)
    189189        {
     
    202202    }
    203203
    204     double ExprParser::parse_expr_3()
    205     {
    206         double value = parse_expr_2();
     204    float ExprParser::parse_expr_3()
     205    {
     206        float value = parse_expr_2();
    207207        for(;;)
    208208        {
     
    217217            case modulo:
    218218                {
    219                     double temp = parse_expr_2();
     219                    float temp = parse_expr_2();
    220220                    value = value - floor(value/temp)*temp;
    221221                    break;
     
    227227    }
    228228
    229     double ExprParser::parse_expr_2()
    230     {
    231         double value = parse_expr_1();
     229    float ExprParser::parse_expr_2()
     230    {
     231        float value = parse_expr_1();
    232232        while (*reading_stream != '\0')
    233233        {
     
    246246    }
    247247
    248     double ExprParser::parse_expr_1()
     248    float ExprParser::parse_expr_1()
    249249    {
    250250        PARSE_BLANKS;
    251         double value;
     251        float value;
    252252
    253253        unary_operator op = parse_unary_operator();
     
    262262        else if ((*reading_stream > 47 && *reading_stream < 59) || *reading_stream == 46)
    263263        {  // number
    264             value = strtod(reading_stream, const_cast<char**>(&reading_stream));
     264            value = (float)strtod(reading_stream, const_cast<char**>(&reading_stream));
    265265        }
    266266        else if ((*reading_stream > 64 && *reading_stream < 91) || (*reading_stream > 96 && *reading_stream < 123) || *reading_stream == 46)
     
    306306                {
    307307                    value = parse_last_argument();
    308                     value = 0.5*log((value + 1)/(value - 1));
     308                    value = 0.5f*log((value + 1.0f)/(value - 1.0f));
    309309                }
    310310                CASE("int")
     
    325325                {
    326326                    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));
    328328                }
    329329                CASE("sqrt")
    330330                    value = sqrt(parse_last_argument());
    331331                CASE("degrees")
    332                     value = parse_last_argument()*180/math::pi_d;
     332                    value = parse_last_argument()*180.0f/math::pi;
    333333                CASE("radians")
    334                     value = parse_last_argument()*math::pi_d/180;
     334                    value = parse_last_argument()*math::pi/180.0f;
    335335                CASE("mod")
    336336                {
    337337                    value = parse_argument();
    338                     double value2 = parse_last_argument();
     338                    float value2 = parse_last_argument();
    339339                    value = value - floor(value/value2)*value2;
    340340                }
     
    356356            else
    357357            {
    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);
    359359                if (it != this->variables_.end())
    360360                    value = it->second;
  • code/branches/kicklib2/src/libraries/util/ExprParser.h

    r7401 r8331  
    5757                COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl;
    5858            }
    59             double result = expr.getResult();
     59            float result = expr.getResult();
    6060        }
    6161        else
     
    125125        void parse(const std::string& str);
    126126        const std::string& getRemains() { return  this->remains_; }
    127         double             getResult()  { return  this->result_; }
     127        float              getResult()  { return  this->result_; }
    128128        bool               getSuccess() { return !this->failed_; }
    129129
    130         void setVariable(const std::string& varname, double value);
     130        void setVariable(const std::string& varname, float value);
    131131
    132132    private:
    133         double parse_expr_1();
    134         double parse_expr_2();
    135         double parse_expr_3();
    136         double parse_expr_4();
    137         double parse_expr_5();
    138         double parse_expr_6();
    139         double parse_expr_7();
    140         double parse_expr_8();
     133        float parse_expr_1();
     134        float parse_expr_2();
     135        float parse_expr_3();
     136        float parse_expr_4();
     137        float parse_expr_5();
     138        float parse_expr_6();
     139        float parse_expr_7();
     140        float parse_expr_8();
    141141        char* parse_word(char* str);
    142142        binary_operator parse_binary_operator();
    143143        unary_operator parse_unary_operator();
    144144
    145         double parse_argument();
    146         double parse_last_argument();
     145        float parse_argument();
     146        float parse_last_argument();
    147147
    148148        binary_operator op;
    149149        const char* reading_stream;
    150150        bool failed_;
    151         double result_;
     151        float result_;
    152152        std::string remains_;
    153         std::map<std::string, double> variables_;
     153        std::map<std::string, float> variables_;
    154154    };
    155155
    156156    //Endzeichen für float expression: ')', '}', ']', ',', ';'
    157     _UtilExport bool parse_float(char* const, char**, double*);
     157    _UtilExport bool parse_float(char* const, char**, float*);
    158158    //Endzeichen angegeben
    159     _UtilExport bool parse_float(char* const, char**, char, double*);
     159    _UtilExport bool parse_float(char* const, char**, char, float*);
    160160    //Letzter Teil-float eines Vektors parsen (keine Vergleichs- und Logikoperationen)
    161     _UtilExport bool parse_vector_float(char* const, char**, bool, double*);
     161    _UtilExport bool parse_vector_float(char* const, char**, bool, float*);
    162162}
    163163
Note: See TracChangeset for help on using the changeset viewer.