Subversion Repositories Kolibri OS

Rev

Rev 7086 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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