void test_double_float() {
    test_header();

    double d = 2.2354e-10;
    float f = d;
    uint32_t i = 7821334;
    uchar_vec b;
    unsigned char *buffer = NULL;

    kv_init(b);
    dump_double(d, &b);
    buffer = b.a;
    fprintf(stderr, "%g == %g - ", d, load_double(&buffer));
    fprintf(stderr, "buffer used: %zu\n", buffer - b.a);

    kv_clear(b);
    dump_float(f, &b);
    buffer = b.a;
    fprintf(stderr, "%g == %g - ", d, load_float(&buffer));
    fprintf(stderr, "buffer used: %zu\n", buffer - b.a);

    kv_clear(b);
    dump_uint32(i, &b);
    buffer = b.a;
    fprintf(stderr, "%d == %d - ", i, load_uint32(&buffer));
    fprintf(stderr, "buffer used: %zu\n", buffer - b.a);

    kv_destroy(b);
}
示例#2
0
int
fctiwz(u32 *frD, void *frB)
{
	FP_DECL_D(B);
	FP_DECL_EX;
	u32 fpscr;
	unsigned int r;

	fpscr = __FPU_FPSCR;
	__FPU_FPSCR &= ~(3);
	__FPU_FPSCR |= FP_RND_ZERO;

	FP_UNPACK_DP(B, frB);
	FP_TO_INT_D(r, B, 32, 1);
	frD[1] = r;

	__FPU_FPSCR = fpscr;

#ifdef DEBUG
	printk("%s: D %p, B %p: ", __func__, frD, frB);
	dump_double(frD);
	printk("\n");
#endif

	return 0;
}
示例#3
0
int
lfd(void *frD, void *ea)
{
	if (copy_from_user(frD, ea, sizeof(double)))
		return -EFAULT;
#ifdef DEBUG
	printk("%s: D %p, ea %p: ", __FUNCTION__, frD, ea);
	dump_double(frD);
	printk("\n");
#endif
	return 0;
}
示例#4
0
int
fnabs(u32 *frD, u32 *frB)
{
	frD[0] = frB[0] | 0x80000000;
	frD[1] = frB[1];

#ifdef DEBUG
	printk("%s: D %p, B %p: ", __FUNCTION__, frD, frB);
	dump_double(frD);
	printk("\n");
#endif

	return 0;
}
示例#5
0
int
fabs(u32 *frD, u32 *frB)
{
	frD[0] = frB[0] & 0x7fffffff;
	frD[1] = frB[1];

#ifdef DEBUG
	printk("%s: D %p, B %p: ", __func__, frD, frB);
	dump_double(frD);
	printk("\n");
#endif

	return 0;
}
示例#6
0
文件: stfd.c 项目: TitaniumBoy/lin
int
stfd(void *frS, void *ea)
{
#if 0
#ifdef DEBUG
	printk("%s: S %p, ea %p: ", __FUNCTION__, frS, ea);
	dump_double(frS);
	printk("\n");
#endif
#endif

	if (copy_to_user(ea, frS, sizeof(double)))
		return -EFAULT;

	return 0;
}
示例#7
0
文件: fctiw.c 项目: TitaniumBoy/lin
int
fctiw(u32 *frD, void *frB)
{
	FP_DECL_D(B);
	unsigned int r;

	__FP_UNPACK_D(B, frB);
	FP_TO_INT_D(r, B, 32, 1);
	frD[1] = r;

#ifdef DEBUG
	printk("%s: D %p, B %p: ", __FUNCTION__, frD, frB);
	dump_double(frD);
	printk("\n");
#endif

	return 0;
}
示例#8
0
int
efdctsi(u32 *rD, void *rB)
{
	FP_DECL_D(B);
	unsigned int r;

	__FP_UNPACK_D(B, rB);
	_FP_ROUND(2, B);
	FP_TO_INT_D(r, B, 32, 1);
	rD[1] = r;

#ifdef DEBUG
	printk("%s: D %p, B %p: ", __FUNCTION__, rD, rB);
	dump_double(rD);
	printk("\n");
#endif

	return 0;
}
static void dump_values(grib_dumper* d,grib_accessor* a)
{
    grib_dumper_debug *self = (grib_dumper_debug*)d;
    int i,k,err =0;
    int more = 0;
    double*  buf = NULL;
    size_t size=0;
    long count=0;

    if( a->length == 0  &&
            (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0)
        return;

    grib_value_count(a,&count);
    size=count;
    if(size == 1){
        dump_double(d,a,NULL);
        return ;
    }
    buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double));

    set_begin_end(d,a);

    for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");
    fprintf(self->dumper.out,"%ld-%ld %s %s = (%ld,%ld)",self->begin,self->theEnd,a->creator->op, a->name,(long)size,a->length);
    aliases(d,a);
    fprintf(self->dumper.out," {");

    if(!buf)
    {
        if(size == 0)
            fprintf(self->dumper.out,"}\n");
        else
            fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size);
        return;
    }

    fprintf(self->dumper.out,"\n");

    err =  grib_unpack_double(a,buf,&size);

    if(err){
        grib_context_free(d->handle->context,buf);
        fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_debug::dump_values]\n}",err,grib_get_error_message(err));
        return ;
    }

    if(size > 100) {
        more = size - 100;
        size = 100;
    }


    k = 0;
    while(k < size)
    {
#if 1
        int j;
        for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," ");
        for(j = 0; j < 8 && k < size; j++, k++)
        {
            fprintf(self->dumper.out,"%10g",buf[k]);
            if(k != size-1)
                fprintf(self->dumper.out,", ");
        }
        fprintf(self->dumper.out,"\n");
