diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-11-05 21:38:11 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-11-05 21:38:11 -0700 |
commit | 0aa6813b004c8003ff675f52850595bbcc2a66a9 (patch) | |
tree | 758d2097e65774aaaf8d55885d791d1d25fbf795 /html/022arithmetic.cc.html | |
parent | cb48c5d79ca41d4b8d6f44f54cca53bfcb7b8670 (diff) | |
download | mu-0aa6813b004c8003ff675f52850595bbcc2a66a9.tar.gz |
3626
Diffstat (limited to 'html/022arithmetic.cc.html')
-rw-r--r-- | html/022arithmetic.cc.html | 35 |
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 "End Primitive Recipe Declarations")</span> +TRUNCATE<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"truncate"</span><span class="Delimiter">,</span> TRUNCATE<span class="Delimiter">);</span> +<span class="Delimiter">:(before "End Primitive Recipe Checks")</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 << 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> << <span class="Constant">"'truncate' requires exactly one ingredient, but got '"</span> << inst<span class="Delimiter">.</span>original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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 << 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> << <span class="Constant">"first ingredient of 'truncate' should be a number, but got '"</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>original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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 "End Primitive Recipe Implementations")</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"> <- </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"> <- </span>truncate -<span class="Constant">12.2</span> +] +<span class="traceContains">+mem: storing -12 in location 1</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> CHARACTER_TO_CODE<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"character-to-code"</span><span class="Delimiter">,</span> CHARACTER_TO_CODE<span class="Delimiter">);</span> |