2015-05-23 21:39:10 +00:00
: ( before " End Primitive Recipe Declarations " )
RANDOM ,
: ( before " End Primitive Recipe Numbers " )
2015-07-04 16:40:50 +00:00
Recipe_ordinal [ " random " ] = RANDOM ;
2015-05-23 21:39:10 +00:00
: ( before " End Primitive Recipe Implementations " )
case RANDOM : {
2015-05-23 21:58:14 +00:00
// todo: limited range of numbers, might be imperfectly random
2015-07-14 03:50:25 +00:00
// todo: thread state in extra ingredients and products
2015-05-23 21:39:10 +00:00
products . resize ( 1 ) ;
products . at ( 0 ) . push_back ( rand ( ) ) ;
break ;
}
: ( before " End Primitive Recipe Declarations " )
MAKE_RANDOM_NONDETERMINISTIC ,
: ( before " End Primitive Recipe Numbers " )
2015-07-04 16:40:50 +00:00
Recipe_ordinal [ " make-random-nondeterministic " ] = MAKE_RANDOM_NONDETERMINISTIC ;
2015-05-23 21:39:10 +00:00
: ( before " End Primitive Recipe Implementations " )
case MAKE_RANDOM_NONDETERMINISTIC : {
srand ( time ( NULL ) ) ;
break ;
}
: ( before " End Primitive Recipe Declarations " )
ROUND ,
: ( before " End Primitive Recipe Numbers " )
2015-07-04 16:40:50 +00:00
Recipe_ordinal [ " round " ] = ROUND ;
2015-05-23 21:39:10 +00:00
: ( before " End Primitive Recipe Implementations " )
case ROUND : {
2015-07-25 21:19:28 +00:00
if ( SIZE ( ingredients ) ! = 1 ) {
2015-10-01 20:13:10 +00:00
raise < < maybe ( current_recipe_name ( ) ) < < " 'round' requires exactly one ingredient, but got " < < current_instruction ( ) . to_string ( ) < < ' \n ' < < end ( ) ;
2015-07-25 21:19:28 +00:00
break ;
}
if ( ! scalar ( ingredients . at ( 0 ) ) ) {
2015-10-01 20:13:10 +00:00
raise < < maybe ( current_recipe_name ( ) ) < < " first ingredient of 'round' should be a number, but got " < < current_instruction ( ) . ingredients . at ( 0 ) . original_string < < ' \n ' < < end ( ) ;
2015-07-25 21:19:28 +00:00
break ;
}
2015-08-03 05:18:19 +00:00
products . resize ( 1 ) ;
2015-05-23 21:39:10 +00:00
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>