1
Dependencies: mbed-dev-f303 FastPWM3
math_ops.cpp@20:bf9ea5125d52, 2017-03-02 (annotated)
- Committer:
- benkatz
- Date:
- Thu Mar 02 15:31:23 2017 +0000
- Revision:
- 20:bf9ea5125d52
- Child:
- 25:f5741040c4bb
Compact version works.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benkatz | 20:bf9ea5125d52 | 1 | |
benkatz | 20:bf9ea5125d52 | 2 | #include "math_ops.h" |
benkatz | 20:bf9ea5125d52 | 3 | |
benkatz | 20:bf9ea5125d52 | 4 | |
benkatz | 20:bf9ea5125d52 | 5 | float fmaxf(float x, float y){ |
benkatz | 20:bf9ea5125d52 | 6 | return (((x)>(y))?(x):(y)); |
benkatz | 20:bf9ea5125d52 | 7 | } |
benkatz | 20:bf9ea5125d52 | 8 | |
benkatz | 20:bf9ea5125d52 | 9 | float fminf(float x, float y){ |
benkatz | 20:bf9ea5125d52 | 10 | return (((x)<(y))?(x):(y)); |
benkatz | 20:bf9ea5125d52 | 11 | } |
benkatz | 20:bf9ea5125d52 | 12 | |
benkatz | 20:bf9ea5125d52 | 13 | float fmaxf3(float x, float y, float z){ |
benkatz | 20:bf9ea5125d52 | 14 | return (x > y ? (x > z ? x : z) : (y > z ? y : z)); |
benkatz | 20:bf9ea5125d52 | 15 | } |
benkatz | 20:bf9ea5125d52 | 16 | |
benkatz | 20:bf9ea5125d52 | 17 | float fminf3(float x, float y, float z){ |
benkatz | 20:bf9ea5125d52 | 18 | return (x < y ? (x < z ? x : z) : (y < z ? y : z)); |
benkatz | 20:bf9ea5125d52 | 19 | } |
benkatz | 20:bf9ea5125d52 | 20 | |
benkatz | 20:bf9ea5125d52 | 21 | void limit_norm(float *x, float *y, float limit){ |
benkatz | 20:bf9ea5125d52 | 22 | float norm = sqrt(*x * *x + *y * *y); |
benkatz | 20:bf9ea5125d52 | 23 | if(norm > limit){ |
benkatz | 20:bf9ea5125d52 | 24 | *x = *x * limit/norm; |
benkatz | 20:bf9ea5125d52 | 25 | *y = *y * limit/norm; |
benkatz | 20:bf9ea5125d52 | 26 | } |
benkatz | 20:bf9ea5125d52 | 27 | } |