Wrote wrapper macros for C interoperability.

This commit is contained in:
Adrien Guatto 2010-07-29 10:43:32 +02:00
parent e9da3c0313
commit 4de7ecac98
2 changed files with 22 additions and 68 deletions

View file

@ -1,32 +1,14 @@
#include <math.h>
#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)

View file

@ -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