diff --git a/lib/Makefile b/lib/Makefile index 6d1548e..6189853 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,10 +1,10 @@ include ../config -STDLIB_INTERFACE=pervasives.epi iostream.epi +STDLIB_INTERFACE=pervasives.epi iostream.epi math.epi STDLIB_OBJ=$(STDLIB_INTERFACE:.epi=.epci) C_DIR=c -C_OBJ=pervasives.h +C_OBJ=pervasives.h math.h math.c .SUFFIXES: .epi .epci diff --git a/lib/c/math.c b/lib/c/math.c new file mode 100644 index 0000000..4668283 --- /dev/null +++ b/lib/c/math.c @@ -0,0 +1,51 @@ + +#include +#include +#include +#include "math.h" +#include + +void Math__float_step(int x, Math__float_out* _out) { + _out->y = (float)x; +} + +void Math__ceil_step(float x, Math__ceil_out* _out) { + _out->y = ceilf(x); +} + +void Math__floor_step(float x, Math__floor_out* _out) { + _out->y = floorf(x); +} + +void Math__sin_step(float x, Math__sin_out* _out) { + _out->y = sinf(x); +} + +void Math__cos_step(float x, Math__cos_out* _out) { + _out->y = cosf(x); +} + +void Math__tan_step(float x, Math__tan_out* _out) { + _out->y = tanf(x); +} + +void Math__asin_step(float x, Math__asin_out* _out) { + _out->y = asinf(x); +} + +void Math__acos_step(float x, Math__acos_out* _out) { + _out->y = acosf(x); +} + +void Math__atan_step(float x, Math__atan_out* _out) { + _out->y = atanf(x); +} + +void Math__min_float_step(float x, float y, Math__min_float_out* _out) { + _out->z = (x < y)? x : y; +} + +void Math__max_float_step(float x, float y, Math__max_float_out* _out) { + _out->z = (x > y)? x : y; +} + diff --git a/lib/c/math.h b/lib/c/math.h new file mode 100644 index 0000000..2771dec --- /dev/null +++ b/lib/c/math.h @@ -0,0 +1,72 @@ + +#ifndef MATH_H +#define MATH_H + + +typedef struct Math__float_out { + float y; +} Math__float_out; + +void Math__float_step(int x, Math__float_out* _out); + +typedef struct Math__ceil_out { + float y; +} Math__ceil_out; + +void Math__ceil_step(float x, Math__ceil_out* _out); + +typedef struct Math__floor_out { + float y; +} Math__floor_out; + +void Math__floor_step(float x, Math__floor_out* _out); + +typedef struct Math__sin_out { + float y; +} Math__sin_out; + +void Math__sin_step(float x, Math__sin_out* _out); + +typedef struct Math__cos_out { + float y; +} Math__cos_out; + +void Math__cos_step(float x, Math__cos_out* _out); + +typedef struct Math__tan_out { + float y; +} Math__tan_out; + +void Math__tan_step(float x, Math__tan_out* _out); + +typedef struct Math__asin_out { + float y; +} Math__asin_out; + +void Math__asin_step(float x, Math__asin_out* _out); + +typedef struct Math__acos_out { + float y; +} Math__acos_out; + +void Math__acos_step(float x, Math__acos_out* _out); + +typedef struct Math__atan_out { + float y; +} Math__atan_out; + +void Math__atan_step(float x, Math__atan_out* _out); + +typedef struct Math__min_float_out { + float z; +} Math__min_float_out; + +void Math__min_float_step(float x, float y, Math__min_float_out* _out); + +typedef struct Math__max_float_out { + float z; +} Math__max_float_out; + +void Math__max_float_step(float x, float y, Math__max_float_out* _out); + +#endif // MATH_H diff --git a/lib/math.epi b/lib/math.epi new file mode 100644 index 0000000..174b4fd --- /dev/null +++ b/lib/math.epi @@ -0,0 +1,19 @@ + +(* int to float conversion (truncation) *) +external val fun float(x:int) returns (y:float) + +(* float operations *) +external val fun ceil(x:float) returns (y:float) + +external val fun floor(x:float) returns (y:float) + +external val fun sin(x:float) returns (y:float) +external val fun cos(x:float) returns (y:float) +external val fun tan(x:float) returns (y:float) +external val fun asin(x:float) returns (y:float) +external val fun acos(x:float) returns (y:float) +external val fun atan(x:float) returns (y:float) + +external val fun min_float(x:float;y:float) returns (z:float) +external val fun max_float(x:float;y:float) returns (z:float) +