123
Dependencies: mbed-dev-f303 FastPWM3
Diff: math_ops.cpp
- Revision:
- 45:aadebe074af6
- Parent:
- 34:51647c6c500d
--- a/math_ops.cpp Sat Jul 14 22:03:52 2018 +0000 +++ b/math_ops.cpp Mon Jul 30 20:25:24 2018 +0000 @@ -1,7 +1,6 @@ #include "math_ops.h" - float fmaxf(float x, float y){ /// Returns maximum of x, y /// return (((x)>(y))?(x):(y)); @@ -37,14 +36,18 @@ } } -int float_to_uint(float x, float x_min, float x_max, int bits){ + +int float_to_uint(float x, float x_min, float x_max, uint8_t bits){ + /// Converts a float to an unsigned int, given range and number of bits /// float span = x_max - x_min; float offset = x_min; - return (int) ((x+offset)*((float)((1<<bits)-1))/span); + return (int) ((x-offset)*((float)((1<<bits)-1))/span); } -float uint_to_float(int x_int, float x_min, float x_max, int bits){ + +float uint_to_float(int x_int, float x_min, float x_max, uint8_t bits){ + /// converts unsigned int to float, given range and number of bits /// float span = x_max - x_min; float offset = x_min; return ((float)x_int)*span/((float)((1<<bits)-1)) + offset; - } + } \ No newline at end of file