summaryrefslogtreecommitdiff
path: root/stage3/math.h
blob: b06740975b8474496caf37ca539debeae2a54af0 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#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 cos(double x)
{
	asm("fldl %1; fcos; fstpl %0":"=m"(x):"m"(x));
	return x;
}

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

static inline void sincos(double x, double *sin, double *cos)
{
	asm("fldl %2; fsincos; fstpl %0; fstpl %1":"=m"(*sin),"=m"(*cos):"m"(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