From 4de7ecac98d5d5aeb7919161a91f8f97c30c404b Mon Sep 17 00:00:00 2001 From: Adrien Guatto Date: Thu, 29 Jul 2010 10:43:32 +0200 Subject: [PATCH] Wrote wrapper macros for C interoperability. --- examples/MissionComputer_for_Core/mathext.c | 38 ++++----------- examples/MissionComputer_for_Core/mathext.h | 52 +++++---------------- 2 files changed, 22 insertions(+), 68 deletions(-) diff --git a/examples/MissionComputer_for_Core/mathext.c b/examples/MissionComputer_for_Core/mathext.c index fae22e7..19420cc 100644 --- a/examples/MissionComputer_for_Core/mathext.c +++ b/examples/MissionComputer_for_Core/mathext.c @@ -1,32 +1,14 @@ #include #include "mathext.h" -void atanr_step(float a, atanr_out *out) -{ - out->o = atan(a); -} +#define WRAP_FUN_DEF(FNAME, CNAME, TY_IN, TY_OUT) \ + void FNAME ## _step(TY_IN a, FNAME ## _out *out) { \ + out->o = CNAME(a); \ + } -void acosr_step(float a, acosr_out *out) -{ - out->o = acos(a); -} - -void cosr_step(float a, cosr_out *out) -{ - out->o = cos(a); -} - -void asinr_step(float a, asinr_out *out) -{ - out->o = asin(a); -} - -void sinr_step(float a, sinr_out *out) -{ - out->o = sin(a); -} - -void sqrtr_step(float a, sqrtr_out *out) -{ - out->o = sqrt(a); -} +WRAP_FUN_DEF(atanr, atan, float, float) +WRAP_FUN_DEF(acosr, acos, float, float) +WRAP_FUN_DEF(cosr, cos, float, float) +WRAP_FUN_DEF(asinr, asin, float, float) +WRAP_FUN_DEF(sinr, sin, float, float) +WRAP_FUN_DEF(sqrtr, sqrt, float, float) diff --git a/examples/MissionComputer_for_Core/mathext.h b/examples/MissionComputer_for_Core/mathext.h index 32eb3e8..1af29aa 100644 --- a/examples/MissionComputer_for_Core/mathext.h +++ b/examples/MissionComputer_for_Core/mathext.h @@ -1,46 +1,18 @@ #ifndef MATHEXT_H #define MATHEXT_H -/* atan(x) */ -typedef struct atanr_out { - float o; -} atanr_out; +#define WRAP_FUN_DECL(FNAME, TY_IN, TY_OUT) \ + typedef struct { \ + TY_OUT o; \ + } FNAME ## _out; \ + \ + void FNAME ## _step(TY_IN, FNAME ## _out *) -void atanr_step(float a, atanr_out *o); - -/* acos(x) */ -typedef struct acosr_out { - float o; -} acosr_out; - -void acosr_step(float a, acosr_out *o); - -/* cos(x) */ -typedef struct cosr_out { - float o; -} cosr_out; - -void cosr_step(float a, cosr_out *o); - -/* asin(x) */ -typedef struct asinr_out { - float o; -} asinr_out; - -void asinr_step(float a, asinr_out *o); - -/* sin(x) */ -typedef struct sinr_out { - float o; -} sinr_out; - -void sinr_step(float a, sinr_out *o); - -/* sin(x) */ -typedef struct sqrtr_out { - float o; -} sqrtr_out; - -void sqrtr_step(float a, sqrtr_out *o); +WRAP_FUN_DECL(atanr, float, float); +WRAP_FUN_DECL(acosr, float, float); +WRAP_FUN_DECL(cosr, float, float); +WRAP_FUN_DECL(asinr, float, float); +WRAP_FUN_DECL(sinr, float, float); +WRAP_FUN_DECL(sqrtr, float, float); #endif