UNPKG

1.95 kBtext/coffeescriptView Raw
1
2
3Eval_float = ->
4 evaluatingAsFloats++
5 push(cadr(p1))
6 Eval()
7 yyfloat()
8 Eval(); # normalize
9 evaluatingAsFloats--
10
11checkFloatHasWorkedOutCompletely = (nodeToCheck) ->
12 numberOfPowers = countOccurrencesOfSymbol(symbol(POWER),nodeToCheck)
13 numberOfPIs = countOccurrencesOfSymbol(symbol(PI),nodeToCheck)
14 numberOfEs = countOccurrencesOfSymbol(symbol(E),nodeToCheck)
15 numberOfMults = countOccurrencesOfSymbol(symbol(MULTIPLY),nodeToCheck)
16 numberOfSums = countOccurrencesOfSymbol(symbol(ADD),nodeToCheck)
17 if DEBUG
18 console.log " ... numberOfPowers: " + numberOfPowers
19 console.log " ... numberOfPIs: " + numberOfPIs
20 console.log " ... numberOfEs: " + numberOfEs
21 console.log " ... numberOfMults: " + numberOfMults
22 console.log " ... numberOfSums: " + numberOfSums
23 if numberOfPowers > 1 or numberOfPIs > 0 or numberOfEs > 0 or numberOfMults > 1 or numberOfSums > 1
24 stop("float: some unevalued parts in " + nodeToCheck)
25
26zzfloat = ->
27 save()
28 evaluatingAsFloats++
29 #p1 = pop()
30 #push(cadr(p1))
31 #push(p1)
32 Eval()
33 yyfloat()
34 Eval(); # normalize
35 evaluatingAsFloats--
36 restore()
37 # zzfloat doesn't necessarily result in a double
38 # , for example if there are variables. But
39 # in many of the tests there should be indeed
40 # a float, this line comes handy to highlight
41 # when that doesn't happen for those tests.
42 #checkFloatHasWorkedOutCompletely(stack[tos-1])
43
44yyfloat = ->
45 i = 0
46 h = 0
47 evaluatingAsFloats++
48 save()
49 p1 = pop()
50 if (iscons(p1))
51 h = tos
52 while (iscons(p1))
53 push(car(p1))
54 yyfloat()
55 p1 = cdr(p1)
56 list(tos - h)
57 else if (p1.k == TENSOR)
58 push(p1)
59 copy_tensor()
60 p1 = pop()
61 for i in [0...p1.tensor.nelem]
62 push(p1.tensor.elem[i])
63 yyfloat()
64 p1.tensor.elem[i] = pop()
65 push(p1)
66 else if (p1.k == NUM)
67 push(p1)
68 bignum_float()
69 else if (p1 == symbol(PI))
70 push_double(Math.PI)
71 else if (p1 == symbol(E))
72 push_double(Math.E)
73 else
74 push(p1)
75 restore()
76 evaluatingAsFloats--
77