/* Copyright (c) 2019, Anthony Latorre * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) * any later version. * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #ifndef PACK2B_H #define PACK2B_H #include // various bits for floating point types--varies for different architectures typedef float float32_t; typedef double float64_t; // macros for packing floats and doubles: #define pack754_32(f) (pack754((f), 32, 8)) #define pack754_64(f) (pack754((f), 64, 11)) #define unpack754_32(i) (unpack754((i), 32, 8)) #define unpack754_64(i) (unpack754((i), 64, 11)) uint64_t pack754(long double f, unsigned bits, unsigned expbits); long double unpack754(uint64_t i, unsigned bits, unsigned expbits); void packi16(uint8_t *buf, int16_t i); void packi32(uint8_t *buf, int32_t i); void packi64(uint8_t *buf, int64_t i); int16_t unpacki16(uint8_t *buf); int32_t unpacki32(uint8_t *buf); int64_t unpacki64(uint8_t *buf); int32_t pack(uint8_t *buf, char *format, ...); void unpack(uint8_t *buf, char *format, ...); #endif