Let the floating point pack/unpack work at arbitrary precision
cmr=v1.7.5:reviewer=rhc This commit was SVN r30334.
Этот коммит содержится в:
родитель
2cf4862b49
Коммит
d2d4eeb2d6
@ -328,17 +328,18 @@ int opal_dss_pack_string(opal_buffer_t *buffer, const void *src,
|
|||||||
int opal_dss_pack_float(opal_buffer_t *buffer, const void *src,
|
int opal_dss_pack_float(opal_buffer_t *buffer, const void *src,
|
||||||
int32_t num_vals, opal_data_type_t type)
|
int32_t num_vals, opal_data_type_t type)
|
||||||
{
|
{
|
||||||
int64_t tmp[2];
|
|
||||||
int ret = OPAL_SUCCESS;
|
int ret = OPAL_SUCCESS;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
float *ssrc = (float*)src;
|
float *ssrc = (float*)src;
|
||||||
|
char *convert;
|
||||||
|
|
||||||
for (i = 0; i < num_vals; ++i) {
|
for (i = 0; i < num_vals; ++i) {
|
||||||
tmp[0] = (int64_t)ssrc[i];
|
asprintf(&convert, "%f", ssrc[i]);
|
||||||
tmp[1] = (int64_t)(1000000.0 * (ssrc[i] - tmp[0]));
|
if (OPAL_SUCCESS != (ret = opal_dss_pack_string(buffer, &convert, 1, OPAL_STRING))) {
|
||||||
if (OPAL_SUCCESS != (ret = opal_dss_pack_int64(buffer, tmp, 2, OPAL_INT64))) {
|
free(convert);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
free(convert);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OPAL_SUCCESS;
|
return OPAL_SUCCESS;
|
||||||
|
@ -402,9 +402,9 @@ int opal_dss_unpack_float(opal_buffer_t *buffer, void *dest,
|
|||||||
int32_t *num_vals, opal_data_type_t type)
|
int32_t *num_vals, opal_data_type_t type)
|
||||||
{
|
{
|
||||||
int32_t i, n;
|
int32_t i, n;
|
||||||
int64_t tmp[2];
|
|
||||||
float *desttmp = (float*) dest;
|
float *desttmp = (float*) dest;
|
||||||
int ret;
|
int ret;
|
||||||
|
char *convert;
|
||||||
|
|
||||||
OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_float * %d\n", (int)*num_vals ) );
|
OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_float * %d\n", (int)*num_vals ) );
|
||||||
/* check to see if there's enough data in buffer */
|
/* check to see if there's enough data in buffer */
|
||||||
@ -414,11 +414,12 @@ int opal_dss_unpack_float(opal_buffer_t *buffer, void *dest,
|
|||||||
|
|
||||||
/* unpack the data */
|
/* unpack the data */
|
||||||
for (i = 0; i < (*num_vals); ++i) {
|
for (i = 0; i < (*num_vals); ++i) {
|
||||||
n=2;
|
n=1;
|
||||||
if (OPAL_SUCCESS != (ret = opal_dss_unpack_int64(buffer, tmp, &n, OPAL_INT64))) {
|
if (OPAL_SUCCESS != (ret = opal_dss_unpack_string(buffer, &convert, &n, OPAL_STRING))) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
desttmp[i] = (float)tmp[0] + (float)tmp[1]/1000000.0;
|
desttmp[i] = strtof(convert, NULL);
|
||||||
|
free(convert);
|
||||||
}
|
}
|
||||||
return OPAL_SUCCESS;
|
return OPAL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user