From c842d90bbc5ab8f4fb88fb89ebb02c0c12051396 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 27 Jul 2016 22:51:11 -0700 Subject: 3158 --- html/067random.cc.html | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 html/067random.cc.html (limited to 'html/067random.cc.html') diff --git a/html/067random.cc.html b/html/067random.cc.html new file mode 100644 index 00000000..28cd2bf5 --- /dev/null +++ b/html/067random.cc.html @@ -0,0 +1,101 @@ + + + + +Mu - 067random.cc + + + + + + + + + + +
+:(before "End Primitive Recipe Declarations")
+REAL_RANDOM,
+:(before "End Primitive Recipe Numbers")
+put(Recipe_ordinal, "real-random", REAL_RANDOM);
+:(before "End Primitive Recipe Checks")
+case REAL_RANDOM: {
+  break;
+}
+:(before "End Primitive Recipe Implementations")
+case REAL_RANDOM: {
+  // todo: limited range of numbers, might be imperfectly random
+  // todo: thread state in extra ingredients and products
+  products.resize(1);
+  products.at(0).push_back(rand());
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+MAKE_RANDOM_NONDETERMINISTIC,
+:(before "End Primitive Recipe Numbers")
+put(Recipe_ordinal, "make-random-nondeterministic", MAKE_RANDOM_NONDETERMINISTIC);
+:(before "End Primitive Recipe Checks")
+case MAKE_RANDOM_NONDETERMINISTIC: {
+  break;
+}
+:(before "End Primitive Recipe Implementations")
+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>
+
+ + + -- cgit 1.4.1-2-gfad0