haskell-posit
Haskell bindings for the SoftPosit C library 🧮 (WIP)
lib.h (860B)
1 #include "softposit.h" 2 #include <stdint.h> 3 #include <stdbool.h> 4 5 #define DEFINE_INT_TO_POSIT(N_BITS) \ 6 uint##N_BITS##_t int_to_posit##N_BITS (int64_t x); 7 8 #define DEFINE_BIN_OP(N_BITS, OP) \ 9 uint##N_BITS##_t posit##N_BITS##_##OP (uint##N_BITS##_t a, uint##N_BITS##_t b); 10 11 #define DEFINE_NEG(N_BITS) \ 12 uint##N_BITS##_t posit##N_BITS##neg (uint##N_BITS##_t a); 13 14 #define DEFINE_ARITH_OPS(N_BITS) \ 15 DEFINE_BIN_OP(N_BITS, add) \ 16 DEFINE_BIN_OP(N_BITS, sub) \ 17 DEFINE_BIN_OP(N_BITS, mul) \ 18 DEFINE_BIN_OP(N_BITS, div) \ 19 DEFINE_NEG(N_BITS) 20 21 #define DEFINE_COMP_OP(N_BITS, OP); 22 23 #define DEFINE_COMP_OPS(N_BITS) \ 24 DEFINE_COMP_OP(N_BITS, eq) \ 25 DEFINE_COMP_OP(N_BITS, le) \ 26 DEFINE_COMP_OP(N_BITS, lt) 27 28 #define DEFINE_ALL_OPS(N_BITS) \ 29 DEFINE_INT_TO_POSIT(N_BITS) \ 30 DEFINE_ARITH_OPS(N_BITS) \ 31 DEFINE_COMP_OPS(N_BITS) 32 33 DEFINE_ALL_OPS(8) 34 DEFINE_ALL_OPS(16) 35 DEFINE_ALL_OPS(32) 36