Austin Brown
/
ESCmk2_Inductance
Inductance Testing Code
Fork of CurrentModeSine by
math_ops/math_ops.cpp@1:64b881306f6f, 2018-10-11 (annotated)
- Committer:
- austinbrown124
- Date:
- Thu Oct 11 04:13:45 2018 +0000
- Revision:
- 1:64b881306f6f
- Parent:
- 0:9edd6ec0f56a
DINGBAT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
austinbrown124 | 0:9edd6ec0f56a | 1 | |
austinbrown124 | 0:9edd6ec0f56a | 2 | #include "math_ops.h" |
austinbrown124 | 0:9edd6ec0f56a | 3 | |
austinbrown124 | 0:9edd6ec0f56a | 4 | |
austinbrown124 | 0:9edd6ec0f56a | 5 | float fmaxf(float x, float y){ |
austinbrown124 | 0:9edd6ec0f56a | 6 | return (((x)>(y))?(x):(y)); |
austinbrown124 | 0:9edd6ec0f56a | 7 | } |
austinbrown124 | 0:9edd6ec0f56a | 8 | |
austinbrown124 | 0:9edd6ec0f56a | 9 | float fminf(float x, float y){ |
austinbrown124 | 0:9edd6ec0f56a | 10 | return (((x)<(y))?(x):(y)); |
austinbrown124 | 0:9edd6ec0f56a | 11 | } |
austinbrown124 | 0:9edd6ec0f56a | 12 | |
austinbrown124 | 0:9edd6ec0f56a | 13 | float fmaxf3(float x, float y, float z){ |
austinbrown124 | 0:9edd6ec0f56a | 14 | return (x > y ? (x > z ? x : z) : (y > z ? y : z)); |
austinbrown124 | 0:9edd6ec0f56a | 15 | } |
austinbrown124 | 0:9edd6ec0f56a | 16 | |
austinbrown124 | 0:9edd6ec0f56a | 17 | float fminf3(float x, float y, float z){ |
austinbrown124 | 0:9edd6ec0f56a | 18 | return (x < y ? (x < z ? x : z) : (y < z ? y : z)); |
austinbrown124 | 0:9edd6ec0f56a | 19 | } |
austinbrown124 | 0:9edd6ec0f56a | 20 | |
austinbrown124 | 0:9edd6ec0f56a | 21 | void limit_norm(float *x, float *y, float limit){ |
austinbrown124 | 0:9edd6ec0f56a | 22 | float norm = sqrt(*x * *x + *y * *y); |
austinbrown124 | 0:9edd6ec0f56a | 23 | if(norm > limit){ |
austinbrown124 | 0:9edd6ec0f56a | 24 | *x = *x * limit/norm; |
austinbrown124 | 0:9edd6ec0f56a | 25 | *y = *y * limit/norm; |
austinbrown124 | 0:9edd6ec0f56a | 26 | } |
austinbrown124 | 0:9edd6ec0f56a | 27 | } |
austinbrown124 | 1:64b881306f6f | 28 | |
austinbrown124 | 1:64b881306f6f | 29 | void limit_abs(float *x, float limit){ |
austinbrown124 | 1:64b881306f6f | 30 | limit = abs(limit); |
austinbrown124 | 1:64b881306f6f | 31 | if(*x > limit){ |
austinbrown124 | 1:64b881306f6f | 32 | *x = limit; |
austinbrown124 | 1:64b881306f6f | 33 | } |
austinbrown124 | 1:64b881306f6f | 34 | if(*x < -limit){ |
austinbrown124 | 1:64b881306f6f | 35 | *x = -limit; |
austinbrown124 | 1:64b881306f6f | 36 | } |
austinbrown124 | 1:64b881306f6f | 37 | } |