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: FastPWM3 mbed-dev-STM-lean
math_ops.cpp
- Committer:
- benkatz
- Date:
- 2017-08-30
- Revision:
- 33:3ab3cce8b44d
- Parent:
- 26:2b865c00d7e9
- Child:
- 34:51647c6c500d
File content as of revision 33:3ab3cce8b44d:
#include "math_ops.h"
float fmaxf(float x, float y){
/// Returns maximum of x, y ///
return (((x)>(y))?(x):(y));
}
float fminf(float x, float y){
/// Returns minimum of x, y ///
return (((x)<(y))?(x):(y));
}
float fmaxf3(float x, float y, float z){
/// Returns maximum of x, y, z ///
return (x > y ? (x > z ? x : z) : (y > z ? y : z));
}
float fminf3(float x, float y, float z){
/// Returns minimum of x, y, z ///
return (x < y ? (x < z ? x : z) : (y < z ? y : z));
}
void limit_norm(float *x, float *y, float limit){
/// Scales the lenght of vector (x, y) to be <= limit ///
float norm = sqrt(*x * *x + *y * *y);
if(norm > limit){
*x = *x * limit/norm;
*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;
}