Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-dev-f303 FastPWM3
Diff: math_ops.cpp
- Revision:
- 26:2b865c00d7e9
- Parent:
- 25:f5741040c4bb
- Child:
- 34:51647c6c500d
--- a/math_ops.cpp Sun Apr 09 03:05:52 2017 +0000 +++ b/math_ops.cpp Mon May 01 15:22:58 2017 +0000 @@ -30,3 +30,15 @@ *y = *y * limit/norm; } } + +int float_to_uint(float x, float x_min, float x_max, int bits){ + float span = x_max - x_min; + float offset = x_min; + 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 span = x_max - x_min; + float offset = x_min; + return ((float)x_int)*span/((float)((1<<bits)-1)) + offset; + }