diff options
author | Mattias Andrée <maandree@member.fsf.org> | 2015-12-16 19:45:48 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@member.fsf.org> | 2015-12-16 19:45:48 +0100 |
commit | 16cddfb8329a25190525858a0784321698cb848b (patch) | |
tree | 6b5c66be00cc10939314398a2c1956ab866fc085 /include | |
parent | m (diff) | |
download | slibc-16cddfb8329a25190525858a0784321698cb848b.tar.gz slibc-16cddfb8329a25190525858a0784321698cb848b.tar.bz2 slibc-16cddfb8329a25190525858a0784321698cb848b.tar.xz |
we need signed integer representation conversion
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to '')
-rw-r--r-- | include/arpa/inet.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/arpa/inet.h b/include/arpa/inet.h index 34ff52c..a7bd2c1 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -157,6 +157,32 @@ uint64_t _htonll(uint64_t) #endif +/* TODO We "need" conversion to and from two's complement. + * It is important to remember than intN_t cannot be + * used for this functions because they require two's + * complement. + * + * unsigned to_twos_complement(signed v) { + * unsigned r; + * if (v >= -0) + * return (unsigned)v; + * r = (unsigned)-v; + * r = ~(r - 1); + * return r; + * } + * + * signed from_twos_complement(unsigned v) { + * signed r; + * if ((v >> (X_BIT - 1)) == 0) + * return (signed)v; + * r = ~r; + * if (r == X_MAX) + * return errno = ERANGE, 0; + * return errno = 0, r + 1; + * } + */ + + #endif |