Esempio n. 1
0
File: inf_div.c Progetto: k6s/tek1
t_nb		*inf_div(t_nb *n1, t_nb *n2, t_base *s_base, char *ops)
{
  t_nb		*res;

  if (zero_check(n2, s_base->base[0], ops[3], ops[2]))
    {
      my_putstr(SYNTAXE_ERROR_MSG);
      return (NULL);
    }
  if (!(res = malloc(sizeof(*res))))
    return (NULL);
  res->sign = get_sign(n1, n2, ops[3]);
  if (!(res->nb = malloc(sizeof(*res) * (n1->len + 2))))
    return (NULL);
  my_bzero(res->nb, n1->len + 2);
  if (do_div(res, n1, n2, s_base) < 0)
    return (NULL);
  set_ret_sign(res);
  if (!(res->len = clean_res(res, n1->len + 2, s_base->base, ops[3])))
    return (NULL);
  return (res);
}
Esempio n. 2
0
 void check_divide_by_zero(SharkValue* value) {
   zero_check(value);
 }
Esempio n. 3
0
 void check_null(SharkValue* object) {
   zero_check(object);
 }
Esempio n. 4
0
int fold_16bit_power(const struct polyco *pc, int imjd, double fmjd, 
        const int16_t *data, int nsamp, double tsamp, int raw_signed,
        struct foldbuf *f) {

    /* Find midtime */
    double fmjd_mid = fmjd + nsamp*tsamp/2.0/86400.0;

    /* Check polyco set, allow 5% expansion of range */
    if (pc_out_of_range_sloppy(pc, imjd, fmjd,1.05)) { return(-1); }

    /* Calc phase, phase step */
    /* NOTE: Starting sample phase is computed for the middle
     * of the first sample, assuming input fmjd refers to 
     * the rising edge of the first sample given
     */
    double dphase=0.0;
    double phase = psr_phase(pc, imjd, fmjd + tsamp/2.0/86400.0, NULL, NULL);
    phase = fmod(phase, 1.0);
    if (phase<0.0) { phase += 1.0; }
    psr_phase(pc, imjd, fmjd_mid, &dphase, NULL);
    dphase *= tsamp;

    /* Fold em */
    int i, ibin;
    float *fptr;
    for (i=0; i<nsamp; i++) {
        ibin = (int)(phase * (double)f->nbin);
        if (ibin<0) { ibin+=f->nbin; }
        if (ibin>=f->nbin) { ibin-=f->nbin; }
        fptr = &f->data[ibin*f->nchan*f->npol];
        if (zero_check((const char *)&data[i*f->nchan*f->npol],
                    2*f->nchan*f->npol)==0) { 
            if (raw_signed==1)
                vector_accumulate_16bit(fptr, 
                        &data[i*f->nchan*f->npol],
                        f->nchan*f->npol);
            else if (raw_signed==2) {
                // First 2 polns are unsigned, last 2 are signed
                vector_accumulate_16bit_unsigned(fptr, 
                        &data[i*f->nchan*f->npol],
                        f->nchan*2);
                vector_accumulate_16bit(fptr + 2*f->nchan, 
                        &data[i*f->nchan*f->npol + 2*f->nchan],
                        f->nchan*2);
            } else if (raw_signed==3) {
                // First 1 pol is unsigned, last 3 are signed
                vector_accumulate_16bit_unsigned(fptr, 
                        &data[i*f->nchan*f->npol],
                        f->nchan);
                vector_accumulate_16bit(fptr + f->nchan, 
                        &data[i*f->nchan*f->npol + f->nchan],
                        f->nchan*3);
            } else 
                // All unsigned
                vector_accumulate_16bit_unsigned(fptr, 
                        (uint16_t *)&data[i*f->nchan*f->npol],
                        f->nchan*f->npol);
            f->count[ibin]++;
        }
        phase += dphase;
        if (phase>1.0) { phase -= 1.0; }
    }

    return(0);
}