File: eval.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (80 lines) | stat: -rw-r--r-- 3,188 bytes parent folder | download | duplicates (4)
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
80
#+begin_src cfengine3
body common control
{
      bundlesequence => { run };
}
body agent control
{
        inform => "true";
}
bundle agent run
{
  vars:
      "values[0]" string => "x"; # bad
      "values[1]" string => "+ 200"; # bad
      "values[2]" string => "200 + 100";
      "values[3]" string => "200 - 100";
      "values[4]" string => "- - -"; # bad
      "values[5]" string => "2 + 3 - 1";
      "values[6]" string => ""; # 0
      "values[7]" string => "3 / 0"; # inf but not an error
      "values[8]" string => "3^3";
      # "values[9]" string => "-1^2.1"; # 'nan' or '-nan' (on some platforms)
      "values[10]" string => "sin(20)";
      "values[11]" string => "cos(20)";
      "values[19]" string => "20 % 3"; # remainder
      "values[20]" string => "sqrt(0.2)";
      "values[21]" string => "ceil(3.5)";
      "values[22]" string => "floor(3.4)";
      "values[23]" string => "abs(-3.4)";
      "values[24]" string => "-3.4 == -3.4";
      "values[25]" string => "-3.400000 == -3.400001";
      "values[26]" string => "e";
      "values[27]" string => "pi";
      "values[28]" string => "100m"; # 100 million
      "values[29]" string => "100k"; # 100 thousand

      "indices" slist => sort( getindices("values"), int);

      "eval[$(indices)]" string => eval("$(values[$(indices)])", "math", "infix");

  reports:
      "math/infix eval('$(values[$(indices)])') = '$(eval[$(indices)])'";
}
#+end_src
###############################################################################
#+begin_src example_output
#@ ```
#@     info: eval error: expression could not be parsed (input 'x')
#@     info: eval error: expression could not be parsed (input '+ 200')
#@     info: eval error: expression could not be parsed (input '- - -')
#@ R: math/infix eval('x') = ''
#@ R: math/infix eval('+ 200') = ''
#@ R: math/infix eval('200 + 100') = '300.000000'
#@ R: math/infix eval('200 - 100') = '100.000000'
#@ R: math/infix eval('- - -') = ''
#@ R: math/infix eval('2 + 3 - 1') = '4.000000'
#@ R: math/infix eval('') = '0.000000'
#@ R: math/infix eval('3 / 0') = 'inf'
#@ R: math/infix eval('3^3') = '27.000000'
#@ R: math/infix eval('sin(20)') = '0.912945'
#@ R: math/infix eval('cos(20)') = '0.408082'
#@ R: math/infix eval('20 % 3') = '2.000000'
#@ R: math/infix eval('sqrt(0.2)') = '0.447214'
#@ R: math/infix eval('ceil(3.5)') = '4.000000'
#@ R: math/infix eval('floor(3.4)') = '3.000000'
#@ R: math/infix eval('abs(-3.4)') = '3.400000'
#@ R: math/infix eval('-3.4 == -3.4') = '1.000000'
#@ R: math/infix eval('-3.400000 == -3.400001') = '0.000000'
#@ R: math/infix eval('e') = '2.718282'
#@ R: math/infix eval('pi') = '3.141593'
#@ R: math/infix eval('100m') = '100000000.000000'
#@ R: math/infix eval('100k') = '100000.000000'
#@     info: eval error: expression could not be parsed (input 'x')
#@     info: eval error: expression could not be parsed (input '+ 200')
#@     info: eval error: expression could not be parsed (input '- - -')
#@     info: eval error: expression could not be parsed (input 'x')
#@     info: eval error: expression could not be parsed (input '+ 200')
#@     info: eval error: expression could not be parsed (input '- - -')
#@ ```
#+end_src