12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #ifndef int_h
- #define int_h
- // this header needs
- #include "bits.h"
- // the below functions are functions to calculate, from bits, an integer.
- // it does not assume that the system integer representation is the same
- // as the integer that it is going to be read from memory.
- // that is why some math is to be done
- // int_op result struct
- typedef struct {
- union {
- owl_umax u;
- owl_smax s;
- } integer;
- owl_bool success;
- } owl_int_op_result;
- typedef enum {
- OWL_TYPE_INT_OP_RESULT = OWL_TYPE_BITARR + 1,
- } owl_type_int_h;
- // basic functions for integers
- owl_int_op_result owl_pow_uint(owl_umax base, owl_byte exponent);
- owl_int_op_result owl_pow_sint(owl_smax base, owl_byte exponent);
- owl_int_op_result owl_get_max_uint(owl_umax uint1, owl_umax uint2);
- owl_int_op_result owl_get_min_uint(owl_umax uint1, owl_umax uint2);
- // See https://en.wikipedia.org/wiki/Signed_number_representations
- owl_int_op_result owl_bits_as_uint(owl_bitarr * bits);
- owl_int_op_result owl_bits_as_sign_mag_sint(owl_bitarr * bits);
- owl_int_op_result owl_bits_as_1_compl_sint(owl_bitarr * bits);
- owl_int_op_result owl_bits_as_2_compl_sint(owl_bitarr * bits);
- owl_int_op_result owl_bits_as_off_bin_sint(owl_bitarr * bits);
- owl_int_op_result owl_bits_as_bminus2_sint(owl_bitarr * bits);
- // get usual unsigned/signed integers from memory
- // no math calculations, assume "standard" representations
- owl_int_op_result owl_get_uint(owl_bitarr * bits);
- owl_int_op_result owl_get_sint(owl_bitarr * bits);
- // get "standard" integers from bits
- // owl_byte aligned, 8/16/32 bits long, big/little endian
- owl_int_op_result owl_get_std_uint(owl_bitarr * bits, owl_endian endian);
- owl_int_op_result owl_get_std_sint(owl_bitarr * bits, owl_endian endian);
- #include "int.c"
- #endif // int_h
|