X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/adec5584e13c63662fda18915280ec026063b29d..08bb7015a9e28c5c9d38fe05a6f6644bc21fa527:/struct/buf.h diff --git a/struct/buf.h b/struct/buf.h index dd5f6e7..2a37220 100644 --- a/struct/buf.h +++ b/struct/buf.h @@ -400,6 +400,60 @@ extern int dbuf_putk64b(dbuf */*db*/, kludge64 /*w*/); #define dbuf_putk64l(db, w) (buf_putk64l(DBUF_BUF(db), (w))) #define dbuf_putk64b(db, w) (buf_putk64b(DBUF_BUF(db), (w))) +/* --- @buf_getf{32,64}{,l,b} --- * + * + * Arguments: @buf *b@ = a buffer to read from + * @float *x_out@, @double *x_out@ = where to put the result + * + * Returns: Zero on success, %$-1$% on failure (and the buffer is + * broken). + * + * Use: Get an IEEE Binary32 or Binary64 value from the buffer. + * Conversion is performed using the `fltfmt' machinery, with + * the usual round-to-nearest/ties-to-even rounding mode. + */ + +extern int buf_getf32(buf */*b*/, float */*x_out*/); +extern int buf_getf32l(buf */*b*/, float */*x_out*/); +extern int buf_getf32b(buf */*b*/, float */*x_out*/); +#define dbuf_getf32(db, x_out) (buf_getf32(DBUF_BUF(db), (x_out))) +#define dbuf_getf32l(db, x_out) (buf_getf32l(DBUF_BUF(db), (x_out))) +#define dbuf_getf32b(db, x_out) (buf_getf32b(DBUF_BUF(db), (x_out))) + +extern int buf_getf64(buf */*b*/, double */*x_out*/); +extern int buf_getf64l(buf */*b*/, double */*x_out*/); +extern int buf_getf64b(buf */*b*/, double */*x_out*/); +#define dbuf_getf64(db, x_out) (buf_getf64(DBUF_BUF(db), (x_out))) +#define dbuf_getf64l(db, x_out) (buf_getf64l(DBUF_BUF(db), (x_out))) +#define dbuf_getf64b(db, x_out) (buf_getf64b(DBUF_BUF(db), (x_out))) + +/* --- @buf_putf{32,64}{,l,b} --- * + * + * Arguments: @buf *b@ = a buffer to write to + * @double x@ = a number to write + * + * Returns: Zero on success, %$-1$% on failure (and the buffer is + * broken). + * + * Use: Get an IEEE Binary32 or Binary64 value from the buffer. + * Conversion is performed using the `fltfmt' machinery, with + * the usual round-to-nearest/ties-to-even rounding mode. + */ + +extern int buf_putf32(buf */*b*/, float /*x*/); +extern int buf_putf32l(buf */*b*/, float /*x*/); +extern int buf_putf32b(buf */*b*/, float /*x*/); +#define dbuf_putf32(db, x) (buf_putf32(DBUF_BUF(db), (x))) +#define dbuf_putf32l(db, x) (buf_putf32l(DBUF_BUF(db), (x))) +#define dbuf_putf32b(db, x) (buf_putf32b(DBUF_BUF(db), (x))) + +extern int buf_putf64(buf */*b*/, double /*x*/); +extern int buf_putf64l(buf */*b*/, double /*x*/); +extern int buf_putf64b(buf */*b*/, double /*x*/); +#define dbuf_putf64(db, x) (buf_putf64(DBUF_BUF(db), (x))) +#define dbuf_putf64l(db, x) (buf_putf64l(DBUF_BUF(db), (x))) +#define dbuf_putf64b(db, x) (buf_putf64b(DBUF_BUF(db), (x))) + /* --- @{,d}buf_getmem{8,{16,24,32,64}{,l,b},z} --- * * * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block @@ -610,63 +664,6 @@ BUF_DOSUFFIXES(BUF_DECL_PUTSTR_) #define dbuf_putstr64b(db, p) (buf_putstr64b(DBUF_BUF(db), (p))) #define dbuf_putstrz(db, p) (buf_putstrz(DBUF_BUF(db), (p))) -/* --- @{,d}buf_getf64{,l,b} --- * - * - * Arguments: @buf *b@ = pointer to a buffer block - * @double *x_out@ = where to put the result - * - * Returns: Zero on success, @-1@ on failure (and the buffer is broken). - * - * If the system supports NaNs, then any encoded NaN is returned - * as the value of @NAN@ in @@; otherwise, this function - * reports failure. - * - * In general, values are rounded to the nearest available - * value, in the way that the system usually rounds. If the - * system doesn't support infinities, then any encoded infinity - * is reported as the largest-possible-magnitude finite value - * instead. - */ - -extern int buf_getf64(buf */*b*/, double */*x_out*/); -extern int buf_getf64l(buf */*b*/, double */*x_out*/); -extern int buf_getf64b(buf */*b*/, double */*x_out*/); -extern int dbuf_getf64(dbuf */*db*/, double */*x_out*/); -extern int dbuf_getf64l(dbuf */*db*/, double */*x_out*/); -extern int dbuf_getf64b(dbuf */*db*/, double */*x_out*/); -#define dbuf_getf64(db, x_out) (buf_getf64(DBUF_BUF(db), (x_out))) -#define dbuf_getf64l(db, x_out) (buf_getf64l(DBUF_BUF(db), (x_out))) -#define dbuf_getf64b(db, x_out) (buf_getf64b(DBUF_BUF(db), (x_out))) - -/* --- @{,d}buf_putf64{,l,b} --- * - * - * Arguments: @buf *b@ or @dbuf *db@ = pointer to a buffer block - * @double x@ = a number to write - * - * Returns: Zero on success, @-1@ on failure (and the buffer is broken). - * - * On C89, this function can't detect negative zero so these - * will be silently written as positive zero. - * - * This function doesn't distinguish NaNs. Any NaN is written - * as a quiet NaN with all payload bits zero. - * - * A finite value with too large a magnitude to be represented - * is rounded to the appropriate infinity. Other finite values - * are rounded as necessary, in the usual IEEE 754 round-to- - * nearest-or-even way. - */ - -extern int buf_putf64(buf */*b*/, double /*x*/); -extern int buf_putf64l(buf */*b*/, double /*x*/); -extern int buf_putf64b(buf */*b*/, double /*x*/); -extern int dbuf_putf64(dbuf */*db*/, double /*x*/); -extern int dbuf_putf64l(dbuf */*db*/, double /*x*/); -extern int dbuf_putf64b(dbuf */*db*/, double /*x*/); -#define dbuf_putf64(db, x) (buf_putf64(DBUF_BUF(db), (x))) -#define dbuf_putf64l(db, x) (buf_putf64l(DBUF_BUF(db), (x))) -#define dbuf_putf64b(db, x) (buf_putf64b(DBUF_BUF(db), (x))) - /* --- @{,D}BUF_ENCLOSETAG@ --- * * * Arguments: @tag@ = a control-structure macro tag @@ -716,17 +713,17 @@ extern int dbuf_putf64b(dbuf */*db*/, double /*x*/); * @kludge64@ machinery. */ -#define BUF_STORESZK64(p, sz) \ +#define MLIB__BUF_STORESZK64(p, sz) \ do { kludge64 _k; ASSIGN64(_k, (sz)); STORE64_((p), _k); } while (0) -#define BUF_STORESZK64_B(p, sz) \ +#define MLIB__BUF_STORESZK64_B(p, sz) \ do { kludge64 _k; ASSIGN64(_k, (sz)); STORE64_B_((p), _k); } while (0) -#define BUF_STORESZK64_L(p, sz) \ +#define MLIB__BUF_STORESZK64_L(p, sz) \ do { kludge64 _k; ASSIGN64(_k, (sz)); STORE64_L_((p), _k); } while (0) #define BUF_ENCLOSEITAG(tag, b, mk, W) \ BUF_ENCLOSETAG(tag, (b), (mk), (_delta <= MASK##W), STORE##W, SZ_##W) -#define BUF_ENCLOSEKTAG(tag, b, mk, W) \ - BUF_ENCLOSETAG(tag, (b), (mk), 1, BUF_STORESZK##W, 8) +#define BUF_ENCLOSEKTAG(tag, b, mk, W) \ + BUF_ENCLOSETAG(tag, (b), (mk), 1, MLIB__BUF_STORESZK##W, 8) #define BUF_ENCLOSEZTAG(tag, b) \ MC_AFTER(tag##__zero, { buf_putbyte((b), 0); })