summaryrefslogtreecommitdiff
path: root/stage3/math.h
blob: 6f7ae58c7fe9a2e367d4bd836b5fee0437e2edaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef MATH_H
#define MATH_H

// for now, stuff will be added in this file as it is needed

#define PI 3.14159265358979323846

/*double get_pi()
{
	double pi;
	asm("fldpi; fstpl %0":"=m"(pi));
	return pi;
}*/

static inline double sin(double x)
{
	asm("fldl %1; fsin; fstpl %0":"=m"(x):"m"(x));
	return x;
}

static inline double rad(double x)
{
	return PI / 180.0 * x;
}

static inline double deg(double x)
{
	return 180.0 / PI * x;
}

static inline double fabs(double x)
{
	asm("fldl %1; fabs; fstpl %0":"=m"(x):"m"(x));
	return x;
}

static inline double atan2(double x, double y)
{
	asm("fldl %1; fldl %2; fpatan; fstpl %0":"=m"(x):"m"(x),"m"(y));
	return x;
}

static inline double sqrt(double x)
{
	asm("fldl %0; fsqrt; fstpl %0":"=m"(x):"m"(x));
	return x;
}

static inline double acos(double x)
{
	return atan2(sqrt(1-x*x),x);
}

static inline long ipow(long b, unsigned long exp)
{
	long x = 1;
	for (unsigned long i = 0; i < exp; i++)
		x *= b;
	return x;
}

#endif