diff options
author | Grant Limberg <grant.limberg@zerotier.com> | 2018-09-25 10:19:59 -0700 |
---|---|---|
committer | Grant Limberg <grant.limberg@zerotier.com> | 2018-09-25 10:19:59 -0700 |
commit | 0510f85a8fe6cba7e6258d534fa49d47f9f8e2a2 (patch) | |
tree | ef9bf53e9dd472a1fb343a41a41630bb30097979 /node/Utils.hpp | |
parent | 5b222d0a09dab1a7e009f728f955a0ef70d569a6 (diff) | |
parent | 27c37a18f3e2f97d06ebc04e2db31d0c796c9452 (diff) | |
download | infinitytier-0510f85a8fe6cba7e6258d534fa49d47f9f8e2a2.tar.gz infinitytier-0510f85a8fe6cba7e6258d534fa49d47f9f8e2a2.zip |
Merge branch 'dev' into libpq
Diffstat (limited to 'node/Utils.hpp')
-rw-r--r-- | node/Utils.hpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/node/Utils.hpp b/node/Utils.hpp index a24f2c9a..35493f01 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -38,6 +38,10 @@ #include <vector> #include <map> +#if defined(__FreeBSD__) +#include <sys/endian.h> +#endif + #include "Constants.hpp" #ifdef __LINUX__ @@ -261,6 +265,14 @@ public: return l; } + static inline float normalize(float value, int64_t bigMin, int64_t bigMax, int32_t targetMin, int32_t targetMax) + { + int64_t bigSpan = bigMax - bigMin; + int64_t smallSpan = targetMax - targetMin; + float valueScaled = (value - (float)bigMin) / (float)bigSpan; + return (float)targetMin + valueScaled * (float)smallSpan; + } + /** * Generate secure random bytes * @@ -411,8 +423,12 @@ public: static inline uint64_t hton(uint64_t n) { #if __BYTE_ORDER == __LITTLE_ENDIAN -#if defined(__GNUC__) && (!defined(__OpenBSD__)) +#if defined(__GNUC__) +#if defined(__FreeBSD__) + return bswap64(n); +#elif (!defined(__OpenBSD__)) return __builtin_bswap64(n); +#endif #else return ( ((n & 0x00000000000000FFULL) << 56) | @@ -440,8 +456,12 @@ public: static inline uint64_t ntoh(uint64_t n) { #if __BYTE_ORDER == __LITTLE_ENDIAN -#if defined(__GNUC__) && !defined(__OpenBSD__) +#if defined(__GNUC__) +#if defined(__FreeBSD__) + return bswap64(n); +#elif (!defined(__OpenBSD__)) return __builtin_bswap64(n); +#endif #else return ( ((n & 0x00000000000000FFULL) << 56) | |