1 # spec/oil-expr-arith
2
3 #### Addition, with conversion from string
4
5 var i = 1 + 2
6
7 var j = ' 2.5 ' + ' 3'
8
9 var k = ' 5.0 ' - ' 2.5 '
10
11 var n = ' 2 ' * 3 * ' 4 '
12
13 write -- $i $j $k $n
14
15 ## STDOUT:
16 3
17 5.5
18 2.5
19 24
20 ## END
21
22
23 #### Floating Point Division with /
24
25 var i = '1.0' / '0.05'
26
27 echo $i
28
29 ## STDOUT:
30 20.0
31 ## END
32
33
34 #### Operations That Convert to Integer: // % **
35
36 var m = ' 5 ' // 2
37
38 var n = ' 5 ' % 2
39
40 var p = ' 5 ' ** 2
41
42 write -- $m $n $p
43
44 ## STDOUT:
45 2
46 1
47 25
48 ## END
49
50 #### Unary Operations
51
52 var a = ~1
53
54 var b = -1
55 var c = -2.3
56
57 var d = not true
58
59
60 write -- $a $b $c $d
61
62 ## STDOUT:
63 -2
64 -1
65 -2.3
66 false
67 ## END
68
69 #### unary ~ applied to bool is not allowed
70 = ~false
71 ## status: 3
72 ## STDOUT:
73 ## END
74
75 #### unary ~ applied to float is not allowed
76 = ~1.
77 ## status: 3
78 ## STDOUT:
79 ## END
80
81 #### unary - applied to bool is not allowed
82 = ~false
83 ## status: 3
84 ## STDOUT:
85 ## END
86
87 #### unary 'not' applied to int is not allowed
88 = not 1
89 ## status: 3
90 ## STDOUT:
91 ## END
92
93 #### unary 'not' applied to float is not allowed
94 = not 1.
95 ## status: 3
96 ## STDOUT:
97 ## END