diff options
| author | Flatmush <Flatmush@gmail.com> | 2012-07-25 14:49:11 +0000 |
|---|---|---|
| committer | Flatmush <Flatmush@gmail.com> | 2012-07-25 14:49:11 +0000 |
| commit | 85204f4a28009408c97bd49df8a205be4e80638e (patch) | |
| tree | 5dc84f5e738c4906dc3d612b01ce377377fc58d2 | |
| parent | bc77d6a3606f244d471681f1b9e6e75da65e7954 (diff) | |
| download | libfixmath-85204f4a28009408c97bd49df8a205be4e80638e.tar.gz | |
Updated coding style document.
Cleaned up some code.
| -rw-r--r-- | libfixmath/code_style.txt | 37 | ||||
| -rw-r--r-- | libfixmath/fix16_trig.c | 28 |
2 files changed, 51 insertions, 14 deletions
diff --git a/libfixmath/code_style.txt b/libfixmath/code_style.txt index 604566a..cb12373 100644 --- a/libfixmath/code_style.txt +++ b/libfixmath/code_style.txt @@ -190,7 +190,7 @@ Suffixes must be used for the various types: Enums must always be typedef'd. Enum values must be prefixed by the enum name. Structs which rely on ordering must use __attribute__((__packed__)). - +Unions must use __attribute__((__packed__)). Bitfields: - must always use __attribute__((__packed__)). - must always follow the GCC rules regarding bitfields. @@ -212,6 +212,7 @@ Examples: typedef struct vector_s vector_t; 2: union types_u + __attribute__((__packed__)) { int i; unsigned u; @@ -227,3 +228,37 @@ Examples: unsigned reserved : 2; unsigned alpha : 4; } img_desc_t; + + + +11.0 - MACROS + +Macros should only be used for condtional compilation and header protection +where this is possible. +For function like macros static inline functions should be defined. +For variable like macros static const variables should be defined. +For enums the enum type should always be used. + +Examples: +0: + static const unsigned max(unsigned x, unsigned y) + { return (x > y ? x : y); } +1: + static const float pi = 3.14152f; +2: + typedef enum + { + fuzzy_no = 0, + fuzzy_yes, + fuzzy_maybe, + } fuzzy_e; + +Counter-examples: +0: + #define MAX(x, y) ((x) > (y) ? (x) : (y)) +1: + #define PI 3.14152 +2: + #define FUZZY_NO 0 + #define FUZZY_YES 1 + #define FUZZY_MAYBE 2 diff --git a/libfixmath/fix16_trig.c b/libfixmath/fix16_trig.c index 864dc22..07c98bd 100644 --- a/libfixmath/fix16_trig.c +++ b/libfixmath/fix16_trig.c @@ -116,22 +116,22 @@ fix16_t fix16_tan(fix16_t inAngle) return fix16_sdiv(fix16_sin(inAngle), fix16_cos(inAngle));
}
-fix16_t fix16_asin(fix16_t inValue)
+fix16_t fix16_asin(fix16_t x)
{
- if((inValue > fix16_one)
- || (inValue < -fix16_one))
+ if((x > fix16_one)
+ || (x < -fix16_one))
return 0;
- fix16_t tempOut;
- tempOut = (fix16_one - fix16_mul(inValue, inValue));
- tempOut = fix16_div(inValue, fix16_sqrt(tempOut));
- tempOut = fix16_atan(tempOut);
- return tempOut;
+ fix16_t out;
+ out = (fix16_one - fix16_mul(x, x));
+ out = fix16_div(x, fix16_sqrt(out));
+ out = fix16_atan(out);
+ return out;
}
-fix16_t fix16_acos(fix16_t inValue)
+fix16_t fix16_acos(fix16_t x)
{
- return ((fix16_pi >> 1) - fix16_asin(inValue));
+ return ((fix16_pi >> 1) - fix16_asin(x));
}
fix16_t fix16_atan2(fix16_t inY , fix16_t inX)
@@ -158,7 +158,9 @@ fix16_t fix16_atan2(fix16_t inY , fix16_t inX) } else {
r = fix16_div( (inX + abs_inY), (abs_inY - inX));
r_3 = fix16_mul(fix16_mul(r, r),r);
- angle = fix16_mul(0x00003240 , r_3) - fix16_mul(0x0000FB50,r) + THREE_PI_DIV_4;
+ angle = fix16_mul(0x00003240 , r_3)
+ - fix16_mul(0x0000FB50,r)
+ + THREE_PI_DIV_4;
}
if (inY < 0)
{
@@ -174,7 +176,7 @@ fix16_t fix16_atan2(fix16_t inY , fix16_t inX) return angle;
}
-fix16_t fix16_atan(fix16_t inValue)
+fix16_t fix16_atan(fix16_t x)
{
- return fix16_atan2(inValue, fix16_one);
+ return fix16_atan2(x, fix16_one);
}
|