#else

        fprintf(self->dumper.out,"%d %g\n",k,buf[k]);

#endif

    }
    if(more)
    {
        for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," ");
        fprintf(self->dumper.out,"... %d more values\n",more);
    }

    for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");
    fprintf(self->dumper.out,"} # %s %s \n",a->creator->op, a->name);
    grib_context_free(d->handle->context,buf);
}
static void dump_values(grib_dumper* d,grib_accessor* a)
{
  grib_dumper_default *self = (grib_dumper_default*)d;
  int k,err =0;
  int more = 0;
  double*  buf = NULL;
  size_t size=0;
  long count=0;

  if ( (a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0)
    return;

  grib_value_count(a,&count);
  size=count;
  if(size == 1){
    dump_double(d,a,NULL);
    return ;
  }
  buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double));

   print_offset(self->dumper.out,d,a);

  if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"# type %s \n",a->creator->op);
  }

  aliases(d,a);

  if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"#-READ ONLY- ");
  } else
    fprintf(self->dumper.out,"  ");

  fprintf(self->dumper.out,"%s(%ld) = ",a->name,(long)size);
  aliases(d,a);
  fprintf(self->dumper.out," {");

  if(!buf)
  {
    if(size == 0)
      fprintf(self->dumper.out,"}\n");
    else
      fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size);
    return;
  }

  fprintf(self->dumper.out,"\n");

  err =  grib_unpack_double(a,buf,&size);

  if(err){
    grib_context_free(d->handle->context,buf);
    fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_default::dump_values]\n}",err,grib_get_error_message(err));
    return ;
  }

  if(!(d->option_flags & GRIB_DUMP_FLAG_ALL_DATA) && size > 100) {
    more = size - 100;
    size = 100;
  }

  k = 0;
  while(k < size)  {
#if 1
    int j;
    fprintf(self->dumper.out,"  ");
    for(j = 0; j < 5 && k < size; j++, k++)  {
      fprintf(self->dumper.out,"%.10e",buf[k]);
      if(k != size-1)
        fprintf(self->dumper.out,", ");
    }
    fprintf(self->dumper.out,"\n");
#else

    fprintf(self->dumper.out,"%d %g\n",k,buf[k]);

#endif

  }  if(more)  {
    fprintf(self->dumper.out,"  ");
    fprintf(self->dumper.out,"... %d more values\n",more);
  }

  fprintf(self->dumper.out,"  ");
  fprintf(self->dumper.out,"} \n");
  grib_context_free(d->handle->context,buf);
}
示例#11
0
static void dump_values(grib_dumper* d,grib_accessor* a)
{
  grib_dumper_c_code *self = (grib_dumper_c_code*)d;
  int k,err =0;
  double*  buf = NULL;
  int type=0;
  char stype[10];
  size_t size=0;
  stype[0]='\0';

  if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)
      || ((a->flags & GRIB_ACCESSOR_FLAG_DATA)
          && (d->option_flags & GRIB_DUMP_FLAG_NO_DATA)   ) )
    return;

  size=grib_value_count(a);
  if(size == 1){
    dump_double(d,a,NULL);
    return ;
  }

  type=grib_accessor_get_native_type(a);
  switch (type) {
     case GRIB_TYPE_LONG:
       sprintf(stype,"%s","long");
       break;
     case GRIB_TYPE_DOUBLE:
       sprintf(stype,"%s","double");
       break;
     default:
       return;
  }

  buf = grib_context_malloc(d->handle->context,size * sizeof(double));
  if(!buf)
  {
    fprintf(self->dumper.out,"/* %s: cannot malloc(%ld) */\n",a->name,(long)size);
    return;
  }

  err =  grib_unpack_double(a,buf,&size);

  if(err){
    grib_context_free(d->handle->context,buf);
    fprintf(self->dumper.out," /*  Error accessing %s (%s) */",a->name,grib_get_error_message(err));
    return ;
  }

  fprintf(self->dumper.out,"    size = %ld;\n",(long)size);
  fprintf(self->dumper.out,"    v%s    = (%s*)calloc(size,sizeof(%s));\n",stype,stype,stype);
  fprintf(self->dumper.out,"    if(!v%s) {\n",stype);
  fprintf(self->dumper.out,"        fprintf(stderr,\"failed to allocate %%d bytes\\n\",size*sizeof(%s));\n",stype);
  fprintf(self->dumper.out,"        exit(1);\n");
  fprintf(self->dumper.out,"    }\n");


  fprintf(self->dumper.out,"\n   ");
  k = 0;
  while(k < size)
  {
    fprintf(self->dumper.out," v%s[%4d] = %7g;",stype,k,buf[k]);
    k++;
    if(k%4 == 0) fprintf(self->dumper.out,"\n   ");

  }
  if(size%4) fprintf(self->dumper.out,"\n");
  fprintf(self->dumper.out,"\n");
  fprintf(self->dumper.out,"    GRIB_CHECK(grib_set_%s_array(h,\"%s\",v%s,size),%d);\n",stype,a->name,stype,0);
  fprintf(self->dumper.out,"    free(v%s);\n",stype);

  grib_context_free(d->handle->context,buf);
}
示例#12
0
/*
 * Style: 0 = auto
 *       -1 = hex
 *       -2 = raw
 *       +? = that format number
 */
