1 #include <portability.h>
49 for (c=args; c!=
NIL; c=c->
rest) {
64 if (float_found) f += arg->
ic.
value;
67 if (float_found) f += arg->
fc.
value;
90 for (c=args; c!=
NIL; c=c->
rest) {
105 if (float_found) f *= arg->
ic.
value;
108 if (float_found) f *= arg->
fc.
value;
109 else { float_found =
TRUE; f = arg->
fc.
value * i; }
134 print (thisAgent,
"Error: '-' function called with no arguments\n");
138 for (c=args; c!=
NIL; c=c->
rest) {
164 if (float_found) f -= arg->
ic.
value;
167 if (float_found) f -= arg->
fc.
value;
168 else { float_found =
TRUE; f = i - arg->
fc.
value; }
191 print (thisAgent,
"Error: '/' function called with no arguments\n");
195 for (c=args; c!=
NIL; c=c->
rest) {
211 print (thisAgent,
"Error: attempt to divide ('/') by zero.\n");
223 else {
print (thisAgent,
"Error: attempt to divide ('/') by zero.\n");
return NIL; }
226 else {
print (thisAgent,
"Error: attempt to divide ('/') by zero.\n");
return NIL; }
256 print (thisAgent,
"Error: attempt to divide ('div') by zero.\n");
290 print (thisAgent,
"Error: attempt to divide ('mod') by zero.\n");
311 print(thisAgent,
"Error: 'sin' function called with no arguments\n");
319 arg_value =
static_cast<double>(arg->
ic.
value) ;
321 print_with_symbols(thisAgent,
"Error: 'sin' function called with non-numeric argument %y\n", arg);
340 print(thisAgent,
"Error: 'cos' function called with no arguments\n");
348 arg_value =
static_cast<double>(arg->
ic.
value) ;
350 print_with_symbols(thisAgent,
"Error: 'cos' function called with non-numeric argument %y\n", arg);
368 print(thisAgent,
"Error: 'sqrt' function called with no arguments\n");
376 arg_value =
static_cast<double>(arg->
ic.
value);
378 print_with_symbols(thisAgent,
"Error: 'sqrt' function called with non-numeric argument %y\n", arg);
399 print(thisAgent,
"Error: 'atan2' function called with no arguments\n");
403 for (c=args; c!=
NIL; c=c->
rest) {
414 print(thisAgent,
"Error: 'atan2' function called with only one argument\n");
422 numer_value =
static_cast<double>(arg->
ic.
value) ;
426 print(thisAgent,
"Error: 'atan2' function called with more than two arguments.\n");
433 denom_value =
static_cast<double>(arg->
ic.
value) ;
450 print(thisAgent,
"Error: 'abs' function called with no arguments\n");
460 print_with_symbols(thisAgent,
"Error: 'abs' function called with non-numeric argument %y\n", arg);
479 print (thisAgent,
"Error: 'int' function called with no arguments.\n");
484 print (thisAgent,
"Error: 'int' takes exactly 1 argument.\n");
490 print_with_symbols (thisAgent,
"Error: variable (%y) passed to 'int' RHS function.\n",
494 print_with_symbols (thisAgent,
"Error: identifier (%y) passed to 'int' RHS function.\n",
503 print (thisAgent,
"Error: bad integer (%y) given to 'int' RHS function\n",
513 modf(sym->
fc.
value, &int_part);
517 print (thisAgent,
"Error: unknown symbol type (%y) given to 'int' RHS function\n",
535 print (thisAgent,
"Error: 'float' function called with no arguments.\n");
540 print (thisAgent,
"Error: 'float' takes exactly 1 argument.\n");
546 print_with_symbols (thisAgent,
"Error: variable (%y) passed to 'float' RHS function.\n",
550 print_with_symbols (thisAgent,
"Error: identifier (%y) passed to 'float' RHS function.\n",
559 print (thisAgent,
"Error: bad float (%y) given to 'float' RHS function\n",
571 print (thisAgent,
"Error: unknown symbol type (%y) given to 'float' RHS function\n",
616 int64_t unbounded_rounded;
620 unbounded_rounded = m * ((n - (m / 2L)) / m);
622 unbounded_rounded = m * ((n + (m / 2L)) / m);
624 return unbounded_rounded;
629 double n_10, m_10, unbounded_rounded;
635 modf((n * 10.0), &ip);
637 modf((m * 10.0), &ip);
642 modf((m_10 / 2.0), &ip2);
643 modf(((n_10 - ip2) / m_10), &ip);
644 unbounded_rounded = (m_10 * ip);
647 modf((m_10 / 2.0), &ip2);
648 modf(((n_10 + ip2) / m_10), &ip);
649 unbounded_rounded = (m_10 * ip);
653 return unbounded_rounded / 10.0;
659 double n = 0, f_m = 0;
662 bool float_found =
FALSE;
665 print(thisAgent,
"Error: 'round_off_heading' function called with no arguments\n");
671 print(thisAgent,
"Error: 'round_off_heading' function called with only one argument.\n");
678 n =
static_cast<double>(arg->
ic.
value) ;
686 print(thisAgent,
"Error: 'round_off_heading' function called with more than two arguments.\n");
715 double n = 0, f_m = 0;
718 bool float_found =
FALSE;
721 print(thisAgent,
"Error: 'round_off' function called with no arguments\n");
727 print(thisAgent,
"Error: 'round_off' function called with only one argument.\n");
734 n =
static_cast<double>(arg->
ic.
value) ;
742 print(thisAgent,
"Error: 'round_off' function called with more than two arguments.\n");
760 #define PI 3.141592653589
761 #define PI_OVER_TWO (PI/2)
762 #define TWO_PI (PI*2)
763 #define RAD_TO_DEG(X) ((X*180)/PI)
770 vector[
X] = pos2[
X] - pos1[
X];
771 vector[
Y] = pos2[
Y] - pos1[
Y];
772 vector[
Z] = pos2[
Z] - pos1[
Z];
778 mag2 = v[
X] * v[
X] + v[
Y] * v[
Y];
780 if (!abort && (mag < 0.01)) {
797 heading =
TWO_PI - heading;
806 double heading_in_rads;
810 (*output) = heading_in_rads;
815 int64_t unbounded_rounded, bounded_rounded;
819 unbounded_rounded = m * ((n - (m / 2L)) / m);
821 unbounded_rounded = m * ((n + (m / 2L)) / m);
826 bounded_rounded = (unbounded_rounded % 360);
827 if (bounded_rounded > 180)
828 bounded_rounded -= 360;
829 if (bounded_rounded <= -180)
830 bounded_rounded += 360;
832 return bounded_rounded;
842 return static_cast<int64_t
>(flo);
847 double plane_pos[3], waypoint_pos[3], dir[3];
850 plane_pos[0] =
static_cast<double>(current_x) ;
851 plane_pos[1] =
static_cast<double>(current_y) ;
854 waypoint_pos[0] =
static_cast<double>(x) ;
855 waypoint_pos[1] =
static_cast<double>(y) ;
874 int64_t current_x, current_y;
875 int64_t waypoint_x, waypoint_y;
880 print(thisAgent,
"Error: 'compute-heading' function called with no arguments\n");
884 for (c = args; c !=
NIL; c = c->
rest) {
888 print_with_symbols(thisAgent,
"Error: non-number (%y) passed to - compute-heading\n", arg);
899 print_with_symbols(thisAgent,
"Error: non-number (%y) passed to compute-heading function.\n", arg);
907 print(thisAgent,
"Error: 'compute-heading' takes exactly 4 arguments.\n");
935 double current_x, current_y;
936 double waypoint_x, waypoint_y;
941 print(thisAgent,
"Error: 'compute-range' function called with no arguments\n");
945 for (c = args; c !=
NIL; c = c->
rest) {
949 print_with_symbols(thisAgent,
"Error: non-number (%y) passed to - compute-range\n", arg);
960 print_with_symbols(thisAgent,
"Error: non-number (%y) passed to compute-range function.\n", arg);
968 print(thisAgent,
"Error: 'compute-range' takes exactly 4 arguments.\n");
984 return make_int_constant(thisAgent, static_cast<int64_t>(sqrt((current_x - waypoint_x)
985 * (current_x - waypoint_x)
986 + (current_y - waypoint_y)
987 * (current_y - waypoint_y))));
1006 n =
static_cast<double>(arg->
ic.
value);
1010 print_with_symbols(thisAgent,
"Error: non-number (%y) passed to - rand-float\n", arg);
1043 n =
static_cast<int64_t
>(arg->
fc.
value);
1062 return ( ( fabs( in ) <= 0.00001 )?( 0 ):( in ) );
1068 uint64_t* b =
new uint64_t[ n+1 ];
1072 for ( i=1; i<=n; ++i )
1075 for ( j=(i-1); j>0; --j )
1108 double p1kd = pow( static_cast< double >( sides ), static_cast< double >( count ) );
1109 double p2nkn = pow( static_cast< double >( sides - 1 ), static_cast< double >( dice - count ) );
1110 double p2nkd = pow( static_cast< double >( sides ), static_cast< double >( dice - count ) );
1112 double result =
static_cast< double >(
_dice_binom( static_cast< uint64_t >( dice ), static_cast< uint64_t >( count ) ) );
1113 result *= (
static_cast< double >( 1.0 ) / p1kd );
1114 result *= ( p2nkn / p2nkd );
1129 double result = 0.0;
1130 for ( int64_t i=0; ( count + i <= dice ); ++i )
1146 enum pred_type { eq, ne, lt, gt, le, ge, bad };
1147 pred_type pred = bad;
1158 print_with_symbols( thisAgent,
"Error: non-number (%y) passed as 'dice' to - compute-dice-probability\n", temp_sym );
1168 print_with_symbols( thisAgent,
"Error: non-number (%y) passed as 'sides' to - compute-dice-probability\n", temp_sym );
1178 print_with_symbols( thisAgent,
"Error: non-number (%y) passed as 'count' to - compute-dice-probability\n", temp_sym );
1187 print_with_symbols( thisAgent,
"Error: non-string (%y) passed as 'pred' to - compute-dice-probability\n", temp_sym );
1190 if ( strcmp( temp_sym->
sc.
name,
"eq" ) == 0 )
1194 else if ( strcmp( temp_sym->
sc.
name,
"ne" ) == 0 )
1198 else if ( strcmp( temp_sym->
sc.
name,
"lt" ) == 0 )
1202 else if ( strcmp( temp_sym->
sc.
name,
"gt" ) == 0 )
1206 else if ( strcmp( temp_sym->
sc.
name,
"le" ) == 0 )
1210 else if ( strcmp( temp_sym->
sc.
name,
"ge" ) == 0 )
1216 print_with_symbols( thisAgent,
"Error: invalid string (%y) passed as 'pred' to - compute-dice-probability\n", temp_sym );
1224 if ( ( count < 0 ) || ( count > dice ) )
1233 else if ( pred == ne )
1235 if ( ( count < 0 ) || ( count > dice ) )
1244 else if ( pred == lt )
1250 else if ( count > dice )
1259 else if ( pred == gt )
1265 else if ( count >= dice )
1274 else if ( pred == le )
1280 else if ( count >= dice )
1289 else if ( pred == ge )
1295 else if ( count > dice )