Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Converted ExprParser to use float instead of double.

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.