File: math-funcs.bc

package info (click to toggle)
nickle 2.107
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,756 kB
  • sloc: ansic: 27,954; yacc: 1,874; lex: 954; sh: 204; makefile: 13; lisp: 1
file content (70 lines) | stat: -rw-r--r-- 871 bytes parent folder | download | duplicates (2)
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
scale = 100

p = 4*a(1)

/* arcsin */
define b(x) {
	auto v;
	if (x < -1.0 || x > 1.0)
		return (10000);
	if (x == -1)
		return (-p/2);
	if (x == 1)
		return (p/2);
	v = a(x / sqrt(1 - x * x));
	if (v < -p/2) v += p;
	return (v);
}

/* arccos */
define d(x) {
	auto v;
	if (x < -1.0 || x > 1.0)
		return (10000);
	if (x == 0)
		return(p/2);
	if (x == -1)
		return p;
	v = a(sqrt(1 - x * x) / x);
	if (v < 0) v += p;
	return (v);
}

/* tan */
define t(x) {
	auto v, w, u;
	v = s(x);
	w = c(x);
	u = w;
	if (u < 0)
		u = -u;
	if (u < .1^20)
		return (9999);
	if (w == 0)
		return (10000);
	return (v / w);
}

/* atan2 */
define u(y, x) {
	auto w;
	if (y == 0) {
		if (x < 0)
			return (p);
		return 0;
	}
	if (x == 0) {
		if (y < 0)
			return (-p/2);
		return (p/2);
	}
	w = a(y/x);
	if (y < 0) {
		if (x < 0)
			w -= p;
	} else {
		if (x < 0)
			w += p;
	}
	return (w);
}