Math module

The Math module contains mathematic functions.
This commit is contained in:
Gwenaël Delaval 2015-09-17 16:51:24 +02:00
parent f720c1844f
commit 015875b279
4 changed files with 144 additions and 2 deletions

View file

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

51
lib/c/math.c Normal file
View file

@ -0,0 +1,51 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "math.h"
#include <math.h>
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;
}

72
lib/c/math.h Normal file
View file

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

19
lib/math.epi Normal file
View file

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