Example #1
0
float percent_of(mixed percent, mixed base){
    float a, b;

    a = (floatp(percent) ? percent : to_float(percent));
    b = (floatp(base) ? base : to_float(base));
    if((b < 1 && b > -1) || !b || b == 0 || b == 0.0 ) return 0.0;
    return (a * b) / 100.0;
}
Example #2
0
LOCAL int nyx_is_labels(LVAL expr)
{
   /* make sure that we have a list whose first element is a
      list of the form (time "label") */

   LVAL label;
   LVAL first;
   LVAL second;
   LVAL third;

   if (expr == NULL) {
      return 0;
   }

   while (expr != NULL) {
      if (!consp(expr)) {
         return 0;
      }

      label = car(expr);

      if (!consp(label)) {
         return 0;
      }

      first = car(label);
      if (!(floatp(first) || fixp(first))) {
         return 0;
      }

      if (!consp(cdr(label))) {
         return 0;
      }

      second = car(cdr(label));

      if (floatp(second) || fixp(second)) {
         if (!consp(cdr(cdr(label)))) {
            return 0;
         }
         third = car(cdr(cdr(label)));
         if (!(stringp(third))) {
            return 0;
         }
      }
      else {
         if (!(stringp(second))) {
            return 0;
         }
      }

      expr = cdr(expr);
   }

   return 1;
}
Example #3
0
float percent(mixed numerator, mixed denominator) {
    float a, b;

    if(!floatp(numerator) && !intp(numerator)) return 0.0;
    else a = (floatp(numerator) ? numerator : to_float(numerator));
    if(!floatp(denominator) && !intp(denominator)) return 0.0;
    else b = (floatp(denominator) ? denominator : to_float(denominator));
    if((b < 1 && b > -1) || !b || b == 0 || b == 0.0 ) return 0.0;
    return ((a/b)*100);
}
Example #4
0
void nyx_get_label(unsigned int index,
                   double *start_time,
                   double *end_time,
                   const char **label)
{
   LVAL s = nyx_result;
   LVAL label_expr;
   LVAL t0_expr;
   LVAL t1_expr;
   LVAL str_expr;

   if (nyx_get_type(nyx_result) != nyx_labels) {
      return;
   }

   while (index) {
      index--;
      s = cdr(s);
      if (s == NULL) {
         // index was larger than number of labels
         return;
      }
   }

   /* We either have (t0 "label") or (t0 t1 "label") */

   label_expr = car(s);
   t0_expr = car(label_expr);
   t1_expr = car(cdr(label_expr));
   if (stringp(t1_expr)) {
      str_expr = t1_expr;
      t1_expr = t0_expr;
   }
   else {
      str_expr = car(cdr(cdr(label_expr)));
   }

   if (floatp(t0_expr)) {
      *start_time = getflonum(t0_expr);
   }
   else if (fixp(t0_expr)) {
      *start_time = (double)getfixnum(t0_expr);
   }

   if (floatp(t1_expr)) {
      *end_time = getflonum(t1_expr);
   }
   else if (fixp(t1_expr)) {
      *end_time = (double)getfixnum(t1_expr);
   }

   *label = (const char *)getstring(str_expr);
}
Example #5
0
int is_labels(LVAL expr)
{
   /* make sure that we have a list whose first element is a
      list of the form (time "label") */

   if (!consp(expr))
      return 0;

   if (!consp(car(expr)))
      return 0;

   if (!(floatp(car(car(expr))) || fixp(car(car(expr)))))
      return 0;

   if (!consp(cdr(car(expr))))
      return 0;

   if (!(stringp(car(cdr(car(expr))))))
      return 0;

   /* If this is the end of the list, we're done */

   if (cdr(expr) == NULL)
      return 1;

   /* Otherwise recurse */

   return is_labels(cdr(expr));
}
Example #6
0
/* xfloatp - is this a float? */
LVAL xfloatp(void)
{
    LVAL arg;
    arg = xlgetarg();
    xllastarg();
    return (floatp(arg) ? s_true : NIL);
}
Example #7
0
/* xnumberp - is this a number? */
LVAL xnumberp(void)
{
    LVAL arg;
    arg = xlgetarg();
    xllastarg();
    return (fixp(arg) || floatp(arg) ? s_true : NIL);
}
Example #8
0
LOCAL double spin_angle P1C(LVAL, object)
{
  LVAL value = slot_value(object, s_rotation_angle);
  
  if (floatp(value)) return(getflonum(value));
  else return(0.0);
}
Example #9
0
string print_vars(mixed *vars) {
    string *result = allocate(sizeof(vars));
    int i;

    for (i=0; i<sizeof(vars); i++) {
	if (mapp(vars[i]))
	    result[i] = "([ ... ])";
	else if (functionp(vars[i]))
	    result[i] = "(: ... :)";
	else if (intp(vars[i]))
	{
	    if (vars[i]) result[i]=vars[i]+"";
	    else if (nullp(vars[i])) result[i]="NULL";
	    else if (undefinedp(vars[i])) result[i]="UNDEFINED";
	    else result[i]="0";
	}
	else if (stringp(vars[i]))
	    result[i] = "\""+vars[i]+"\"";
	else if (arrayp(vars[i]))
	    result[i] = "({ ... })";
	else if (floatp(vars[i]))
	    result[i] = vars[i]+"";
	else if (bufferp(vars[i]))
	    result[i] = "<BUFFER>";
    }
    return implode(result, ", ");
}
Example #10
0
void nyx_get_label(int index,
                   double *time,
                   const char **label)
{
   LVAL s = nyx_result;
   LVAL t_expr;

   if (nyx_get_type(nyx_result) != nyx_labels)
      return;

   if (index < 0 || index >= nyx_get_num_labels())
      return;

   while(index) {
      index--;
      s = cdr(s);
   }

   t_expr = car(car(s));
   if (floatp(t_expr))
      *time = getflonum(t_expr);
   else if (fixp(t_expr))
      *time = (double)getfixnum(t_expr);
   *label = (const char *)getstring(car(cdr(car(s))));
}
Example #11
0
void print_data(string str) {
    mixed *data;
    int i, j;

    switch (str) {
        case "mem"   : { data = pastmem; break; }
        case "obs"   : { data = pastobs; break; }
        case "cpu"   : { data = pastcpu; break; }
        case "users" : { data = pastusers; break; }
    }

    for (i = 0, j = counter; i < TRACK_NUM && floatp(data[j]); i++, j--) {
        switch (i) {
            case 0:
                write(sprintf("Current:        %f\n", data[j]));
                break;
            case 1:
                write(sprintf("Last period:    %f\n", data[j]));
                break;
            default:
                write(sprintf("%2d periods ago: %f\n", i, data[j]));
                break;
        }
        if (j == 0)
            j = TRACK_NUM;
    }
}
Example #12
0
/* eql - internal eql function */
int eql P2C(LVAL, arg1, LVAL, arg2)
{
    /* compare the arguments */
    if (arg1 == arg2)
	return (TRUE);
    else if (arg1 != NIL) {
	switch (ntype(arg1)) {
	case FIXNUM:
	    return (fixp(arg2) ? getfixnum(arg1)==getfixnum(arg2) : FALSE);
#ifdef BIGNUMS
	case RATIO:
	    return (ratiop(arg2) ? compareratio(arg1, arg2) : FALSE);
	case BIGNUM:
	    return (bignump(arg2) ? comparebignum(arg1, arg2) == 0 : FALSE);
#endif
	case FLONUM:
	    return (floatp(arg2) ? getflonum(arg1)==getflonum(arg2) : FALSE);
        case COMPLEX:
            return (complexp(arg2) ? comparecomplex(arg1,arg2) : FALSE);
	default:
	    return (FALSE);
	}
    }
    else
	return (FALSE);
}
Example #13
0
int is_labels(LVAL expr)
{
   /* make sure that we have a list whose first element is a
      list of the form (time "label") */

   LVAL label;
   LVAL first;
   LVAL second;
   LVAL third;

   if (!consp(expr))
      return 0;

   label = car(expr);

   if (!consp(label))
      return 0;

   first = car(label);
   if (!(floatp(first) || fixp(first)))
      return 0;

   if (!consp(cdr(label)))
      return 0;

   second = car(cdr(label));

   if (floatp(second) || fixp(second)) {
      if (!consp(cdr(cdr(label))))
         return 0;
      third = car(cdr(cdr(label)));
      if (!(stringp(third)))
         return 0;
   }
   else
      if (!(stringp(second)))
         return 0;

   /* If this is the end of the list, we're done */

   if (cdr(expr) == NULL)
      return 1;

   /* Otherwise recurse */

   return is_labels(cdr(expr));
}
Example #14
0
void nyx_get_label(int index,
                   double *start_time,
                   double *end_time,
                   const char **label)
{
   LVAL s = nyx_result;
   LVAL label_expr;
   LVAL t0_expr;
   LVAL t1_expr;
   LVAL str_expr;

   if (nyx_get_type(nyx_result) != nyx_labels)
      return;

   if (index < 0 || index >= nyx_get_num_labels())
      return;

   while(index) {
      index--;
      s = cdr(s);
   }

   /* We either have (t0 "label") or (t0 t1 "label") */

   label_expr = car(s);
   t0_expr = car(label_expr);
   t1_expr = car(cdr(label_expr));
   if (stringp(t1_expr)) {
      str_expr = t1_expr;
      t1_expr = t0_expr;
   }
   else
      str_expr = car(cdr(cdr(label_expr)));

   if (floatp(t0_expr))
      *start_time = getflonum(t0_expr);
   else if (fixp(t0_expr))
      *start_time = (double)getfixnum(t0_expr);

   if (floatp(t1_expr))
      *end_time = getflonum(t1_expr);
   else if (fixp(t1_expr))
      *end_time = (double)getfixnum(t1_expr);

   *label = (const char *)getstring(str_expr);
}
Example #15
0
void fromobject__fetch(register fromobject_susp_type susp, snd_list_type snd_list)
{
    int cnt = 0; /* how many samples computed */
    int togo;
    int n;
    sample_block_type out;
    register sample_block_values_type out_ptr;

    register sample_block_values_type out_ptr_reg;

    register boolean done_reg;
    register LVAL src_reg;
    falloc_sample_block(out, "fromobject__fetch");
    out_ptr = out->samples;
    snd_list->block = out;

    while (cnt < max_sample_block_len) { /* outer loop */
	/* first compute how many samples to generate in inner loop: */
	/* don't overflow the output sample block: */
	togo = max_sample_block_len - cnt;

        if (susp->done) {
            togo = 0; /* indicate termination */
            break;    /* we're done */
        }

	n = togo;
	done_reg = susp->done;
	src_reg = susp->src;
	out_ptr_reg = out_ptr;
	if (n) do { /* the inner sample computation loop */
            LVAL rslt = xleval(cons(s_send, cons(src_reg,
                                                 consa(s_next))));
            if (floatp(rslt)) {
                *out_ptr_reg++ = (sample_type) getflonum(rslt);
            } else {
                done_reg = true;
                /* adjust togo to what it should have been */
                break;
            };
	} while (--n); /* inner loop */

	togo -= n;
	susp->done = done_reg;
	out_ptr += togo;
	cnt += togo;
    } /* outer loop */

    /* test for termination */
    if (togo == 0 && cnt == 0) {
	snd_list_terminate(snd_list);
    } else {
	snd_list->block_len = cnt;
	susp->susp.current += cnt;
    }
} /* fromobject__fetch */
Example #16
0
/* equal - internal equal function */
int equal P2C(LVAL, arg1, LVAL, arg2)
{
    FIXTYPE n=0;    /* for circularity check -- 6/93 */
    
    /* compare the arguments */
isItEqual:  /* turn tail recursion into iteration */
    if (arg1 == arg2)
	return (TRUE);
    else if (arg1 != NIL) {
	switch (ntype(arg1)) {
	case FIXNUM:
	    return (fixp(arg2) ? getfixnum(arg1)==getfixnum(arg2) : FALSE);
#ifdef BIGNUMS
	case RATIO:
	    return (ratiop(arg2) ? compareratio(arg1, arg2) : FALSE);
	case BIGNUM:
	    return (bignump(arg2) ? comparebignum(arg1, arg2) == 0 : FALSE);
#endif
	case FLONUM:
	    return (floatp(arg2) ? getflonum(arg1)==getflonum(arg2) : FALSE);
	case COMPLEX:
            return (complexp(arg2) ? comparecomplex(arg1,arg2) : FALSE);
        case STRING: /* TAA MOD */
	    return (stringp(arg2) ? stringcmp(arg1,arg2) : FALSE);
	case CONS:  /* TAA MOD turns tail recursion into iteration */
                    /* Not only is this faster, but greatly reduces chance */
                    /* of stack overflow */
#ifdef STSZ
	    if (consp(arg2) && (stchck(), equal(car(arg1),car(arg2))))
#else
            if (consp(arg2) && equal(car(arg1),car(arg2)))
#endif
	    {
                arg1 = cdr(arg1);
                arg2 = cdr(arg2);
                if (++n > nnodes) xlfail("circular list");
                goto isItEqual;
            }
            return FALSE;
	default:
	    return (FALSE);
	}
    }
    else
	return (FALSE);
}
Example #17
0
string comma(mixed x){
    string ret = "", pre = "", post = "";
    int count = 0, i;
    if(floatp(x)) sscanf(x+"","%s.%s",pre,post);
    else if(intp(x)) pre = itoa(x);
    else return 0;
    i = sizeof(pre);
    while(i){
        count++;
        ret = pre[<count..<count] + ret;
        if(!(count % 3) && (i = sizeof(pre[<count+1..<count+1]))){
            ret = "," + ret;
        }
    }
    if(!sizeof(ret)) ret = "0";
    if(sizeof(post)){
        ret += "." + post[0..1];
    }
    return ret;
}