int dumpABIBlock(abi_index_t *ind, int style, int separator, int date_sep,
		 int line_sep) {
    if (style == -2) {
	dump_raw(ind->data, ind->size);
    } else {
	int hex = (style == -1);

	/*
	 * Guess some style. PBAS, APrX, MODL etc are type 2 (1-byte char),
	 * but are really strings. Conversly PCON is also type 2 and is a
	 * series of numbers.
	 */
	if (style == 0 && ind->format == 2) {
	    int i;
	    for (i = 0; i < ind->size; i++)
		if (!(isprint(ind->data[i]) || isspace(ind->data[i])))
		    break;
	    if (i == ind->size)
		style = 19; /* C-string */
	}


	if (style <= 0)
	    style = ind->format;

	switch(style) {
	case 2:
	    dump_int1(ind->data, ind->size, hex, separator);
	    break;
	    
	case 4:
	    dump_int2(ind->data, ind->size, hex, separator);
	    break;
	    
	case 5:
	    dump_int4(ind->data, ind->size, hex, separator);
	    break;
	    
	case 7:
	    dump_float(ind->data, ind->size, hex, separator);
	    break;
	    
	case 8:
	    dump_double(ind->data, ind->size, hex, separator);
	    break;
	    
	case 10:
	    dump_date(ind->data, ind->size, hex, separator, date_sep);
	    break;
	    
	case 11:
	    dump_time(ind->data, ind->size, hex, separator, date_sep);
	    break;
	    
	case 18:
	    dump_pstr(ind->data, ind->size, hex, separator);
	    break;
	    
	case 19:
	    dump_cstr(ind->data, ind->size, hex, separator);
	    break;
	    
	default:
	    /* Default to hex dump for unknown ones */
	    dump_int1(ind->data, ind->size, 1, separator);
	    break;
	}
    }

    if (separator != '\n')
	putchar(line_sep);

    return 0;
}
static void dump_values(grib_dumper* d,grib_accessor* a)
{
  grib_dumper_serialize *self = (grib_dumper_serialize*)d;
  int k,err =0;
  double*  buf = NULL;
  int last=0;
  int columns=4;
  char* values_format=NULL;
  char* default_format="%.16e";
  char* columns_str=NULL;
  size_t len=0;
  char* pc=NULL;
  char* pcf=NULL;
  size_t size=0;
  long count=0;
  values_format=default_format;

  if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY))
    return;

  grib_value_count(a,&count);
  size=count;

  if (self->format) {
    if (self->format[0]=='\"') values_format=self->format+1;
    else values_format=self->format;
    last=strlen(values_format)-1;
    if (values_format[last]=='\"') values_format[last]='\0';
  }


  pc = values_format;
  pcf = values_format;
  while( *pc!='\0' && *pc != '%') pc++;
  if (strlen(pc) > 1 ) {
    values_format=pc;
    len=pc-pcf;
  } else {
    values_format=default_format;
    len=0;
  }

  if (len>0) {
    columns_str=(char*)malloc((len+1)*sizeof(char));
    columns_str=(char*)memcpy(columns_str,pcf,len);
    columns_str[len]='\0';
    columns=atoi(columns_str);
    free(columns_str);
  }

  if(size == 1){
    dump_double(d,a,NULL);
    return ;
  }

  if ((d->option_flags & GRIB_DUMP_FLAG_VALUES) == 0 ) return;

  buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double));

  fprintf(self->dumper.out,"%s (%ld) {",a->name,(long)size);

  if(!buf)
  {
    if(size == 0)
      fprintf(self->dumper.out,"}\n");
    else
      fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size);
    return;
  }

  fprintf(self->dumper.out,"\n");

  err =  grib_unpack_double(a,buf,&size);

  if(err){
    grib_context_free(d->handle->context,buf);
    fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_values]\n}",err,grib_get_error_message(err));
    return ;
  }

  k = 0;
  while(k < size)
  {
    int j;
    for(j = 0; j < columns && k < size; j++, k++)
    {
      fprintf(self->dumper.out,values_format,buf[k]);
      if(k != size-1)
        fprintf(self->dumper.out,", ");
    }
    fprintf(self->dumper.out,"\n");
  }
  fprintf(self->dumper.out,"}\n");
  grib_context_free(d->handle->context,buf);
}