about summary refs log blame commit diff stats
path: root/064random.cc
blob: de304714121ba460079c6528ef9e9725c815f14e (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                             
                                  



                                       

                                                
                                                                
                                                         
                     






                                             
                                                                              



                                       








                                                
                                
                                       
             

                                                                                                                               

          

                                                                                                                                                            

          



                                                
                     











                                                          
:(before "End Primitive Recipe Declarations")
RANDOM,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["random"] = RANDOM;
:(before "End Primitive Recipe Checks")
case RANDOM: {
  break;
}
:(before "End Primitive Recipe Implementations")
case 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")
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")
Recipe_ordinal["round"] = ROUND;
:(before "End Primitive Recipe Checks")
case ROUND: {
  if (SIZE(inst.ingredients) != 1) {
    raise << maybe(Recipe[r].name) << "'round' requires exactly one ingredient, but got " << inst.to_string() << '\n' << end();
    break;
  }
  if (!is_mu_scalar(inst.ingredients.at(0))) {
    raise << maybe(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)
recipe main [
  1:number <- round 12.2
]
+mem: storing 12 in location 1

:(before "End Includes")
#include<math.h>