diff options
-rw-r--r-- | glcd/fastMath.c | 29 | ||||
-rw-r--r-- | glcd/fastMath.h | 5 |
2 files changed, 15 insertions, 19 deletions
diff --git a/glcd/fastMath.c b/glcd/fastMath.c index 26ae0d3f..1957b304 100644 --- a/glcd/fastMath.c +++ b/glcd/fastMath.c @@ -116,44 +116,39 @@ float sintable[91] = { }; -float getSin(unsigned int degree) -{ +float getSin(unsigned int degree) { degree = degree % 360; - if(degree <= 90) - { + + if(degree <= 90) { return sintable[degree]; } - else if(degree <= 180) - { + else if(degree <= 180) { return sintable[180-degree]; } - else if(degree <= 270) - { + else if(degree <= 270) { return sintable[degree-180]*(-1.0); } - else - { + else { return sintable[360-degree]*(-1.0); } } -double getCos(unsigned int degree) -{ +double getCos(unsigned int degree) { degree = degree % 360; + return getSin(degree+90); } /* signum function */ -char sgn(char x){ +char sgn(char x) { return (x > 0) ? 1 : (x < 0) ? -1 : 0; } -unsigned char max(unsigned char a, unsigned char b) -{ +unsigned char max(unsigned char a, unsigned char b) { return (a<b) ? b : a; } -unsigned char min (unsigned char a, unsigned char b) -{ +unsigned char min (unsigned char a, unsigned char b) { return (a<b) ? a : b; } + diff --git a/glcd/fastMath.h b/glcd/fastMath.h index 674f2394..db4c7329 100644 --- a/glcd/fastMath.h +++ b/glcd/fastMath.h @@ -19,12 +19,13 @@ * Copyright: 2011 Roland Domke */ -#ifndef FASTMATH_H_ -#define FASTMATH_H_ +#ifndef FASTMATH_H +#define FASTMATH_H char sgn(char x); double getCos(unsigned int degree); double getSin(unsigned int degree); unsigned char max(unsigned char a, unsigned char b); unsigned char min(unsigned char a, unsigned char b); + #endif /* FASTMATH_H_ */ |