lib/stream: add float/double <-> IEEE-754 single/double mux/demuxers
* stream.{c,h}: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
Thanks to Aidan Delaney <aidan@phoric.eu> and Olivier Dugeon for pointing
out the __STDC_IEC_559__ macro.
Update: GCC does not per se set __STDC_IEC_559__, so also test for
__GCC_IEC_559 >= 1.
diff --git a/lib/stream.h b/lib/stream.h
index 1fc382d..06b0ee1 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -186,6 +186,12 @@
extern uint64_t stream_getq_from (struct stream *, size_t);
extern u_int32_t stream_get_ipv4 (struct stream *);
+/* IEEE-754 floats */
+extern float stream_getf (struct stream *);
+extern double stream_getd (struct stream *);
+extern int stream_putf (struct stream *, float);
+extern int stream_putd (struct stream *, double);
+
#undef stream_read
#undef stream_write