int.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef int_h
  2. #define int_h
  3. // this header needs
  4. #include "bits.h"
  5. // the below functions are functions to calculate, from bits, an integer.
  6. // it does not assume that the system integer representation is the same
  7. // as the integer that it is going to be read from memory.
  8. // that is why some math is to be done
  9. // int_op result struct
  10. typedef struct {
  11. union {
  12. owl_umax u;
  13. owl_smax s;
  14. } integer;
  15. owl_bool success;
  16. } owl_int_op_result;
  17. typedef enum {
  18. OWL_TYPE_INT_OP_RESULT = OWL_TYPE_BITARR + 1,
  19. } owl_type_int_h;
  20. // basic functions for integers
  21. owl_int_op_result owl_pow_uint(owl_umax base, owl_byte exponent);
  22. owl_int_op_result owl_pow_sint(owl_smax base, owl_byte exponent);
  23. owl_int_op_result owl_get_max_uint(owl_umax uint1, owl_umax uint2);
  24. owl_int_op_result owl_get_min_uint(owl_umax uint1, owl_umax uint2);
  25. // See https://en.wikipedia.org/wiki/Signed_number_representations
  26. owl_int_op_result owl_bits_as_uint(owl_bitarr * bits);
  27. owl_int_op_result owl_bits_as_sign_mag_sint(owl_bitarr * bits);
  28. owl_int_op_result owl_bits_as_1_compl_sint(owl_bitarr * bits);
  29. owl_int_op_result owl_bits_as_2_compl_sint(owl_bitarr * bits);
  30. owl_int_op_result owl_bits_as_off_bin_sint(owl_bitarr * bits);
  31. owl_int_op_result owl_bits_as_bminus2_sint(owl_bitarr * bits);
  32. // get usual unsigned/signed integers from memory
  33. // no math calculations, assume "standard" representations
  34. owl_int_op_result owl_get_uint(owl_bitarr * bits);
  35. owl_int_op_result owl_get_sint(owl_bitarr * bits);
  36. // get "standard" integers from bits
  37. // owl_byte aligned, 8/16/32 bits long, big/little endian
  38. owl_int_op_result owl_get_std_uint(owl_bitarr * bits, owl_endian endian);
  39. owl_int_op_result owl_get_std_sint(owl_bitarr * bits, owl_endian endian);
  40. #include "int.c"
  41. #endif // int_h