-
Notifications
You must be signed in to change notification settings - Fork 59
/
mod.coffee
55 lines (42 loc) · 824 Bytes
/
mod.coffee
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
Eval_mod = ->
push(cadr(p1))
Eval()
push(caddr(p1))
Eval()
mod()
mod = ->
n = 0
save()
p2 = pop()
p1 = pop()
if (isZeroAtomOrTensor(p2))
stop("mod function: divide by zero")
if (!isNumericAtom(p1) || !isNumericAtom(p2))
push_symbol(MOD)
push(p1)
push(p2)
list(3)
restore()
return
if (isdouble(p1))
push(p1)
n = pop_integer()
if (isNaN(n))
stop("mod function: cannot convert float value to integer")
push_integer(n)
p1 = pop()
if (isdouble(p2))
push(p2)
n = pop_integer()
if (isNaN(n))
stop("mod function: cannot convert float value to integer")
push_integer(n)
p2 = pop()
if (!isinteger(p1) || !isinteger(p2))
stop("mod function: integer arguments expected")
p3 = new U()
p3.k = NUM
p3.q.a = mmod(p1.q.a, p2.q.a)
p3.q.b = mint(1)
push(p3)
restore()