GH-696: Add bytestring_to_float BIF

This commit is contained in:
Tim Wojtulewicz 2022-07-11 13:12:46 -07:00
parent 96a14b39fa
commit 7e56605d83
6 changed files with 101 additions and 1 deletions

View file

@ -261,6 +261,15 @@ inline double htond(double d)
return d;
}
inline float ntohf(float f)
{
return f;
}
inline float htonf(float f)
{
return f;
}
#ifndef HAVE_BYTEORDER_64
inline uint64_t ntohll(uint64_t i)
{
@ -299,6 +308,27 @@ inline double htond(double d)
return ntohd(d);
}
inline float ntohf(float f)
{
assert(sizeof(f) == 4);
float tmp;
char* src = (char*)&f;
char* dst = (char*)&tmp;
dst[0] = src[3];
dst[1] = src[2];
dst[2] = src[1];
dst[3] = src[0];
return tmp;
}
inline float htonf(float f)
{
return ntohf(f);
}
#ifndef HAVE_BYTEORDER_64
inline uint64_t ntohll(uint64_t i)
{