about summary refs log tree commit diff stats
path: root/html/022arithmetic.cc.html
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-11-05 21:38:11 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-11-05 21:38:11 -0700
commit0aa6813b004c8003ff675f52850595bbcc2a66a9 (patch)
tree758d2097e65774aaaf8d55885d791d1d25fbf795 /html/022arithmetic.cc.html
parentcb48c5d79ca41d4b8d6f44f54cca53bfcb7b8670 (diff)
downloadmu-0aa6813b004c8003ff675f52850595bbcc2a66a9.tar.gz
3626
Diffstat (limited to 'html/022arithmetic.cc.html')
-rw-r--r--html/022arithmetic.cc.html35
1 files changed, 35 insertions, 0 deletions
diff --git a/html/022arithmetic.cc.html b/html/022arithmetic.cc.html
index b18bc7d2..e3474849 100644
--- a/html/022arithmetic.cc.html
+++ b/html/022arithmetic.cc.html
@@ -763,6 +763,41 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
 <span class="traceContains">+mem: storing -12 in location 1</span>
 
 <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
+TRUNCATE<span class="Delimiter">,</span>
+<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
+put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;truncate&quot;</span><span class="Delimiter">,</span> TRUNCATE<span class="Delimiter">);</span>
+<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
+<span class="Normal">case</span> TRUNCATE: <span class="Delimiter">{</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
+    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'truncate' requires exactly one ingredient, but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
+    <span class="Identifier">break</span><span class="Delimiter">;</span>
+  <span class="Delimiter">}</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
+    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;first ingredient of 'truncate' should be a number, but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
+    <span class="Identifier">break</span><span class="Delimiter">;</span>
+  <span class="Delimiter">}</span>
+  <span class="Identifier">break</span><span class="Delimiter">;</span>
+<span class="Delimiter">}</span>
+<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
+<span class="Normal">case</span> TRUNCATE: <span class="Delimiter">{</span>
+  products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>
+  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>trunc<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)));</span>
+  <span class="Identifier">break</span><span class="Delimiter">;</span>
+<span class="Delimiter">}</span>
+
+<span class="Delimiter">:(scenario truncate_to_nearest_integer)</span>
+<span class="muRecipe">def</span> main [
+  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>truncate <span class="Constant">12.2</span>
+]
+<span class="traceContains">+mem: storing 12 in location 1</span>
+
+<span class="Delimiter">:(scenario truncate_negative)</span>
+<span class="muRecipe">def</span> main [
+  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>truncate -<span class="Constant">12.2</span>
+]
+<span class="traceContains">+mem: storing -12 in location 1</span>
+
+<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
 CHARACTER_TO_CODE<span class="Delimiter">,</span>
 <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
 put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;character-to-code&quot;</span><span class="Delimiter">,</span> CHARACTER_TO_CODE<span class="Delimiter">);</span>
ision' href='/akkartik/mu/blame/html/077slurp.subx.html?h=hlt&id=22fb844ba4edf14eb85245a35f42e721658c4f8e'>^
695f9bf8 ^


33352536 ^

695f9bf8 ^


33352536 ^



695f9bf8 ^
33352536 ^

695f9bf8 ^


33352536 ^
695f9bf8 ^
33352536 ^


695f9bf8 ^

8aeb85f0 ^
33352536 ^

8aeb85f0 ^
33352536 ^
695f9bf8 ^
33352536 ^
695f9bf8 ^
33352536 ^
4a4a392d ^
695f9bf8 ^

33352536 ^
695f9bf8 ^
33352536 ^
695f9bf8 ^
33352536 ^




b1635a5c ^
33352536 ^

695f9bf8 ^







fa786ea7 ^
695f9bf8 ^
33352536 ^
695f9bf8 ^
33352536 ^

695f9bf8 ^










33352536 ^
8aeb85f0 ^
695f9bf8 ^
8aeb85f0 ^
999c529c ^





8aeb85f0 ^
999c529c ^














8aeb85f0 ^

999c529c ^







8aeb85f0 ^
999c529c ^
8aeb85f0 ^
999c529c ^





695f9bf8 ^



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222