Skip to content
Snippets Groups Projects
Commit 58e63757 authored by Morris Jette's avatar Morris Jette
Browse files

Add functions to un/pack long double

parent 90af8654
No related branches found
No related tags found
No related merge requests found
...@@ -70,6 +70,8 @@ strong_alias(pack_time, slurm_pack_time); ...@@ -70,6 +70,8 @@ strong_alias(pack_time, slurm_pack_time);
strong_alias(unpack_time, slurm_unpack_time); strong_alias(unpack_time, slurm_unpack_time);
strong_alias(packdouble, slurm_packdouble); strong_alias(packdouble, slurm_packdouble);
strong_alias(unpackdouble, slurm_unpackdouble); strong_alias(unpackdouble, slurm_unpackdouble);
strong_alias(packlongdouble, slurm_packlongdouble);
strong_alias(unpacklongdouble, slurm_unpacklongdouble);
strong_alias(pack64, slurm_pack64); strong_alias(pack64, slurm_pack64);
strong_alias(unpack64, slurm_unpack64); strong_alias(unpack64, slurm_unpack64);
strong_alias(pack32, slurm_pack32); strong_alias(pack32, slurm_pack32);
...@@ -208,6 +210,7 @@ int unpack_time(time_t * valp, Buf buffer) ...@@ -208,6 +210,7 @@ int unpack_time(time_t * valp, Buf buffer)
* Given a double, multiple by FLOAT_MULT and then * Given a double, multiple by FLOAT_MULT and then
* typecast to a uint64_t in host byte order, convert to network byte order * typecast to a uint64_t in host byte order, convert to network byte order
* store in buffer, and adjust buffer counters. * store in buffer, and adjust buffer counters.
* NOTE: There is an IEEE standard format for double.
*/ */
void packdouble(double val, Buf buffer) void packdouble(double val, Buf buffer)
{ {
...@@ -240,6 +243,7 @@ void packdouble(double val, Buf buffer) ...@@ -240,6 +243,7 @@ void packdouble(double val, Buf buffer)
* Given a buffer containing a network byte order 64-bit integer, * Given a buffer containing a network byte order 64-bit integer,
* typecast as double, and divide by FLOAT_MULT * typecast as double, and divide by FLOAT_MULT
* store a host double at 'valp', and adjust buffer counters. * store a host double at 'valp', and adjust buffer counters.
* NOTE: There is an IEEE standard format for double.
*/ */
int unpackdouble(double *valp, Buf buffer) int unpackdouble(double *valp, Buf buffer)
{ {
...@@ -261,6 +265,38 @@ int unpackdouble(double *valp, Buf buffer) ...@@ -261,6 +265,38 @@ int unpackdouble(double *valp, Buf buffer)
return SLURM_SUCCESS; return SLURM_SUCCESS;
} }
/*
* long double has no standard format, so pass the data as a string
*/
void packlongdouble(long double val, Buf buffer)
{
char val_str[256];
snprintf(val_str, sizeof(val_str), "%Lf", val);
packstr(val_str, buffer);
}
/*
* long double has no standard format, so pass the data as a string
*/
int unpacklongdouble(long double *valp, Buf buffer)
{
long double nl;
char *val_str = NULL;
uint32_t size_val_str = 0;
int rc;
rc = unpackmem_ptr(&val_str, &size_val_str, buffer);
if (rc != SLURM_SUCCESS)
return rc;
if (sscanf(val_str, "%Lf", &nl) != 1)
return SLURM_ERROR;
*valp = nl;
return SLURM_SUCCESS;
}
/* /*
* Given a 64-bit integer in host byte order, convert to network byte order * Given a 64-bit integer in host byte order, convert to network byte order
* store in buffer, and adjust buffer counters. * store in buffer, and adjust buffer counters.
......
...@@ -96,6 +96,9 @@ int unpack_time(time_t *valp, Buf buffer); ...@@ -96,6 +96,9 @@ int unpack_time(time_t *valp, Buf buffer);
void packdouble(double val, Buf buffer); void packdouble(double val, Buf buffer);
int unpackdouble(double *valp, Buf buffer); int unpackdouble(double *valp, Buf buffer);
void packlongdouble(long double val, Buf buffer);
int unpacklongdouble(long double *valp, Buf buffer);
void pack64(uint64_t val, Buf buffer); void pack64(uint64_t val, Buf buffer);
int unpack64(uint64_t *valp, Buf buffer); int unpack64(uint64_t *valp, Buf buffer);
...@@ -155,6 +158,19 @@ int unpackmem_array(char *valp, uint32_t size_valp, Buf buffer); ...@@ -155,6 +158,19 @@ int unpackmem_array(char *valp, uint32_t size_valp, Buf buffer);
goto unpack_error; \ goto unpack_error; \
} while (0) } while (0)
#define safe_packlongdouble(val,buf) do { \
assert(sizeof(val) == sizeof(long double)); \
assert(buf->magic == BUF_MAGIC); \
packlongdouble(val,buf); \
} while (0)
#define safe_unpacklongdouble(valp,buf) do { \
assert(sizeof(*valp) == sizeof(long double)); \
assert(buf->magic == BUF_MAGIC); \
if (unpacklongdouble(valp,buf)) \
goto unpack_error; \
} while (0)
#define safe_pack64(val,buf) do { \ #define safe_pack64(val,buf) do { \
assert(sizeof(val) == sizeof(uint64_t)); \ assert(sizeof(val) == sizeof(uint64_t)); \
assert(buf->magic == BUF_MAGIC); \ assert(buf->magic == BUF_MAGIC); \
......
...@@ -240,6 +240,8 @@ ...@@ -240,6 +240,8 @@
#define unpack_time slurm_unpack_time #define unpack_time slurm_unpack_time
#define packdouble slurm_packdouble #define packdouble slurm_packdouble
#define unpackdouble slurm_unpackdouble #define unpackdouble slurm_unpackdouble
#define packlongdouble slurm_packlongdouble
#define unpacklongdouble slurm_unpacklongdouble
#define pack64 slurm_pack64 #define pack64 slurm_pack64
#define unpack64 slurm_unpack64 #define unpack64 slurm_unpack64
#define pack32 slurm_pack32 #define pack32 slurm_pack32
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment