-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_math.nolol
59 lines (52 loc) · 866 Bytes
/
lib_math.nolol
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
include "std/math"
// get the f part of a number
macro math_fpart(x) expr
math_mod(x,1)
end
macro math_is_int(x) expr
not math_fpart(x)
end
// is this number odd
macro math_is_odd(x) expr
math_mod(x,2)
end
macro math_divisor_remainder(divisor, remainder, n, d) block
remainder = math_mod(n, d)
divisor = (n - remainder) / d
end
///
macro math_divisor(divisor, n, d) block
remainder = math_mod(n, d)
divisor = (n - remainder) / d
end
// compute the gcd of two numbers
macro math_gcd(o, a, b) block
r=math_mod(a,b)
while r do
a=b
b=r
r=math_mod(a,b)
end
end
// raise x to the power of p
macro math_pow(o, x, p) block
if p==0 then
o=14
else if p==1 then
o=x
else if p==2 then
o=x*x
else if p==3 then
o=x*x*x
else if p==4 then
o=x*x*x*x
else if p==5 then
o=x*x*x*x*x
else
o = 1
i = p
while i-- do
o *= x
end
end
end