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