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.
Fork of Teleop_Controller by
math_ops.cpp
00001 00002 #include "math_ops.h" 00003 00004 00005 float fmaxf(float x, float y){ 00006 /// Returns maximum of x, y /// 00007 return (((x)>(y))?(x):(y)); 00008 } 00009 00010 float fminf(float x, float y){ 00011 /// Returns minimum of x, y /// 00012 return (((x)<(y))?(x):(y)); 00013 } 00014 00015 float fmaxf3(float x, float y, float z){ 00016 /// Returns maximum of x, y, z /// 00017 return (x > y ? (x > z ? x : z) : (y > z ? y : z)); 00018 } 00019 00020 float fminf3(float x, float y, float z){ 00021 /// Returns minimum of x, y, z /// 00022 return (x < y ? (x < z ? x : z) : (y < z ? y : z)); 00023 } 00024 00025 void limit_norm(float *x, float *y, float limit){ 00026 /// Scales the lenght of vector (x, y) to be <= limit /// 00027 float norm = sqrt(*x * *x + *y * *y); 00028 if(norm > limit){ 00029 *x = *x * limit/norm; 00030 *y = *y * limit/norm; 00031 } 00032 } 00033 00034 00035 int float_to_uint(float x, float x_min, float x_max, int bits){ 00036 /// Converts a float to an unsigned int, given range and number of bits /// 00037 float span = x_max - x_min; 00038 float offset = x_min; 00039 return (int) ((x-offset)*((float)((1<<bits)-1))/span); 00040 } 00041 00042 00043 float uint_to_float(int x_int, float x_min, float x_max, int bits){ 00044 /// converts unsigned int to float, given range and number of bits /// 00045 float span = x_max - x_min; 00046 float offset = x_min; 00047 return ((float)x_int)*span/((float)((1<<bits)-1)) + offset; 00048 }
Generated on Wed Jul 13 2022 06:07:44 by
