elvout / cs393r

CS 393R Graduate Autonomous Robots, Fall 2021 | Autobots
0 stars 0 forks source link

Templated angle conversion may not work as expected. #14

Closed elvout closed 3 years ago

elvout commented 3 years ago

The degree-to-radians and radians-to-degrees functions defined in shared/math/math_util.h use templated parameter and return types. If the angle parameter is specified as an int, the function does statically casts the return type to an int, which loses precision and may not be what the caller was expecting.

elvout commented 3 years ago

We can use

static_assert(std::is_floating_point<T>::value, "");

To raise a compile error if an integral type is passed to the function.