diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-08-13 21:55:20 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-08-13 21:55:20 -0700 |
commit | 0e6a3c0d21006a31bf45138ca8e7470d97a0e139 (patch) | |
tree | 36d4a88076c548ab0ac3052575f06b3e98564565 | |
parent | f3c75c738f7d19b88111158900c777b895a0b94a (diff) | |
download | mu-0e6a3c0d21006a31bf45138ca8e7470d97a0e139.tar.gz |
3181
-rw-r--r-- | 022arithmetic.cc | 32 | ||||
-rw-r--r-- | 067random.cc | 32 |
2 files changed, 32 insertions, 32 deletions
diff --git a/022arithmetic.cc b/022arithmetic.cc index 6f1e4c1c..2d7e1436 100644 --- a/022arithmetic.cc +++ b/022arithmetic.cc @@ -684,3 +684,35 @@ def main [ 1:number <- flip-bits 12 ] +mem: storing -13 in location 1 + +:(before "End Primitive Recipe Declarations") +ROUND, +:(before "End Primitive Recipe Numbers") +put(Recipe_ordinal, "round", ROUND); +:(before "End Primitive Recipe Checks") +case ROUND: { + if (SIZE(inst.ingredients) != 1) { + raise << maybe(get(Recipe, r).name) << "'round' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); + break; + } + if (!is_mu_number(inst.ingredients.at(0))) { + raise << maybe(get(Recipe, r).name) << "first ingredient of 'round' should be a number, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + break; + } + break; +} +:(before "End Primitive Recipe Implementations") +case ROUND: { + products.resize(1); + products.at(0).push_back(rint(ingredients.at(0).at(0))); + break; +} + +:(scenario round_to_nearest_integer) +def main [ + 1:number <- round 12.2 +] ++mem: storing 12 in location 1 + +:(before "End Includes") +#include <math.h> diff --git a/067random.cc b/067random.cc index c9eaa4d1..ca02e01a 100644 --- a/067random.cc +++ b/067random.cc @@ -28,35 +28,3 @@ case MAKE_RANDOM_NONDETERMINISTIC: { srand(time(NULL)); break; } - -:(before "End Primitive Recipe Declarations") -ROUND, -:(before "End Primitive Recipe Numbers") -put(Recipe_ordinal, "round", ROUND); -:(before "End Primitive Recipe Checks") -case ROUND: { - if (SIZE(inst.ingredients) != 1) { - raise << maybe(get(Recipe, r).name) << "'round' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); - break; - } - if (!is_mu_number(inst.ingredients.at(0))) { - raise << maybe(get(Recipe, r).name) << "first ingredient of 'round' should be a number, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); - break; - } - break; -} -:(before "End Primitive Recipe Implementations") -case ROUND: { - products.resize(1); - products.at(0).push_back(rint(ingredients.at(0).at(0))); - break; -} - -:(scenario round_to_nearest_integer) -def main [ - 1:number <- round 12.2 -] -+mem: storing 12 in location 1 - -:(before "End Includes") -#include <math.h> |