Subversion Repositories Kolibri OS

Rev

Rev 7086 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5640 pavelyakov 1
//IO library
2
#ifndef INCLUDE_MATH_H
3
#define INCLUDE_MATH_H
5676 pavelyakov 4
#print "[include ]\n"
5640 pavelyakov 5
 
6
#ifndef INCLUDE_KOLIBRI_H
7
#include "../lib/kolibri.h"
8
#endif
9
 
10
:struct MATH
11
{
12
	float pi();
13
	float cos(float x);
14
	float sin(float x);
15
	float sqrt(float x);
16
	float tan(float x);
17
	float abs(float x);
5730 pavelyakov 18
	float floor(float x);
19
	signed round(float x);
20
	signed ceil(float x);
7086 leency 21
	signed min(signed i1, i2);
22
	signed max(signed i1, i2);
7272 leency 23
	signed in(signed base, min1, max1);
5640 pavelyakov 24
}math;
7086 leency 25
 
5730 pavelyakov 26
:signed MATH::round(float x)
27
{
28
	x+=0.6;
29
	return x;
30
}
31
:signed MATH::ceil(float x)
32
{
33
	dword z;
34
	float tmp;
35
	z = x;
36
	tmp = z;
37
	IF(tmp
38
	return z;
39
}
40
:float MATH::floor(float x)
41
{
42
	signed long z;
43
	z = x;
44
	IF(z==x)return x;
45
	IF(z<0) return z-1;
46
	return z;
47
}
5640 pavelyakov 48
:float MATH::abs(float x)
49
{
50
	IF(x<0)return -x;
51
	return x;
52
}
53
 
54
:float MATH::cos(float x)
55
{
56
	float r;
57
	asm
58
	{
59
		fld x
60
		fcos
61
		fstp r
62
	}
63
	return r;
64
}
65
:float MATH::sin(float x)
66
{
67
	float r;
68
	asm
69
	{
70
		fld x
71
		fsin
72
		fstp r
73
	}
74
	return r;
75
}
76
:float MATH::sqrt(float x)
77
{
78
	float r;
79
	asm
80
	{
81
		fld x
82
		fsqrt
83
		fstp r
84
	}
85
	return r;
86
}
87
:float MATH::tan(float x)
88
{
89
	float r;
90
	asm
91
	{
92
		fld x
93
		fld1
94
		fpatan
95
		fstp r
96
	}
97
	return r;
98
}
7086 leency 99
:signed MATH::min(signed i1, i2)
100
{
101
	if (i1 < i2)
102
		return i1;
103
	else
104
		return i2;
105
}
106
:signed MATH::max(signed i1, i2)
107
{
108
	if (i1 > i2)
109
		return i1;
110
	else
111
		return i2;
112
}
7272 leency 113
:signed MATH::in(signed base, min1, max1)
114
{
115
	if (base > max1) return max1;
116
	if (base < min1) return min1;
117
	return base;
118
}
5640 pavelyakov 119
#endif