about summary refs log blame commit diff stats
path: root/sandbox/008-sandbox-edit.mu
blob: 42778faab846d78141a7515d744c1f66a19ae94a (plain) (tree)
">,</span> <span class="Constant">3</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal ] <span class="traceContains">+mem: storing 2 in location 1</span> <span class="Comment">//: Integer division</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span> DIVIDE_WITH_REMAINDER<span class="Delimiter">,</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span> Recipe_number[<span class="Constant">&quot;divide-with-remainder&quot;</span>] = DIVIDE_WITH_REMAINDER<span class="Delimiter">;</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span> case DIVIDE_WITH_REMAINDER: <span class="Delimiter">{</span> long long int quotient = 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> / ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> long long int remainder = static_cast&lt;long long int&gt;<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> % static_cast&lt;long long int&gt;<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span> <span class="Comment">// very large integers will lose precision</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>quotient<span class="Delimiter">);</span> products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>remainder<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario divide_with_remainder_literal)</span> recipe main [ <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>divide-with-remainder <span class="Constant">9</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal ] <span class="traceContains">+run: instruction main/0</span> <span class="traceContains">+run: ingredient 0 is 9</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+run: product 0 is 1</span> <span class="traceContains">+mem: storing 4 in location 1</span> <span class="traceContains">+run: product 1 is 2</span> <span class="traceContains">+mem: storing 1 in location 2</span> <span class="Delimiter">:(scenario divide_with_remainder)</span> recipe main [ <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">27</span>:literal <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">11</span>:literal <span class="Constant">3</span>:number<span class="Delimiter">,</span> <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>divide-with-remainder <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number ] <span class="traceContains">+run: instruction main/2</span> <span class="traceContains">+run: ingredient 0 is 1</span> <span class="traceContains">+mem: location 1 is 27</span> <span class="traceContains">+run: ingredient 1 is 2</span> <span class="traceContains">+mem: location 2 is 11</span> <span class="traceContains">+run: product 0 is 3</span> <span class="traceContains">+mem: storing 2 in location 3</span> <span class="traceContains">+run: product 1 is 4</span> <span class="traceContains">+mem: storing 5 in location 4</span> <span class="Delimiter">:(scenario divide_with_decimal_point)</span> recipe main [ <span class="Comment"># todo: literal floats?</span> <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>divide <span class="Constant">5</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal ] <span class="traceContains">+mem: storing 2.5 in location 1</span> </pre> </body> </html> <!-- vim: set foldmethod=manual : -->