ocra-recipes / ocra-wbi-plugins

Controller implementations and plugins for communicating between the whole body controller libraries developed at ISIR, ocra-recipes, and the iCub Whole Body Interface, WBI, libraries.
GNU General Public License v3.0
3 stars 3 forks source link

Use of integer absolute value in place of floating point one #3

Closed traversaro closed 8 years ago

traversaro commented 8 years ago

Compiling the repo in clang I got this interesting warning:

/home/pegua/isir-tests/codyco-superbuild/main/ocra-wbi-plugins/libs/taskSequences/src/sequences/JointTest.cpp:44:19: warning: using integer absolute value function
      'abs' when argument is of floating point type [-Wabsolute-value]
        taskErr = abs(taskErrorVector(jIndex));
                  ^
/home/pegua/isir-tests/codyco-superbuild/main/ocra-wbi-plugins/libs/taskSequences/src/sequences/JointTest.cpp:44:19: note: use function 'std::abs' instead
        taskErr = abs(taskErrorVector(jIndex));
                  ^~~
                  std::abs
/home/pegua/isir-tests/codyco-superbuild/main/ocra-wbi-plugins/libs/taskSequences/src/sequences/Exploration.cpp:159:11: warning: using integer absolute value function
      'abs' when argument is of floating point type [-Wabsolute-value]
    if ( (abs(time - resetTimeLeft) >= TIME_LIMIT) || (attainedGoal(state, lHandIndex)) )
          ^
/home/pegua/isir-tests/codyco-superbuild/main/ocra-wbi-plugins/libs/taskSequences/src/sequences/Exploration.cpp:159:11: note: use function 'std::abs' instead
    if ( (abs(time - resetTimeLeft) >= TIME_LIMIT) || (attainedGoal(state, lHandIndex)) )
          ^~~
          std::abs
/home/pegua/isir-tests/codyco-superbuild/main/ocra-wbi-plugins/libs/taskSequences/src/sequences/Exploration.cpp:175:11: warning: using integer absolute value function
      'abs' when argument is of floating point type [-Wabsolute-value]
    if ( (abs(time - resetTimeRight) >= TIME_LIMIT) || (attainedGoal(state, rHandIndex)) )
          ^
/home/pegua/isir-tests/codyco-superbuild/main/ocra-wbi-plugins/libs/taskSequences/src/sequences/Exploration.cpp:175:11: note: use function 'std::abs' instead
    if ( (abs(time - resetTimeRight) >= TIME_LIMIT) || (attainedGoal(state, rHandIndex)) )
          ^~~
          std::abs
/home/pegua/isir-tests/codyco-superbuild/main/ocra-wbi-plugins/modules/gocraController/src/gOcraSequenceCollection.cpp:1240:15: warning: using integer absolute value
      function 'abs' when argument is of floating point type [-Wabsolute-value]
    taskErr = abs(taskErrorVector(jIndex));
              ^
/home/pegua/isir-tests/codyco-superbuild/main/ocra-wbi-plugins/modules/gocraController/src/gOcraSequenceCollection.cpp:1240:15: note: use function 'std::abs' instead
    taskErr = abs(taskErrorVector(jIndex));
              ^~~
              std::abs

Given that using the integer abs would approximate (I think) all error values between -0.5 and 0.5 to 0.0, this could cause some strange (but potentially difficult to notice) behaviors.

rlober commented 8 years ago

Hey Silvio,

I will look at this first thing tomorrow!

rlober commented 8 years ago

Hey @traversaro

This should be fixed by: https://github.com/ocra-recipes/ocra-recipes/commit/99893865f16cff367becb793d91babb1b642d7cf https://github.com/ocra-recipes/ocra-wbi-plugins/commit/7b4aba0f3a85e55ea79eb87f9547a17ab25c3a41

Let me know if it compiles with clang now.

ahoarau commented 8 years ago

let's add clang on travis !

rlober commented 8 years ago

https://github.com/ocra-recipes/ocra-wbi-plugins/issues/4

rlober commented 8 years ago

Please let me know if anyone catches this problem again but I will close it for now.