2015-08-02 00:08:58 +02:00
|
|
|
//IO library
|
|
|
|
#ifndef INCLUDE_MATH_H
|
|
|
|
#define INCLUDE_MATH_H
|
2015-08-04 17:48:36 +02:00
|
|
|
#print "[include <math.h>]\n"
|
2015-08-02 00:08:58 +02:00
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
:struct MATH
|
|
|
|
{
|
|
|
|
float pi();
|
|
|
|
float cos(float x);
|
|
|
|
float sin(float x);
|
|
|
|
float sqrt(float x);
|
|
|
|
float tan(float x);
|
|
|
|
float abs(float x);
|
2015-08-17 02:16:17 +02:00
|
|
|
float floor(float x);
|
|
|
|
signed round(float x);
|
|
|
|
signed ceil(float x);
|
2017-10-11 00:26:56 +02:00
|
|
|
signed min(signed i1, i2);
|
|
|
|
signed max(signed i1, i2);
|
2018-05-06 17:03:12 +02:00
|
|
|
signed in(signed base, min1, max1);
|
2015-08-02 00:08:58 +02:00
|
|
|
}math;
|
2017-10-11 00:26:56 +02:00
|
|
|
|
2015-08-17 02:16:17 +02:00
|
|
|
:signed MATH::round(float x)
|
|
|
|
{
|
|
|
|
x+=0.6;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
:signed MATH::ceil(float x)
|
|
|
|
{
|
|
|
|
dword z;
|
|
|
|
float tmp;
|
|
|
|
z = x;
|
|
|
|
tmp = z;
|
|
|
|
IF(tmp<x)z++;
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
:float MATH::floor(float x)
|
|
|
|
{
|
|
|
|
signed long z;
|
|
|
|
z = x;
|
|
|
|
IF(z==x)return x;
|
|
|
|
IF(z<0) return z-1;
|
|
|
|
return z;
|
|
|
|
}
|
2015-08-02 00:08:58 +02:00
|
|
|
:float MATH::abs(float x)
|
|
|
|
{
|
|
|
|
IF(x<0)return -x;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
:float MATH::cos(float x)
|
|
|
|
{
|
|
|
|
float r;
|
|
|
|
asm
|
|
|
|
{
|
|
|
|
fld x
|
|
|
|
fcos
|
|
|
|
fstp r
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
:float MATH::sin(float x)
|
|
|
|
{
|
|
|
|
float r;
|
|
|
|
asm
|
|
|
|
{
|
|
|
|
fld x
|
|
|
|
fsin
|
|
|
|
fstp r
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
:float MATH::sqrt(float x)
|
|
|
|
{
|
|
|
|
float r;
|
|
|
|
asm
|
|
|
|
{
|
|
|
|
fld x
|
|
|
|
fsqrt
|
|
|
|
fstp r
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
:float MATH::tan(float x)
|
|
|
|
{
|
|
|
|
float r;
|
|
|
|
asm
|
|
|
|
{
|
|
|
|
fld x
|
|
|
|
fld1
|
|
|
|
fpatan
|
|
|
|
fstp r
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2017-10-11 00:26:56 +02:00
|
|
|
:signed MATH::min(signed i1, i2)
|
|
|
|
{
|
|
|
|
if (i1 < i2)
|
|
|
|
return i1;
|
|
|
|
else
|
|
|
|
return i2;
|
|
|
|
}
|
|
|
|
:signed MATH::max(signed i1, i2)
|
|
|
|
{
|
|
|
|
if (i1 > i2)
|
|
|
|
return i1;
|
|
|
|
else
|
|
|
|
return i2;
|
|
|
|
}
|
2018-05-06 17:03:12 +02:00
|
|
|
:signed MATH::in(signed base, min1, max1)
|
|
|
|
{
|
|
|
|
if (base > max1) return max1;
|
|
|
|
if (base < min1) return min1;
|
|
|
|
return base;
|
|
|
|
}
|
2015-08-02 00:08:58 +02:00
|
|
|
#endif
|