mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-01 17:06:03 +08:00
Set bit_xpl_nbr_sgn_dbl=52 not 53. No longer add additional bit to prc_bnr_xpl_rqr for BitGroom NC_DOUBLE. Bugfix maintains original BG behavior, fixes corner case.
This commit is contained in:
parent
72eb8b2ce2
commit
b4969df1ef
@ -604,12 +604,9 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type,
|
||||
* exact binary digits of precision. Add one because the first bit
|
||||
* is implicit not explicit but corner cases prevent our taking
|
||||
* advantage of this. */
|
||||
prc_bnr_xpl_rqr = (unsigned short)ceil(nsd * bit_per_dgt) + 1;
|
||||
if (dest_type == NC_DOUBLE)
|
||||
prc_bnr_xpl_rqr++; /* Seems necessary for double-precision
|
||||
* ppc=array(1.234567,1.0e-6,$dmn) */
|
||||
prc_bnr_xpl_rqr = (unsigned short)ceil(nsd * bit_per_dgt) + 1;
|
||||
|
||||
else if (quantize_mode == NC_QUANTIZE_BITROUND){
|
||||
}else if (quantize_mode == NC_QUANTIZE_BITROUND){
|
||||
|
||||
/* BitRound interprets nsd as number of significant binary digits (bits) */
|
||||
prc_bnr_xpl_rqr = nsd;
|
||||
@ -658,12 +655,10 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type,
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} /* endif quantize */
|
||||
|
||||
|
||||
/* OK, this is ugly. If you can think of anything better, I'm open
|
||||
to suggestions!
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
Dennis Heimbigner, 1/16/22
|
||||
*/
|
||||
|
||||
#include <math.h> /* Define fabs(), powf(), round() */
|
||||
#include <nc_tests.h>
|
||||
#include "err_macros.h"
|
||||
#include "netcdf.h"
|
||||
@ -66,7 +67,7 @@ pd(double myd)
|
||||
uint64_t u;
|
||||
} du;
|
||||
du.d = myd;
|
||||
sprintf(pf_str, "0x%lx", (unsigned long)du.u);
|
||||
sprintf(pf_str, "0x%llx", (unsigned long long)du.u);
|
||||
return pf_str;
|
||||
}
|
||||
|
||||
@ -292,8 +293,8 @@ fprintf(stderr,"\n>>> type url = |%s|\n",file_name);
|
||||
/* printf ("\nfloat_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */
|
||||
/* float_data[0], fout.u, float_data[0], fin.u); */
|
||||
if (fin.u != 0x3f8e3000) ERR;
|
||||
/* printf ("\ndouble_data: %15g : 0x%16lx double_data_in: %15g : 0x%lx\n", */
|
||||
/* double_data[0], dfout.u, double_data[0], dfin.u); */
|
||||
/* printf ("\ndouble_data: %15g : 0x%16llx double_data_in: %15g : 0x%llx\n", */
|
||||
/* double_data[0], dfout.u, double_data[0], dfin.u);*/
|
||||
if (dfin.u != 0x3ff1c60000000000) ERR;
|
||||
|
||||
/* Close the file again. */
|
||||
@ -352,7 +353,7 @@ fprintf(stderr,"\n>>> type url = |%s|\n",file_name);
|
||||
/* printf ("\nfloat_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */
|
||||
/* float_data[0], fout.u, float_data[0], fin.u); */
|
||||
if (fin.u != 0x3f8e3000) ERR;
|
||||
/* printf ("\ndouble_data: %15g : 0x%16lx double_data_in: %15g : 0x%lx\n", */
|
||||
/* printf ("\ndouble_data: %15g : 0x%16llx double_data_in: %15g : 0x%llx\n", */
|
||||
/* double_data[0], dfout.u, double_data[0], dfin.u); */
|
||||
if (dfin.u != 0x3ff1c60000000000) ERR;
|
||||
|
||||
@ -433,8 +434,8 @@ fprintf(stderr,"\n>>> type url = |%s|\n",file_name);
|
||||
if (fin.u != xpect[x].u) ERR;
|
||||
/* dfout.d = double_data[x]; */
|
||||
dfin.d = double_in[x];
|
||||
/* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", */
|
||||
/* double_data[x], dfout.u, double_data[x], dfin.u); */
|
||||
/*printf("double_data: %15g : 0x%16llx double_data_in: %15g : 0x%16llx\n",*/
|
||||
/* double_data[x], dfout.u, double_data[x], dfin.u);*/
|
||||
if (dfin.u != double_xpect[x].u) ERR;
|
||||
}
|
||||
|
||||
@ -549,7 +550,7 @@ fprintf(stderr,"\n>>> type url = |%s|\n",file_name);
|
||||
/* union FU fout; */
|
||||
union FU xpect[DIM_LEN_5];
|
||||
union DU dfin;
|
||||
/* union DU dfout; */
|
||||
union DU dfout;
|
||||
union DU double_xpect[DIM_LEN_5];
|
||||
xpect[0].u = 0x3f8e3000;
|
||||
xpect[1].u = 0x3f800fff;
|
||||
@ -584,8 +585,8 @@ fprintf(stderr,"\n>>> type url = |%s|\n",file_name);
|
||||
if (fin.u != xpect[x].u) ERR;
|
||||
/* dfout.d = double_data[x]; */
|
||||
dfin.d = double_in[x];
|
||||
/* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", */
|
||||
/* double_data[x], dfout.u, double_data[x], dfin.u); */
|
||||
/* printf("double_data: %15g : 0x%16llx double_data_in: %15g : 0x%16llx\n",*/
|
||||
/* double_data[x], dfout.u, double_data[x], dfin.u);*/
|
||||
if (dfin.u != double_xpect[x].u) ERR;
|
||||
}
|
||||
|
||||
@ -872,8 +873,8 @@ fprintf(stderr,"\n>>> type url = |%s|\n",file_name);
|
||||
dfin.d = double_data_in[x];
|
||||
/* printf ("%d float_data_in : %08.8f : 0x%x expected %08.8f : 0x%x\n", */
|
||||
/* x, float_data_in[x], fin.u, xpect[x].f, xpect[x].u); */
|
||||
/* printf ("%d double_data_in : %15g : 0x%lx expected %15g : 0x%lx\n", */
|
||||
/* x, double_data_in[x], dfin.u, double_xpect[x].d, double_xpect[x].u); */
|
||||
/* printf ("%d double_data_in : %15g : 0x%llx expected %15g : 0x%llx\n",*/
|
||||
/* x, double_data_in[x], dfin.u, double_xpect[x].d, double_xpect[x].u);*/
|
||||
if (fin.u != xpect[x].u)
|
||||
ERR;
|
||||
if (dfin.u != double_xpect[x].u)
|
||||
@ -957,9 +958,9 @@ fprintf(stderr,"\n>>> type url = |%s|\n",file_name);
|
||||
|
||||
for (i = 0; i < DIM_LEN_SIMPLE; i++)
|
||||
{
|
||||
if (abs(float_data_in[i] - float_data[i]) > EPSILON)
|
||||
if (fabs(float_data_in[i] - float_data[i]) > EPSILON)
|
||||
ERR;
|
||||
if (abs(double_data_in[i] - double_data[i]) > EPSILON)
|
||||
if (fabs(double_data_in[i] - double_data[i]) > EPSILON)
|
||||
ERR;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user